21. Worksheet B
Moving colored dot animation, with a walkthrough including helper functions.
note
Pay attention to contracts for the functions you are asked to write. When afull-circle
is mentioned, that means the data type that you defined in question 1 and 2. Both “takes in” and “given” are indications that the parameters to the function are being specified.
Animation: Moving Colored Dot
- Create a data definition for a type “fc” (for full-circle) that is able to store the location of the center, color, and radius of a dot.
- Write the actual struct definition.
- Test each feature (center, color, radius).
- Write a function to create a solid circle of the given color and radius.
- Design and test a function to draw the circle at the given position on the background.
- Design and test a function
fc-move
that takes in a full-circle and a position, and returns a new full-circle with the same color and radius, but different position. - Write a function
fc-set-color
. Include a sensible purpose and contract. - Write a function
fc-change-radius
that takes in a full-circle and an amount to change the radius. Include sensible purpose and contract. - Create an animation of a full-circle randomly moving around the screen.