# simulate simple harmonic motion # using formulas here for x(t) and w: # http://en.wikipedia.org/w/index.php?title=Simple_harmonic_motion&oldid=473101961#Dynamics_of_simple_harmonic_motion import turtle import math # amplitude (range of motion) A = 100 # frequency (Hz so good) f = 0.2 # phase # set to stun phase = 0 # number of simulation time steps, in seconds NSTEPS = 1000000 steps_per_sec = 60 w = 2 * math.pi * f # make the turtle a cute li'l ball turtle.shape('circle') for t in range(NSTEPS): x = A * math.cos(w * (t/steps_per_sec) - phase) turtle.goto(x, 0)