CS108 Lab 3: Drawing Generated Pictures, Part 2
Using a similar program to lab 2 (you can start with lab 2 if you want), add three buttons that draw different patterns:
- Decagon: Draws a decagon (10-sided figure). This will work like lab 2, except that count will be multiplied by 36 instead of 7, and lines will be drawn from the previous point (the count-1 point) instead of (100,100).
- Spiral: Draws a spiral. This is like a decagon, except that the sides are shorter (so multiply count by something much smaller than 36), and the radius will be related to count instead of fixed. Try using count/30 for the radius. Dividing count by something larger will produce a tighter spiral.
- Something else: Make up a pattern yourself (does not have to be related to circles), and use this button to display it.
Preserve the "Reset" functionality from lab 2. To set up multiple patterns, you can use multiple clocks. So the buttons should selectively enable and disable clocks. Note that for three buttons, each button will disable two clocks and enable one. If you had four patterns, each button would disable three and enable 1. So each clock you add increases the number of statements each button requires! There are ways to fix this using functions. Feel free to experiment, but finish the rest of the lab first.
Colors can be created out of three numbers: red, green, and blue. These should be in the range of 0 through 255, although blocks does not give an error for out-of-range numbers. Try this to generate a color pattern: (sin(count) * 127) + 128. Since sine gives a value between -1 and 1, that will yield a value between 1 and 255, which will change with count. Adding to or multiplying count will change the pattern. If you set red, green, and blue to the same value, the result will be a shade of grey. The artistic merits of grey are up to you, but setting them different from each other will yield a wide variety of colors.
Turning in the Lab
Show me that you have finished, and I will mark off that you have.