Tut­o­r­i­a­l 9

by Elizabeth Hennessey
  • Show Sketch
/** @peep sketchcode */
float angle = 0.0;
float y = 20;
float speed = 3.0;
float spin = 0.05;
 
void setup() {
  size(400, 400);
  background(0, 12);
  noStroke();
}
void draw() { 
 
  //draw spinning square
  fill(0, 12);
  rect(0, 0, width, height);
 
  fill(255);
  translate(width/2, y);
  rotate(angle);
  rect(-60, -60, 120,120);
    pushMatrix();   //draw left small square
    fill(0, 255, 250);
    translate(-100, 0);
    rect(0, 0, 30, 30);
    popMatrix();
    pushMatrix(); //draw right small square
    fill(255, 0, 255);
    translate(60, 0);
    rect(0, 0, 30, 30);
    popMatrix();
    pushMatrix(); //draw top small square
    fill(0, 255, 0);
    translate(0, -100);
    rect(0, 0, 30, 30);
    popMatrix();
 
      angle = angle + 0.02;
      y += speed; 
      if (y > height + 200) {
        y = -125;
      }
  }

Comments

Nobody has said anything yet.