Created
June 29, 2017 14:59
-
-
Save kasperkamperman/1c3d844bd94840c287d6339f60d4b88a to your computer and use it in GitHub Desktop.
Rotating shapes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() | |
{ | |
size(500,500); | |
strokeWeight(2); | |
} | |
void draw() | |
{ background(128); | |
rotateRect(width/2,height/2,100,100,frameCount%360); | |
rotateRect(100,400,50,100,frameCount%360); | |
rotateLine(300,100,100,frameCount%360); | |
rotateEllipse(100,100,100,50,frameCount%360); | |
} | |
void rotateRect(float x, float y, float w, float h, float angle) { | |
// center anchorpoint | |
// can be done easier with rectMode(CENTER), however this is more flexible for other configurations | |
float ax = -(w/2); | |
float ay = -(h/2); | |
pushMatrix(); | |
translate(x,y); | |
rotate(radians(angle)); | |
rect(ax,ay,w,h); | |
popMatrix(); | |
// draw Anchor | |
fill(0); | |
ellipse(x,y,5,5); | |
noFill(); | |
} | |
void rotateLine(float x, float y, float l, float angle) { | |
// center anchorpoint | |
float ax = -(l/2); | |
pushMatrix(); | |
translate(x,y); | |
rotate(radians(angle)); | |
line(ax, 0, ax+l, 0); | |
//rect(ax,ay,w,h); | |
popMatrix(); | |
// draw Anchor | |
fill(0); | |
ellipse(x,y,5,5); | |
noFill(); | |
} | |
void rotateEllipse(float x, float y, float w, float h, float angle) { | |
pushMatrix(); | |
translate(x,y); | |
rotate(radians(angle)); | |
ellipse(0,0,w,h); | |
popMatrix(); | |
// draw Anchor | |
fill(0); | |
ellipse(x,y,5,5); | |
noFill(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment