In this section, you are going to be using random. To receive full credit for “attending” this section, complete at least 3 of the problems and turn them in on D2L.
Write a sketch named section_14_1 .
Your canvas should be wide and narrow, like the gif shows.
Your canvas should have the "digits" label as shown.
You program will display only the digits 0-9 that the user types.
If the user types other letters or symbols, they should not be displayed!
Also, pressing the space-bar will clear all the digits off of the canvas, and the user can types something new.
|
Write a sketch named section_14_2 .
This program will generate two random numbers between 0 and 20 on each frame (each time draw() runs).
One of the numbers will be converted to an integerer (thus, getting rid of the decimal places) and the other will be left as a float.
These two numbers will be displayed on the canvas, as shown in the screen capture.
Below, the sum of the two numbers will be displayed, also in integer form.
You should set the frameRate() to a small number (for example, 1) so that the numbers dont change too quickly.
|
Write a sketch named section_14_3 .
This sketch will read in numbers that you type.
As you type in digits, the digits will be displayed on the top line with the "limit" label.
Once you hit "Enter" (represented by the "\n" special character) then the number will be cleared.
In addition to clearing the number, a number will appear next to the "random number" label.
This number should be a randomly-generated number between 0 and the number that the user typed in before hitting the ENTER key.
|
Write a sketch named random_drawing .
This sketch should place an ellipse in a random position and of random size on the canvas, 30 times per-secons.
Each ellipse should show up within the bounds of the canvas.
The size of each ellipse should be between 10 and 70.
Use the below code as a starting point.
The code to compute the random values and draw the ellipse should go in the drawRadomEllipse function.
|
Modify your program from the last problem so that each ellipse is also given a random fill. You should accomplish this by generating 3 random integers between 0 and 255 and then using them in a call to the fill function. You should create a separate function that handles this. |
Modify your program from the last problem so that the screen is cleared periodically, with a new background that has a random color. After 100 shapes are drawn, clear the background, and then repeat. See the gif for an example of the behavior. |