In this assignment, you will create several simple animations using your newfound function-writing skills. To create an animation, write a Number -> Image
function that takes in a frame number and returns the image to be displayed on that frame.
Please design the following functions, in a file called YourNameAnimations1.rkt
. At the end of this document, I’ve provided a list of potentially useful built-in functions. Important note: on your own computer, in order to use animate
, you will need to go to the Language menu and select “Add Teachpack.” Select the universe.rkt
teachpack.
Create three separate animations in which:
a ball moves across the screen, left to right.
a circle starts small and grows bigger, in the center of a large empty scene.
a shape moves diagonally, from top left to bottom right.
Create two separate animations in which:
a shape moves from bottom to top.
a shape moves from right to left at a speed of 5 pixels per frame.
Create three separate animations in which:
a shape moves from left to right, then, when it hits the righthand side, loops back around to the left and starts over. This repeats forever.
a shape moves from right to left, but when it hits the lefthand side, “bounces” back toward the right. It’s OK if it then goes off the end. (If you have heard of if
statements, a feature available in most programming languages, do not use them here. There is another way.)
the previous two ideas are combined, and a shape moves from right to left, then back, then back again, etc. In other words, loop the “single bounce” animation infinitely.
Create an animation in which two shapes are moving independently.
Create an animation in which a ball moves diagonally, but at different speeds in each direction (e.g., 2 pixels downward and 4 pixels rightward per frame). When the ball hits the left or right side, it should reverse its horizontal direction; when it hits the top or bottom, its vertical direction should reverse.
Create any animation you’d like, using built-in shapes or images from the Internet.
Create an animation of a sunrise, that goes from the bottom left corner of a screen upward, in a parabola, ending at the bottom right corner.
You may find the following functions useful in completing this assignment:
abs : Number -> Number
If the input is negative, this returns the positive version. Otherwise, leaves input unchanged.
remainder : Number Number -> Number
Computes the remainder after dividing one number by another.
quotient : Number Number -> Number
Computes how many times the entire second number goes into the first number.
sqrt : Number -> Number
Computes the square root of a number.
sqr : Number -> Number
Squares a number (multiplies it by itself).
empty-scene : Number Number -> Image
Creates an empty rectangular scene of the given width and height, in which to place other images.
place-image : Image Number Number Image -> Image
Places the first image on top of the second image to obtain a new image. The image is placed so that its center appears x pixels over and y pixels down from the top left corner of the screen, where x and y are the two numerical arguments.
overlay : Image Image -> Image
Places the first image on top of the second image, so that the centers of each image are aligned. (That is, the first image is placed in exactly the center of the second.)