Meeting 15: Week 8, Short day (Tuesday March 31 4:05 – 5:20)

Discussion

  • Student lead discussions:  Omar, Katarina
  • Look at some homework assignments, pay attention to program structure and usage of functions, transformations, and loops
  • Reorganized schedule of student lead discussions

Lecture

What is the difference between random() and noise()?

Example use of noise():

void setup() {
  size(400, 400);
  fill(0);
}

// Why are these global?
// initial arguments for perlin noise. 
// ty is different from tx so values aren't both the same
float tx = 0;
float ty = 100; // value is arbitrary as long as it's different

// set to true to demonstrate behavior with random numbers
// set to false to demonstrate behavior with perlin noise
boolean useRandom = true;

void draw() {

  float x; // Why didn't I initialize?
  float y;

  background(255);

  if (useRandom) {
    // generate random number between 0 and 1 (not inclusive)
    x = random(1);
    y = random(1);
  } else {
    // generate perlin noise for values tx and ty
    x = noise(tx);
    y = noise(ty);
    // advance to next noise value
    tx = tx + 0.01; 
    ty = ty + 0.01;
  }

  // x and y will always be between 0 and 1, so scale
  // to fit the canvas
  x = map (x, 0, 1, 0, width);
  y = map (y, 0, 1, 0, height);
  ellipse(x, y, 30, 30);
}

Time permitting

Introduction to Object Oriented Programming
 

Homework due Thursday April 2

Read:

Homework due Tuesday April 7

Make an art piece or a game using object oriented programming.