Wondering about learning Python
Lee Harr
missive at frontiernet.net
Thu Jul 22 17:55:07 EDT 2004
On 2004-07-22, Chris <nospam@[> wrote:
> 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.
>
It is not a direct translation, but here is how I made a spiral
method for my Penguin object in pygsear
(http://www.nongnu.org/pygsear/)
class Penguin(Turtle):
def spiral(self, turns=1, rPerT=100, stepsPerT=60, connect=0):
'''Make a spiral shape
@param turns: number of times to go around the spiral.
@param rPerT: amount spiral grows per turn.
@param stepsPerT: number of line segments in each spiral turn.
(more segments makes a smoother curve)
@param connect: if True, draw a line from the center to each
generated point on the curve.
'''
center = self.get_position()
for c in range(turns * stepsPerT):
f = (PIx2 * rPerT/stepsPerT) * (float(c) / stepsPerT)
self.forward(f)
self.right(360.0 / stepsPerT)
if connect:
p = self.get_position()
self.lineTo(center)
self.lineTo(p)
More information about the Python-list
mailing list