Animation

JythonMusic supports animation through the animate() function.

FunctionDescription
animate(function)Calls function repeatedly based on animation rate (see below). Provided function should expect no parameters.

Also see:

FunctionDescription
setAnimationRate(rate)Sets animation rate to provided rate – default is 60 (times per second).
getAnimationRate()Returns current animation rate.
pauseAnimation()Pauses animation.
resumeAnimation()Resumes animation.

For example:

# Animate a circle by moving it randomly.

from gui import *
from random import *

d = Display("Animation Example", 600, 400)

# initialize circle coordinates
x = 300
y = 200   

# create filled red circle
c = Circle(x, y, 25, Color.RED, True)
d.add(c)

def moveCircle():
   
   global x, y   # these will be updated

   # update global circle coordinates   
   x = x + randint(-5, 5)
   y = y + randint(-5, 5)
   
   # now, move circle
   d.move(c, x, y)
   
# start animation
animate( moveCircle )

For more complex animations, see Timer.