[Edu-sig] From trees to text
Gregor Lingl
gregor.lingl at aon.at
Wed Mar 25 17:47:22 CET 2009
Edward Cherlin schrieb:
> http://tonyforster.blogspot.com/2009/03/orbital-motion-in-python-and-turtleart.html
> Orbital motion in Python and TurtleArt
>
I'd like to contribute to this topic just three scripts using Python's
own turtle module (since 3.6) - for now without any further comment ( as
I'm just preparing my journey to Chicago, leaving Vienna tommorow
in the morning). Of course there are many ways of doing this,
depending on your previous knowledge, approaches to math and physics,
and to programming etc.
Please run the example scripts (and compare and asses the code, if you
like)
# orbit1.py
from turtle import *
shape("turtle")
speed(0)
pu(); goto(200,0); pd()
G = 800
hspeed, vspeed = 0, 1
t = 0
while t < 1000:
x, y = pos()
goto(x+hspeed, y+vspeed)
r = distance(0,0)
x, y = pos()
hacc = (-G/r**2)*(x/r)
vacc = (-G/r**2)*(y/r)
hspeed = hspeed + hacc
vspeed = vspeed + vacc
t = t + 1
# orbit2.py
from turtle import *
color("orange")
dot(10)
color("blue")
shape("turtle")
speed(0)
pu(); goto(200,0); pd()
G = 800
v = Vec2D(0, 1)
t = 0
while t < 1000:
goto(pos() + v)
setheading(towards(0,0))
r = distance(0,0)
acc = (-G/r**3)*pos()
v = v + acc
t = t + 1
# orbit3.py
from turtle import Screen, Turtle, Vec2D
s = Screen()
sun = Turtle()
sun.shape("circle")
sun.color("orange")
planet = Turtle()
planet.shape("circle")
planet.shapesize(0.4)
planet.pu()
planet.goto(200,0)
planet.pd()
G = 800
v = Vec2D(0, -2)
dt = 0.5
t = 0
while t < 1000:
planet.goto(planet.pos() + dt*v)
r = planet.distance(sun)
acc = (-G/r**3)*planet.pos()
v = v + dt*acc
t = t + dt
You can find a more elaborate example using a Planet class here:
http://svn.python.org/view/python/trunk/Demo/turtle/tdemo_planet_and_moon.py?view=markup
Best regards,
Gregor
> Intended to demonstrate two things,
> a) that programmable simulations are good ways for kids to learn
> physics and maths
> b) that the programmable block provides a way for kids to move from
> simple drag and drop programming to more complicated text based
> programming
>
> Tony's point is that the programmable block allows users to explore
> Python at any level they like, from a single function call up. This
> will be an essential part of my strategy for teaching CS and
> programming through Turtle Art.
>
>
More information about the Edu-sig
mailing list