Spiral
Pete Shinners
shredwheat at attbi.com
Thu May 30 11:34:57 EDT 2002
Chris 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
chris, hopefully this helps. it is a version of your program in python. it
uses pygame to actually handle the graphics (http:/wwww.pygame.org)
for the most part it is exactly the same, just a little extra work to do at
the beginning and end of the program. in python we need to "import" the
different modules we want to use.
to set the graphics mode is a little more work than "SCREEN 12". you can
take out the 'FULLSCREEN' flag to pygame.display.set_mode(), and it will
run in a window, which might be nicer?
i'm not framilair with the "PSET" command. what color does it set the
pixels too? i just guessed white, but you can see it is easy enough to
change in the python version.
at the end we have to flip the display, so all our drawing becomes visible.
we also wait for the user to close the window or press the keyboard
before the program finishes.
the functions for all the pygame calls are much longer than the simple
keywords in basic. but pygame can also do a lot more than what you have
available in basic too (at least, i think so). the pygame functions are all
organized into different modules.
i'd be curious to know about the speed? on my celeron 1.3g it is almost
instantaneous. i'm not sure how the basic version compares, but i'm sure
it's close.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: spiral.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20020530/d94c4d59/attachment.ksh>
More information about the Python-list
mailing list