Saint Louis University |
Computer Science 144
|
Dept. of Math & Computer Science |
Topic: Arrays
Related Reading: Ch. 5 of text, Notes/slides from class
Due:
11:00am, Tuesday, February 24, 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.
Assume that variable data represents an array of floating-point numbers. Provide a segment of Processing code that reassigns each entry of the array to be double its current value.
The Processing library includes a function max() that returns the maximum value in an array. It would support a calling syntax such as
float biggest = max(data); // assuming data is an array of floatsOf course, if that function did not exist, we could program such a function ourselves. Please give a self-contained implementation of a function named max that takes a nonempty array of floating-point numbers as a parameter, and which returns that maximum floating-point value that can be found in the array.
The following program moves a randomly located and randomly colored square in a "southeast" direction, wrapping at the boundaries. Rewrite the program, using arrays to do the same for 50 squares with randomly chosen initial positions and colors.
int x; int y; color c; void setup() { size(500, 500); x = int( random(width) ); y = int( random(height) ); c = color( random(255), random(255), random(255) ); } void draw() { background(255); x = (x + 1) % width; y = (y + 1) % height; fill( c ); rect(x, y, 20, 20); }