CS 100 Spring 2014
Lab 5
More on Conditionals
Due Monday March, 31th

Using the Processing language/environment answer the following questions.

1. [4 pts] Consider this new version of the snow flakes program where the flakes fall within two vertical strips. Before running the program

size(300, 200);
println("w : " + width + " h: " + height);

background(200);

int snowFlakeSize = 5;
smooth();
noStroke();
float xVal = 0;
float yVal = 0;
float sizeNoise = 0;

for (int i=0; i<400; i=i+1) {
  xVal = random(width);
  yVal = random(height);
  sizeNoise = random(5);

  if (xVal>50) {
    if (xVal<100) {
     ellipse(xVal, yVal, 
	snowFlakeSize+sizeNoise, snowFlakeSize+sizeNoise);
    }
  }
  
  if (xVal>200) {
    if (xVal<250) {
     ellipse(xVal, yVal, 
	snowFlakeSize+sizeNoise, snowFlakeSize+sizeNoise);
    }
  }
  println("i = " + i + " xVal " + xVal + " yVal " + yVal);
}

Now paste the code in a file constrainedSnowFlakes.pde and do the following.

2. [2 pts] Read this alternate program, which instead uses the random function passing two arguments, low and high, in between each the random number is generated.

Answer the following questions in the comment box when you submit the lab

3. [4 pts] Write a program horizontallyConstrainedSnowFlakes.pde that creates an output similar to this image.

Hint: Within a window 300x200 the snow is either

Bonus

Please read the hints at the bottom of the page.

  1. Write a program that constrains dots of random colors and sizes to be placed at random locations within a rectangle as shown below.

  2. Write a program that constrains dots of random colors and sizes to be placed at random locations within a circle as shown below.

Note: