Wednesday, February 18, 2009

Homework 4

Part one: Triangle Rotation



Part two: Rotating a triangle more than once to create a cool picture



Part three: Interesting rotating square







float[][] matrixRotation = new float[2][2];
int x1,y1,x2,y2,x3,y3;
int originX, originY;
float angle, cosine, sine, jitter;

void setup(){
size(720,480);
background(0);
//noLoop();
//noFill();
smooth();

}



void draw(){

fill(random(255),random(255),random(255));
stroke(247,26,141);


crazyBox();
pushMatrix();
popMatrix();

//
//x1 = int(random(520));
//y1 = int(random(360));
//x2 = int(random(520));
//y2 = int(random(360));
//x3 = int(random(520));
//y3 = int(random(360));

//code to rotate the triangle many times to create a cool picture
//for(float a=0; a < 2; a += .067){
//triangleRotation(x1,y1,x2,y2,x3,y3,(a*PI));
//}

//code to rotate the triangle once
//for(float f=0; f < 2; f+=1){
//triangleRotation(x1,y1,x2,y2,x3,y3,(f*PI));
//stroke(255,255,0);
//}



}

void crazyBox() {

fill(random(255),random(255),random(255));
stroke(247,26,141);
stroke(0);
if(second()%2 == 0) {
jitter = (random(-0.20, 1));
}
angle = angle + jitter;
cosine = cos(angle);
sine = sin(angle);

translate(120, 200);
rotate(cosine);
rectMode(CENTER);
rect(10,10,150,150);

}
void anotherCrazyBox() {



}

void rotateTheMatrix(float p){
matrixRotation[0][0] = cos(p);
matrixRotation[0][1] = -sin(p);
matrixRotation[1][0] = sin(p);
matrixRotation[1][1] = cos(p);
}


void triangleRotation(int x0, int y0, int x1, int y1, int x2, int y2, float p){

rotateTheMatrix(p);
originX = (x0+x1+x2)/3;
originY = (y0+y1+y2)/3;

float[][] theOrigin = {{x0-originX,y0-originY},{x1-originX,y1-originY},{x2-originX,y2-originY}};
theOrigin = multiplyMatrices(theOrigin,matrixRotation);

for(int a=0; a < theOrigin.length; a++){
for(int b=0; b < theOrigin[0].length; b++){
if(b==0){
theOrigin[a][b] += originX;
}else
theOrigin[a][b] += originY;
}
}
triangle(theOrigin[0][0],theOrigin[0][1],theOrigin[1][0],theOrigin[1][1],theOrigin[2][0],theOrigin[2][1]);
}



float[][] multiplyMatrices(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int i=0; i < matrix1.length; i++) {
for(int j=0; j < matrix2[0].length; j++) {
for(int k=0; k < matrix1[0].length; k++) {
matrix3[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}
return matrix3;
}

void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}

Sunday, February 1, 2009

Project Proposal

I found theTwisted World project in NodeBox to be very interesting. Using the advantage of hardware acceleration, the Core Image library of NodeBox is put to use to create these twisted images. Filters and transformations are applied with real-time and interactive response. The neat part about it is that the images are stored in script, so the source images remain unchanged. The images are created with multiple images put on a canvas that are rotated and scaled, with an occasional twirl or kaleidoscope filter. These images look like they have been editted with photoshop, but really they have been manipulated with NodeBox using the python programming language. I'd like to take the picture below of Hoggard Hall to be the first layer, and use the twirl filter with another picture of a beach sunset around it. Maybe even add another layer of the color teal, or a picture of an old building from downtown Wilmington.

Homework #3




For the first part of HW 3, we were to draw some cubic bezier curves based on where the mouse is clicked on the screen. The next part involved drawing triangles with a function that accepts 3 (x,y) coordinates, my myTri method. Each time the letter r is pressed, random triangles are drawn with this method. The last part randomly chooses coordinates to draw 5 different triangles placed at random in my window, which happens when the letter t is pressed. Here is my source code:

int pointclicks;
int x1, x2, x3, x4, y1, y2, y3, y4;
int xMax = 720;
int yMax = 480;

void setup() {
size(720, 480);
background(0);
}

void draw() {
stroke(random(0, 255), random(0, 255), random(0, 255));
noFill();
}

void keyPressed() {
if(key == 't') {
triangle(random(xMax), random(yMax), random(xMax), random(yMax), random(xMax), random(yMax));
}
if(key == 'r') {
myTri();
}
}
void mousePressed() {
if(pointclicks == 0) {
x1 = mouseX;
y1 = mouseY;
point(x1, y1);
pointclicks = 1;
}
else if (pointclicks == 1) {
x2 = mouseX;
y2 = mouseY;
pointclicks = 2;
}
else if (pointclicks == 2) {
x3 = mouseX;
y3 = mouseY;
pointclicks = 3;
}

else if (pointclicks == 3) {
x4 = mouseX;
y4 = mouseY;
point(x4, y4);
bezier(x1, y1, x2, y3, x3, y3, x4, y4);
pointclicks = 0;
}

}

void myTri(){
float a = random(xMax);
float b = random(xMax);
float c = random(xMax);
float d = random(yMax);
float e = random(yMax);
float f = random(yMax);

line(a,d,b,e);
line(b,e,c,f);
line(c,f,a,d);
}