Lesson goal: Simple animation with for-loops

Previous: The Lorenz Attractor | Home | Next: Animate a more complex shape

Computer animation is the process of making things move on the computer screen. Anything from video games to movies make use of computer animation. In this lesson, you'll learn how to make a single pixel move across the screen.

Computer animation works by drawing an object, erasing it, then moving it to a new location, all in rapid succession. Computers can do this so quickly that it appears as if the object you are drawing is actually moving. Here, we'll use a for-loop to count over some range of horizontal ($x$-coordinate) locations on the screen.

We'll draw a pixel at the $x$ location given by the for-loop (and $y=0$) using pset, then erase the pixel quickly thereafter using pcls(0). As the for-loop continues to count, this draw-erase-draw cycle will make it appear as if the pixel is moving across the screen.

Now you try. Try fixing the for and color statements to make a pixel move.

Type your code here:


See your results here: