473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Wondering about learning Python

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.

I'm wondering about learning Python - just for fun - and it would be
interesting to see how easy it is in comparison with qbasic.
--
Chris
Jul 18 '05 #1
8 1994
Chris <no****@[127.0.0.1]> wrote in news:bK**************@[127.0.0.1]:
Anyway, I wonder if anyone would be so kind as to convert it to Python.

I'm wondering about learning Python - just for fun - and it would be
interesting to see how easy it is in comparison with qbasic.


Python version (put it in a file 'spiral.py' then just run it):

from turtle import *

def spiral():
reset()
degrees()
tracer(0)
for i in range(40000):
t = i/100.
x = .5 * t * cos(t)
y = .5 * t * sin(t)
goto(x, y)

if __name__=='__main__':
spiral()
# The code below lets the screen update and then waits until you
# close the window.
import turtle
turtle._root.mainloop()
Jul 18 '05 #2
on 22 Jul 2004 11:50:10 GMT
Duncan Booth <me@privacy.net> wrote:
Chris <no****@[127.0.0.1]> wrote in news:bK**************@[127.0.0.1]:

....

sorry, your example doesn't work for me: the turtle sits there in the middle of the window pointing to the right and the program hangs.

- Josef
Jul 18 '05 #3
on Thu, 22 Jul 2004 14:35:57 +0200
Josef Dalcolmo <da******@vh-s.de> wrote:
sorry, your example doesn't work for me: the turtle sits there in the middle of the window pointing to the right and the program hangs.


Sorry, I put my foot in the mouth: I just didn't wait long enough for the spiral to appear.

- Josef
Jul 18 '05 #4
Josef Dalcolmo <da******@vh-s.de> wrote in
news:20040722144601.00004df5@titan:
on Thu, 22 Jul 2004 14:35:57 +0200
Josef Dalcolmo <da******@vh-s.de> wrote:
sorry, your example doesn't work for me: the turtle sits there in the
middle of the window pointing to the right and the program hangs.


Sorry, I put my foot in the mouth: I just didn't wait long enough for
the spiral to appear.

Don't worry about it, it fooled me as well. Change the 'trace(0)' to
'trace(1)' (or just delete it entirely: trace(1) is the default) and you
get to see the turtle doing the drawing.
Jul 18 '05 #5
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.


I suspect the patterns to which you refer are the moire
patterns generated when you superimpose the pattern you are
drawing and the two "grids" imposed by the rasterizaion done by
your frame buffer and the grid formed by the phosphor dots and
shadow mask of your CRT.

http://www.mathematik.com/Moire/
http://www.exploratorium.edu/snacks/moire_patterns.html
http://eluzions.com/Illusions/Moire/

--
Grant Edwards grante Yow! Vote for ME
at -- I'm well-tapered,
visi.com half-cocked, ill-conceived
and TAX-DEFERRED!
Jul 18 '05 #6
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)
Jul 18 '05 #7
Duncan Booth wrote:
from turtle import *

def spiral():
reset()
degrees()
tracer(0)
for i in range(40000):
t = i/100.
x = .5 * t * cos(t)
y = .5 * t * sin(t)
goto(x, y)

if __name__=='__main__':
spiral()
# The code below lets the screen update and then waits until you
# close the window.
import turtle
turtle._root.mainloop()
Change for i in range(40000):
t = i/100. into for t in range(200):

and you get something fairly cool looking, assuming spirals are cool.

Jul 18 '05 #8
Chris wrote:
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


Someone has already posted a Python Turtle example, you can also do a
pretty direct translation using Pygame. It turns out I already have this
exact same algorithm on my drive. Someone else must have been using the
same example. See attached.

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ron Stephens | last post by:
The newly rechristened Python Learning Foundation is a web site dedicated to the assistance of people learning the Python programming language. Features include: 1. Daily lists of new and recent...
7
by: Ryan Walker | last post by:
Hi, I'm getting started with python and have almost zero programming experience. I'm finding that there are tons of tutorials on the internet -- such as the standard tutorial at python.org -- that...
4
by: Ray | last post by:
I want to jump in a learn Python. I have spent about a day looking at editors and IDEs and (probably prematurely) selected jEdit to work in. I have downloaded Python and jEdit. I have been going...
2
by: AnOvercomer02 | last post by:
Hi. What is the best way to learn Python? None of the local schools near me teach any courses on the topic. Thanks. -- Cody Houston AnOvercomer02@webtv.net
5
by: Falc | last post by:
Hi there... I have been looking at learning Python, so far it looks like an absolutely grat language. I am having trouble finding some free resources to learn Python from. I am on windows and...
7
by: Max | last post by:
On monday I start a semester course in Python (the alternative was Java). I was looking through the course outline and noticed the following: 1) UserDict is used. This is deprecated, right? 2)...
5
by: romiro | last post by:
Hi all, I'm a PHP5 developer looking to "broaden my horizons" so to speak by learning a new language. I emphasize the 5 in PHP since I have fully engrossed myself in the full OOP of version 5...
6
by: dogatemycomputer | last post by:
Greetings, A friend of mine dropped off a copy of Sams Teach Yourself Python in 24 Hours published in 2000. I skimmed the first couple of chapters looking for the interpreter version and the...
6
by: Rui Maciel | last post by:
Recently I woke up inclined to take up the task of learning another programming language. I've already dipped my toes in Perl (I've read online tutorials and wrote a couple of irrelevant pet...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.