Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example Solution to Exercise 7 


Code Block
languagejava
titleExample solution
int red;
int green;
int blue;
int myShapeSpacingX;
int myShapeSpacingY;
int offset = 30; // used to create an empty border around grid
void setup() {
  size(500, 500);
  myShapeSpacingX = (width-offset*2)/10; // offset is for left and right side
  myShapeSpacingY = (height-offset*2)/10; // offset is for top and bottom side
}

void draw() {
  background(255);
  for  (int i =0; i<=10; i++) {
    green+=10;
    for  (int j =0; j<=10; j++) {
      red+=10;
      fill(color(red, green, blue));
      myShape(offset+i*myShapeSpacingX, offset+j*myShapeSpacingY); 
    }
    red = 0;
  }
  green = 0;
}

void myShape(int x, int y) {
  ellipse(x, y, 30, 30);
  ellipse(x, y-15, 15, 15);
}

...