Created
December 31, 2011 22:29
-
-
Save bmander/1545530 to your computer and use it in GitHub Desktop.
A simple app for learning how scale() and translate() work.
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
// I, Brandon Martin-Anderson, release this into the public domain. | |
// Do whatever you want with it. | |
// A simple app for learning how scale() and translate() work. | |
// Left click and drag to scale. | |
// Right click and drag to translate. | |
// Spacebar to switch to between translate-first, and scale-first. | |
float xscale=1; | |
float yscale=1; | |
float xtrans=0; | |
float ytrans=0; | |
void setup() { | |
size(500,500); | |
} | |
boolean scalefirst=false; | |
void mouseDragged() { | |
if(mouseButton==37){ | |
xscale += (mouseX-pmouseX)*0.01; | |
yscale += (mouseY-pmouseY)*0.01; | |
} | |
if(mouseButton==39){ | |
xtrans += (mouseX-pmouseX); | |
ytrans += (mouseY-pmouseY); | |
} | |
println( "["+xscale+","+yscale+"] ["+xtrans+","+ytrans+"]" ); | |
} | |
void keyPressed() { | |
if( key==' ' ) { | |
scalefirst = !scalefirst; | |
} | |
} | |
void draw() { | |
if(scalefirst) { | |
scale(xscale,yscale); | |
translate(xtrans,ytrans); | |
} else { | |
translate(xtrans,ytrans); | |
scale(xscale,yscale); | |
} | |
background(255); | |
rect( -100, -100, 200, 200 ); | |
line(0,0,100,100); | |
line(0,-100,0,100); | |
line(-100,0,100,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment