Tuesday, February 17, 2009

Homework #4

Once again a busy start to the week!...For this assignment we had to rotate a triangle. Then we had to rotate it to make a design. After that, the last part I spent creating a cool image using pushMatrix, popMatrix, translate, rotate, and scale. So here are some pictures of what I have created and then code is listed below them:



Code:
float[][] rotateMatrix = new float[2][2];

void setup(){
size(720,480);
background(30,144,255);
noLoop();
}

void draw(){
noFill();
stroke(16,78,139);
int x0,y0,x1,y1,x2,y2;
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

for(float a=0; a < 2; a += 1){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
stroke(255,0,0);
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
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);
}



Code:

float[][] rotateMatrix = new float[2][2];

void setup(){
size(720,480);
background(30,144,255);
noLoop();
}

void draw(){
noFill();
stroke(16,78,139);
int x0,y0,x1,y1,x2,y2;
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

for(float a=0; a < 2; a += .04166666){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
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);
}



Code:
float[][] rotateMatrix = new float[2][2];

void setup(){
size(950,700);
background(30,144,255);
noLoop();
}

void draw(){
fill(0);
rect(0,0,50,50);
pushMatrix();
for(int i=0; i < 9; i++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int j=0; j < 9; j++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 10; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int k=0; k < 8; k++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int j=0; j < 8; j++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 9; a++){
popMatrix();
}

fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 7; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 7; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 8; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 6; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 6; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 7; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 5; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 5; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 6; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 4; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 4; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 5; a++){
popMatrix();
}
noFill();
stroke(random(255),random(255),random(255));
int x0,y0,x1,y1,x2,y2;
x0 = 0;
y0 = 0;
x1 = 100;
y1 = 100;
x2 = 50;
y2 = 50;

translate(175,25);
for(float a=0; a < 2; a += .04166666){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
}
stroke(random(255),random(255),random(255));
translate(-250,500);
pushMatrix();
for(int i=0; i < 50; i++){
rotate(PI/12);
rect(0,0,100,50);
}
stroke(random(255),random(255),random(255));
translate(500,-275);
for(int i=0; i < 50; i++){
rotate(PI/12);
rect(0,0,100,50);
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
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);
}

Friday, February 6, 2009

Project Proposal

It has been a busy week so far and I had neglected to repost my proposal for the project. I have been looking around and since I know we're going to be doing some more on processing, I wanted to branch out and try something different. So I went to the resources page and found something that involves using NodeBox. NodeBox is a pretty cool program that uses Python as its language. I found a picture that looked pretty cool that is called Membrane. Here is a link to it:

http://nodebox.net/code/index.php/Membrane_%7C_Dynamics_in_Core_Image

It involves an already taken picture that is stored on your computer. That picture is stored as a layer, and then on top of that there is another layer that, at that website, is called the Membrane, which is just what looks like bubbles popping/twirling around the picture distorting the picture. I think I could possibly create a different layer that would act, of course, differently from the one that is posted on the website.

Sunday, February 1, 2009

Homework #3

For the first part of this homework, I had to draw a cubic Bezier curve by clicking the mouse to draw it. Here is the code and a picture:

int points;
int x0, y0, x1, y1, x2, y2, x3, y3;

void setup(){
size(400,400);
background(0);
}

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

void mousePressed(){
if(points == 0){
x0 = mouseX;
y0 = mouseY;
point(x0,y0);
println(x0 + "x0" + y0 + "y0");
points = 1;
}else if(points == 1){
x1 = mouseX;
y1 = mouseY;
points = 2;
}else if(points == 2){
x2 = mouseX;
y2 = mouseY;
points = 3;
}else if(points == 3){
x3 = mouseX;
y3 = mouseY;
stroke(255,0,0);
bezier(x0,y0,x1,y1,x2,y2,x3,y3);
points = 0;
}
}


I'm not able to get the applet to load onto here, so I just posted the picture itself of tons of bezier curves.

For the second part I had to create a function that accepts 3 points and draws a triangles of random size/ with random points. Here is the code and a picture for that as well:

int x0,y0,x1,y1,x2,y2;
void setup(){
size(720,480);
background(0,100,100);
}

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

void keyPressed(){
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

if(key == 't'){
drawTriangle(x0,y0,x1,y1,x2,y2);
}

}

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);
}



Finally for the third part, I am supposed to draw a rectangle with size 360 X 240 in the center of a 720 X 480 screen with 5 random triangles drawn and clipped down to just residing in the rectangle. I've been working on this yesterday and have gotten somewhere but it isn't exactly correct. But I will post that later on this week.

My proposal will come during the Super Bowl while I'm watching it tonight...