Spiral

Kevin Altis altis at semi-retired.com
Thu May 30 15:02:25 EDT 2002


Chris, here's a variation of the script Pete Shinners supplied that works
with the turtle sample included with PythonCard http://www.pythoncard.org/

This is run from the PythonCard shell, so I've left in the interpreter
prompts (>>> and ...)

The turtle sample has a lot of example scripts like this one and you can
experiment in the shell either using turtles or drawing directly on the
canvas like the example below. In order to speed up the redrawing, I
disabled autoRefresh, but if you want to see the spiral drawn, you don't
have to include that line, it will just take longer to do the drawing.

>>> import math
>>> buf = bg.components.bufOff
>>> buf.clear()
>>> buf.autoRefresh = 0
>>> for i in range(1, 40000):
...     i *= .01
...     x = .5 * i * math.cos(i)
...     y = .5 * i * math.sin(i)
...     buf.plot(x + 320, y + 240)
...
>>> buf.refresh()

Python is a wonderful language for exploring math and visualizations.

Enjoy,

ka

"Chris" <nospam@[127.0.0.1]> wrote in message
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!
> --
> Chris





More information about the Python-list mailing list