Skip to content

Latest commit

 

History

History
125 lines (74 loc) · 4.37 KB

File metadata and controls

125 lines (74 loc) · 4.37 KB

Homework 2 (due Sunday, September 13, 2015)

This homework has two parts: programming practice due Sunday, and a required tutorial to be completed before Tuesday night.

Classes Tutorial

  • Assignment: Follow the Processing Objects tutorial.

  • Assignment: Email me answers to the following questions to jzamfirescupereira@cca.edu by Tuesday night: Send 3-4 sentences per question.

    1. In what ways is a class like a cookie cutter?

    2. What sets apart instance variables from regular variables?

    3. In the following code, how many instances of Ball are created in total?

class Ball {
  float x, y;

  Ball(float x, float y) {
    this.x = x;
    this.y = y;
  }

  void display() {
    ellipse(x, y, 50, 50);
  }
}


Ball b = new Ball(100, 100);
Ball b2;

void setup() {
  size(500, 500);
  b = new Ball(120, 200);
  b2 = new Ball(35, 35);
  noStroke();
}

void draw() {
  background(255);
  fill(128, 178, 255);
  b.display();
  b2.display();
}

Programming Practice

Without further ado, here are the sketches:

  1. Circles in a diagonal line. Use a while loop to draw the balls in sequence. What do you know about the x and y coordinates of each ball? (Spoiler: They're the same!)

    ball-diagonal

  2. Circles in a grid. You will likely need a while loop inside another while loop!

    ball-grid

  3. Colored circles in a grid, random version. Check out the colorMode function, and HSB, in the Processing reference.

    ball-grid-randoms

  4. Colored circles in a grid, sequential version. Check out the colorMode function, and HSB, in the Processing reference. Note that the colors shift from left to right and from top to bottom!

    ball-grid-rainbows

  5. Circles in an triangle.

    ball-triangle

  6. Circles in an hourglass.

    ball-hourglass

  7. The grid.

    grid

  8. Diagonal lines.

    diagonal-lines

  9. Diagonal lines, interrupted.

    big-p

  10. Random bars.

random-bars

  1. Random bars, animated.

random-bars-animated

  1. Animated bars, mouse-sensitive. Check out the Processing-defined variables mouseX and mouseY in the Processing reference.

random-bars-mouse

  1. Bouncing balls, just two.

bouncing-balls

  1. Challenge: Bouncing balls, more added by clicking. You may need to use an ArrayList.

bouncing-balls-with-clicks

  1. Challenge: Fireworks! They should track the mouse and appear on clicks.

fireworks