Created
December 24, 2011 05:22
-
-
Save atduskgreg/1516424 to your computer and use it in GitHub Desktop.
Controlling the center of rotation in Processing
This file contains hidden or 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
// Rotation Around a Point | |
// *********************** | |
// To acheive rotation around a given point | |
// - translate to that point | |
// - rotate | |
// - then translate back | |
// (note: in Processing this last step is implicit | |
// since draw() resets all transformations | |
// each time it runs.) | |
void setup() { | |
size(200, 200); | |
smooth(); | |
} | |
void draw() { | |
background(0); | |
// move the center of rotation | |
// to the center of the sketch | |
translate(width/2, height/2); | |
// rotate around the center of the sketch | |
rotate(radians(frameCount)); | |
// draw a red dot at | |
// the center of the sketch | |
fill(255, 0, 0); | |
ellipse(0, 0, 20, 20); | |
// draw a rectangle with | |
// its top-left corner | |
// at the center of rotation | |
fill(255); | |
rect(0, 0, 50, 50); | |
} |
Thank you. This is enormously helpful. Now I have an example that has allowed me to make incremental changes and have a much clearer understanding of translate and rotate.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice.