Tut­o­r­i­a­l 6/7 - Week 4

by Matthew Brunker
  • Show Code
  • Show Sketch
//Concert Lights green
 
/** @peep sketchcode */
 
/** @peep sketch */
 
size(500, 500);
background(50,200,50); 
fill(10,100); 
noStroke();
ellipseMode(CENTER);
for (int x = 10; x < width; x += 20) { 
  for (int y = 10; y < height; y += 20) { 
    float r = random(20, 40);
    ellipse(x, y, r, r);
  }
 
}
  • Show Code
  • Show Sketch
Rain
 
 
/** @peep sketchcode */
 
/** @peep sketch */
 
size(500, 500); 
smooth();
for (int y = 20; y <= height - 20; y += 10) {
  for (int x = 20; x <= width - 20; x += 10) {
    if (random(1) < 0.5) {
      line(x-5, y+5, x+5, y-5);
    } else {
    }
  } 
}
  • Show Code
  • Show Sketch
puddles
 
/** @peep sketchcode */
 
/** @peep sketch */
 
size(500, 500);
background(50,150,200); 
fill(10,50); 
noStroke();
ellipseMode(CENTER);
for (int x = 10; x < width; x += 20) { 
  for (int y = 450; y < height; y += 20) { 
    float r = random(20, 40);
    ellipse(x, y, r, r);
  }
 
}
  • Show Code
Car Smoke
 
/** @peep sketch */
size(200, 200);
squareRecursion(0, 0, width, height);
 
void squareRecursion(float x, float y, float w, float h) {
  // Draw a rectangle
  noFill();
  stroke(0);
  rect(x, y, w, h);
 
  // Test to see if we should recurse...
  if ((random(100) < 80) && (w > 10 || h > 10)) {
    // Set a border to go around sub-rectangles
    float bx = 5;
    float by = 2;
    // Calculatue the width and height of sub-rectangles
    w = (w - 3*bx) / 1;
    h = (h - 3*by) / 2;
    // Call the same function to draw the sub-rectangles
    squareRecursion(x + bx, y + by, w, h);
    squareRecursion(x + bx + w + bx, y + by, w, h);
    squareRecursion(x + bx, y + by + h + by, w, h);
    squareRecursion(x + bx + w + bx, y + by + h + by, w, h);
  }
 
}

Comments

Nobody has said anything yet.