Skip to content

Instantly share code, notes, and snippets.

@bmander
Created December 31, 2011 22:29
Show Gist options
  • Save bmander/1545530 to your computer and use it in GitHub Desktop.
Save bmander/1545530 to your computer and use it in GitHub Desktop.
A simple app for learning how scale() and translate() work.
// 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