Spiral

Chris nospam at [127.0.0.1]
Fri May 31 03:25:51 EDT 2002


In article <Xns921E939913B0Bduncanrcpcouk at 127.0.0.1>, Duncan Booth 
<duncan at NOSPAMrcp.co.uk> writes
>Chris <nospam@[127.0.0.1]> wrote in news:gXPDTYGWch98Ew1w@[127.0.0.1]:
>> I've written a small QBASIC program which draws a spiral. Here is the
>> code:
>> SCREEN 12
>> CLS
>> FOR t = 1 TO 400 STEP .01
>> x = .5 * t * COS(t)
>> y = .5 * t * SIN(t)
>> PSET (x + 320, y + 240)
>> NEXT t
>> I noticed that it generated some interesting patterns, probably as a
>> result of rounding errors.  These can be explored further by making the
>> spiral tighter.
>> Anyway, I wonder if anyone would be so kind as to convert it to Python
>> because then I can try and decide whether Python is easy enough for me
>> to learn!

>How about:
>>>> from turtle import *
>>>> reset()
>>>> tracer(0)
>>>> for t1 in range(1, 40000):
>       t = t1/100.
>       x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi)
>       goto(x, y)
>
>
>Notes: Python uses radians for cos and sin, so you have to convert your
>degrees to radians.
>Use 'tracer(1)' to see what is happening (but it is much slower).
>
>You get pretty much the same output with:
>>>> from turtle import *
>>>> reset()
>>>> tracer(0)
>>>> for t in range(1, 400):
>       x, y = .5 * t * sin(t/180.*pi), .5 * t * cos(t/180.*pi)
>       goto(x, y)

Thanks - and thanks to others who replied, too.
I'm totally new to Python and so I'll have to experiment a bit -
but does your program work with the standard Python package or do I have 
to get some add-ons?  (It's the "import" that made me wonder.)
-- 
Chris



More information about the Python-list mailing list