Using variables, draw the diagram you see here.
The sketch window is 150 by 150 with a white background.
Save the sketch with the name variable1.
width and
height to calculate the value of these variables.width and height to calculate the
value of these variables. Use addition to get the
ending point. You must use different variables to draw the line than
you used for the circle.width
and height variables. Do not pre-calculate
the values for the coordinates! If I decide later to change the
window size to 200 by 200, your program should continue to work
without having to rewrite any other part.
The circle and line must each use their own set of variables.
Thus, the variables for the starting point of the line must be separate
from the variables used for the center of the circle.
You must use the width and height
variables only when drawing the square.
In a sketch window that is 100 by 100 pixels with a white background,
draw a square 20 pixels on a side whose initial location is (0,0).
Use variables to store the location of the upper left corner of the square.
In your setup()
function, use frameRate(5); to set the frame rate
to 5 frames per second so you can see the result more
clearly.
In your draw() function, add 3 to the square’s x coordinate
and 2 to its y coordinate.
Do not fill the square. You may use any color you like for its
stroke color.
Save the sketch with the name variable2.
The “staggering square.”
This is the same as part 2, except that you add a random number
between 2 and 8 to each of the x and y coordinates
of the square so that it staggers around instead of walking normally.
Save the sketch with the name variable3.
Set up your sketch window to be 200 by 200, with a white background,
and a frameRate(15);
If the frame rate is too fast, the
result is very annoying. Set noStroke() in your
setup function.
In the draw() function, randomly assign a number
between 10 and 50 to a variable named diameter.
Draw a circle with that diameter, centered at the current mouse position.
The circle’s red, green, and blue values must be randomly assigned and must
have a transparency value of 192. You do not need to use variables
for the random color, but you may do so if you wish.
Erase the sketch in the setup() function. Do not
erase the sketch unless the user clicks the mouse button. Use
the mousePressed() function to do this.
Save the sketch with the name variable4.
Create a new folder called variable and
put all four sketch folders into that new folder.
Zip up the “big folder” into a zip file named
variable.zip and upload that to Moodle.