Courses‎ > ‎APCS - Term 1‎ > ‎Konstantinovich‎ > ‎

2019-05-15 Rotations

posted May 15, 2019, 6:21 AM by Konstantinovich Samuel   [ updated May 15, 2019, 6:26 AM ]
Quickly read (or re-read) this:




Rotations:

float x,y,angle;

void setup(){
 size(600,600);
 x = 100;
 y = 250;
 angle = radians(45);
 rectMode(CENTER);
}

void drawShapeAtAngle(float x,float y,float angle){
  pushMatrix();
   //change the coordinates for JUST this one object
   translate(x,y);
   rotate(angle);
   rect(0,0,100,100);
  popMatrix();
}


void draw(){
  background(255);
  
  pushMatrix();//backup the original coordinate system
  //Change the coordinates for 
  //all objects then draw everything.
  translate(frameCount % width, frameCount % height);
  
  //Draw all the things you want to draw
  ellipse(0,0,20,20);
  drawShapeAtAngle(100+x,y,angle+radians(frameCount));
  drawShapeAtAngle(100+-x,y,angle+radians(frameCount));
  
  popMatrix();//restore the original coordinate system
}
Comments