Python for a 10-14 years old?

L

Lee Harr

Couldn't help myself. I had to write the Dragon Fractal in python.turtle
:)

That's nice. I ported it to use the pygsear Turtle class.
http://www.nongnu.org/pygsear/


--- Dragon.py 2005-03-27 08:48:13.000000000 -0500
+++ pDragon.py 2005-03-27 16:33:48.000000000 -0500
@@ -1,9 +1,14 @@
"""Generates the L-System for the Dragon Fractal, using
-the turtle module."""
+the pygsear.Drawable.Turtle class."""

-import re, turtle
+import re
+#import turtle
+from pygsear.Drawable import Turtle
from math import sin, pi

+turtle = Turtle()
+#turtle.visible = False
+
"""The default L-System rules for the dragon fractal are:
Angle 45 degrees
Starting Axiom FX
@@ -65,7 +70,7 @@
red = 1.0
green = 0.0
blue = 1.0 - fract
- return red, green, blue
+ return red*255, green*255, blue*255

# The default is that the turtle will only move one pixel
def parser(parsestring, distance=1, angle=45):
@@ -73,13 +78,14 @@
newstring = re.sub("X", "", parsestring)
newstring = re.sub("Y", "", newstring)
# Clear the screen
- turtle.clear()
+ #turtle.clear()
strlen = len(newstring)
colorinc = 1.0 / float(strlen)
- turtle.color(colorator(0))
+ turtle.set_color(colorator(0))
for i in range(strlen):
value = newstring
- turtle.color(colorator(float(i) * colorinc))
+ color = colorator(float(i) * colorinc)
+ turtle.set_color(color)
if value == "+":
turtle.right(angle)
elif value == "-":
@@ -87,7 +93,7 @@
elif value == "F":
turtle.forward(distance)
# Hide the cursor
- turtle.color(1.0,1.0,1.0)
+ turtle.uclear()

def run(count=15, distance=1, angle=45, width=1):
string = "FX"
@@ -96,14 +102,15 @@
count -= 1
# "Hide" the cursor while we are moving it.
## print string
- turtle.width(width)
- turtle.color(1.0,1.0,1.0)
+ turtle.set_width(width)
+ #turtle.color(1.0,1.0,1.0)
# Move the cursor so the turtle won't go off the screen.
# You might want to resize the turtle screen while the program is doing this
- turtle.setx(100)
- turtle.sety(-200)
+ #turtle.setx(100)
+ #turtle.sety(-200)
parser(string, distance=distance, angle=angle)


if __name__ == "__main__":
run(15)
+ raw_input()
 
J

Joal Heagney

Lee said:
That's nice. I ported it to use the pygsear Turtle class.
http://www.nongnu.org/pygsear/

Nice. I still have to download a version of pygame to try this out, but
the fact that you can't hide the turtle in python.turtle was bugging me
out with my version. (A fair bit of copy/paste in gimp, I can tell you!)

Joal
 
D

Duncan Booth

Joal said:
Nice. I still have to download a version of pygame to try this out, but
the fact that you can't hide the turtle in python.turtle was bugging me
out with my version. (A fair bit of copy/paste in gimp, I can tell you!)

What was wrong with hiding the turtle? 'turtle.tracer(False)' usually does
it nicely and speeds things up a lot.
 
G

Greg Ewing

Jot said:
If she's really gifted i hope she dumps that obsolete monolithic kernel
as soon as she realizes that such beautiful language as python shouldn't
be used on top of ugly, badly designed software.

Maybe she'll go on to write that oft-proposed pure Python
operating system, and give us a computing environment
that's truly elegant from the ground up! :)
 
J

Joal Heagney

Duncan said:
Joal Heagney wrote:




What was wrong with hiding the turtle? 'turtle.tracer(False)' usually does
it nicely and speeds things up a lot.

Ahhah! Thanks for that.

I also noticed that I got severe speed hits if the Xwindows mouse was
over the turtle tk window while the program was running.

BTW. How do I move the turtle to a new location without drawing anything?

Joal
 
J

Joal Heagney

Joal said:
Ahhah! Thanks for that.

I also noticed that I got severe speed hits if the Xwindows mouse was
over the turtle tk window while the program was running.

BTW. How do I move the turtle to a new location without drawing anything?

Joal

Whoop. That WAS a speedup!!! :)

Joal
 
G

Greg Ewing

Leif said:
I've got a thirteen-year old daughter to whom I have recently taught the
HTML basics, but she doesn't readily take to actual programming. If
you've got any idea what I should push to her to get her fascinated
about _real_ programming, I'd be obliged.

If she's interested in creating web sites, maybe you could
introduce her to some simple CGI programming?
 
J

Joal Heagney

Joal said:
Whoop. That WAS a speedup!!! :)

Joal

Now, is there a way to embed the turtle window into a scrollable canvas,
preferably with arbitrary runtime size?

Joal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top