-
-
Save jkwok91/3bcb12298840a1013e17 to your computer and use it in GitHub Desktop.
BWAHAHAHAHAHAHAHA ROTATION. IT HAS BEEN DID.
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
/* | |
rotating some mfkin thing with a mfkin matrix ok bro it's gonna happen | |
TODAY IS THE DAY | |
March 19th, 2014 | |
TODAY WAS THE DAY THAT I DISCOVERED THAT PROCESSING COORDINATES WERE THROWING ME OFFFFF | |
APRIL 10th, 2014!!!!!!! | |
*/ | |
int w = 300; | |
int h = 300; | |
int cx = w/2; | |
int cy = h/2; | |
Trianggl t; | |
float theta; | |
color c; | |
void setup() { | |
size(w, h); | |
background(0); | |
t = new Trianggl(); | |
theta = .1; | |
c = color(200, 200, 0); | |
} | |
void draw() { | |
background(0); | |
//crucial element | |
//i could've used a translation matrix but i was lazy | |
translate(cx, cy); | |
float[][] r = getRotationMat(theta); | |
PVector p1 = getNew(r, t.v1); | |
PVector p2 = getNew(r, t.v2); | |
PVector p3 = getNew(r, t.v3); | |
t = new Trianggl(p1, p2, p3); | |
t.drawT(c); | |
} | |
/* | |
this was a test because i was not sure if i understood how matrices were being applied | |
obviously i did because i know what matrices are. but just in case. | |
*/ | |
float[][] getScalingMat(float scale) { | |
float[][] scaling = new float[2][2]; | |
scaling[0][0] = scale; | |
scaling[0][1] = 0; | |
scaling[1][0] = 0; | |
scaling[1][1] = scale; | |
return scaling; | |
} | |
float[][] getRotationMat(float theta) { | |
float[][] rotation = new float[2][2]; | |
rotation[0][0] = cos(theta); | |
rotation[0][1] = sin(theta); | |
rotation[1][0] = sin(theta); | |
rotation[1][1] = cos(theta); | |
return rotation; | |
} | |
/* | |
gets new triangle coordinate | |
*/ | |
PVector getNew(float[][] r, PVector p) { | |
float x = p.x*r[0][0] - p.y*r[0][1]; | |
float y = p.x*r[1][0] + p.y*r[1][1]; | |
PVector pp = new PVector(x, y); | |
return pp; | |
} | |
/* | |
added this in so that i can make use of my scaling matrix | |
*/ | |
void mouseReleased() { | |
float[][] r = getScalingMat(1.5); | |
PVector p1 = getNew(r, t.v1); | |
PVector p2 = getNew(r, t.v2); | |
PVector p3 = getNew(r, t.v3); | |
t = new Trianggl(p1, p2, p3); | |
theta -= 0.02; | |
} |
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
class Trianggl { | |
PVector v1, v2, v3; | |
Trianggl() { | |
/* | |
default constructor | |
generates an eq.tri w/ radius 20 | |
*/ | |
v1 = new PVector(0, -20.0); | |
v2 = new PVector(-1*(20*sin(PI/3)), 10.0); | |
v3 = new PVector(20*sin(PI/3), 10.0); | |
} | |
Trianggl(PVector p1, PVector p2, PVector p3) { | |
v1 = p1; | |
v2 = p2; | |
v3 = p3; | |
} | |
void drawT(color c) { | |
stroke(c); | |
line(v1.x, v1.y, v2.x, v2.y); | |
line(v2.x, v2.y, v3.x, v3.y); | |
line(v1.x, v1.y, v3.x, v3.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment