Saint Louis University |
Computer Science 144
|
Dept. of Math & Computer Science |
Topic: Control Structures
Related Reading: Notes/slides from class
Due:
11:00am, Tuesday, February 10, 2015
Note that homework assignments should be submitted in class as hard copy (although you are welcome to test your solutions with Processing).
For this assignment, you must work individually.
Please make sure you adhere to the policies on academic integrity in this regard.
Given the following definitions, what value and type do the following expressions evaluate to?
int a = 2; int b = 5; float x = 2.0; float y = 10.0;1) y * (b - a)
Translate the following while loop to an equivalent for loop:
int n = 0; while (n < 50) { ellipse(n, n, 2*n, 2*n); n = n + 10; }
Write statements that will change the background of the canvas to a random color if the current mouseX and mouseY are near the bottom left corner of the sketch window, and do nothing otherwise. (Hint: you can monitor the mouseX and mouseY variables from within draw, or use the mouseMoved() function, which is called whenver the mouse is moved over the canvas. That function provides both mouseX and mouseY as well as previous values pmouseX and pmouseY.)
Here is an example:
Write a script that paints a grid over the canvas using horizontal and vertical lines. The resolution of the grid (i.e., the number of cells in each direction) should be determined by two int variables, r and c, where r specifies the number of rows and c specifies the number of columns.
Here is an example sketch for values r=8 and c=5.