This mini-lab will help you learn how to create simple animations
using for loops, and the copyInto and
show functions.
for loop, set the range so that the box
does not go off of your canvas. You should step by something other than
1 - try 5 to start with.) Inside the loop, you should copy the
picture you chose, or your colored background, into the canvas. Then
place a filled rectangle (remember how to use
addRectFilled?) at the appropriate position and show the
canvas.
for loop.)
import time
def movingRectangles():
pict = makeEmptyPicture(400,400)
canvas = duplicatePicture(pict)
show(canvas)
for y in range(1, getHeight(pict)/4):
addRectFilled(canvas, y*5, y*5, 30, 30, blue)
pinkx = 100 + int(10*sin(y))
pinky = 4*y + int(10*cos(y))
addRectFilled(canvas, pinkx, pinky, 30, 30, pink)
repaint(canvas)
time.sleep(.1)
# cover the rectangles with white, in effect "erase" them
addRectFilled(canvas, y*5, y*5, 30, 30, white)
addRectFilled(canvas, pinkx, pinky, 30, 30, white)
addText instead of addRectFilled.