FSEM 131 Fall 2016
Lab 4
Loop Practice
Due Wed, Nov 2nd, 10:00 p.m.

Using the Processing language/environment answer the following four questions.

1. [8 pts] Using for and while, as in class one after the other, write a program moreLoops2 that produces on the console the output below for Loop 1 and Loop 2. Write your code first on a piece of paper, checking manually the loop iterations. (Loop 3 and Loop 4 are bonuses, do them if you have time.)

  
Loop 1 with while
20 15 10 5 0

Loop 1 with for
20 15 10 5 0

--------------------------

Loop 2 (power of two) with while
1 2 4 8 16 32 64

Loop 2 (power of two) with for
1 2 4 8 16 32 64

2. [4 pts] Copy the following code into a program called manyEllipses and run it.

size(400, 400);

background(255);
smooth();
fill(random(128, 255), random(128, 255), random(128, 255));
ellipse(random(width), random(height), 50, 50);

fill(random(128, 255), random(128, 255), random(128, 255));
ellipse(random(width), random(height), 50, 50);

Add a loop to create many ellipses, the result is an image like the one below.

3. [4 pts] Write a program called dice that creates a 300 x 300 window and initializes the variables

int dotSize = 25;
int dotX = 40;
int dotY = 40;
int incX = 50;
int incY = 50;

which are used in a loop to produce the image below.

Changing the window size to 400 x 400 produces this image.

4. [5 pts] Create some graphical patterns using loop.

For example using the values of Loop 2 above for the rectangle width the following image is produced.