Monday, May 4, 2009

Sunday, March 29, 2009

Wednesday, March 25, 2009

Interesting topics in the Articles

OpenGL is everywhere from a simple game on your cell phone to a complex game on your PS3. OpenGL ES cuts out all the bloatware and rarely used features so it can run on the smallest platforms. Open GL is an API that talks directly to hardware. Its for both 2d and 3d graphics. OpenGL is the leading 3D rendering API for mobile embedded devices. I can see this is true because it takes up a small foot print and it is still powerful. This could be a reason why all our cell phones and smart phones graphics are becoming incredible. If you looked back a couple of years ago you would of never thought a cell phone could have this good of graphics. Most cell phones have better graphics then last generation game consoles.

Bezier in OpenGL


This is a pretty neat assignment with a little tweaking and luck i got this program to work. I like how when you move the arrow keys it looks like a rubber band.

Sunday, March 15, 2009

Project 1







Using the distance formula I did 3 tests the first one is to see if the circles are inside the bounds of the big circle, if a circle is intersecting another then we shrink it down till they are not intersecting, and if a circle is entirely within a circle another circle.
Credit goes to Mattox and the Mathematician who discovered the distance formula.

Wednesday, February 18, 2009


























The tunnel Link Just hit 'r' and it will take off


float i=0;
float k=0;
int x0 = 300;
int y0 = 300;
int x1 = 400;
int y1 = 100 ;
int x2 = 500 ;
int y2 = 300 ;

void setup() {
size(700, 700);
background(0);

} // end setup

void draw() {
frameRate(1999999999);
fill(random(0,255),random(0,255), random(0,255));
keyPressed();
}

void keyPressed(){
if (key == 'r'){
i -=.17;
k +=1;
translate(width/2,height/2);
rotate(PI*i);
triangle(x0-k,y0-k,x0-k,y1-k,0,0);
}
}

Tuesday, February 17, 2009


float angle = (PI*.05) ;
float original [][] = {{500, 300}, {300, 5},{200,300}};
float rotScaler [][] = {{cos(angle),sin(angle)}, {-sin(angle),cos(angle)}};
float translator [][] ={{20,20},{20,20},{20,20}};
float translated [][];
float rotated [][];
int x0 = 500 ;
int x1 = 300 ;
int x2 = 300 ;
int y0 = 5 ;
int y1 = 200 ;
int y2 = 300 ;

void setup() {
size(700, 700);
background(0);

println("Original Coords");
drawMatrix(original); // just writes out the coods of the matrix
triangle(original[0][0], original[0][1], original[1][0], original[1][1],original[2][0],original[2][1]); // draw original triangle

println("Translated Coords");
float moved [][] = translateShape(original, translator ); // draws first translated triangle
for (int i=0; i < 10; i++) { //draws 9 more triangles
fill(random(0,255),random(0,255), random(0,255)); // makes a new random color for each triangle
moved = translateShape(moved, translator); // draws a new translated triangle
}

println("Rotated Coords");
rotateShape(moved,rotScaler); //draws rotated triangle
} // end setup

void draw() {
fill(random(0,255),random(0,255), random(0,255));
triangle(x0,y0,x1,y1,x2,y2); // does translate with wasd keys

}


float [][] translateShape (float [][] A , float [][] B){ // translate function
float translated [][] = matrixAdd(A, B);
triangle(translated[0][0], translated[0][1], translated[1][0], translated[1][1],translated[2][0],translated[2][1]); // draws translated triangle
drawMatrix(translated); // writes out coordinats
return translated;
}

float [][] rotateShape (float [][] A , float [][] B){ //rotate function
fill(255,0,0);
float rotated [][] = matrixMul(A, B);
triangle(rotated[0][0], rotated[0][1], rotated[1][0], rotated[1][1],rotated[2][0],rotated[2][1]); // draws rotated triangle
drawMatrix(rotated); //writes out coordinates
return rotated;
}


float[][] matrixMul(float[][] A, float [][] B) { // matrix multiplication function
float[][] product = new float[A.length][B[0].length];
for(int row = 0; row < A.length; row++) {
for(int col = 0; col < B[0].length; col++) {
for(int i = 0; i < B.length; i++){

product[row][col] += A[row][i]*B[i][col];
}
}
}
return product;
} //end matrixMul


float[][] matrixAdd(float[][] A, float [][] B) { // matrix addition function
int row = 0;
int col = 0;
float [][]addSum = new float[A.length][A[row].length];
for(row = 0; row < A.length; row++) {
for(col = 0; col < A[row].length; col++) {
addSum[row][col]+=(A[row][col]+B[row][col]);
}
}
return addSum;
}//end matrix add function


void drawMatrix(float[][] A) { // just prints out the coords of matrices
for(int row = 0; row < A.length; row++) {
for(int col = 0; col < A[row].length; col++) {
print(" "+ A[row][col]);
}
println();
}
}//end drawMulMatrix1



void keyPressed(){
if (key=='d'){
x0+=10 ;
x1+=10 ;
x2+=10 ;
}

if (key=='a'){
x0-=10 ;
x1-=10 ;
x2-=10 ;
}


if (key=='s'){
y0+=10 ;
y1+=10 ;
y2+=10 ;
}

if (key=='w'){
y0-=10 ;
y1-=10 ;
y2-=10 ;
}
}

Rotating and Translating functions


float angle = (PI*.05) ;
float original [][] = {{500, 300}, {300, 5},{200,300}};
float rotScaler [][] = {{cos(angle),sin(angle)}, {-sin(angle),cos(angle)}};
float translator [][] ={{20,20},{20,20},{20,20}};
float translated [][];
float rotated [][];

void setup() {
size(700, 700);
background(0);

println("Original Coords");
drawMatrix(original); // just writes out the coods of the matrix
triangle(original[0][0], original[0][1], original[1][0], original[1][1],original[2][0],original[2][1]); // draw original triangle

println("Translated Coords");
float moved [][] = translateShape(original, translator ); // draws first translated triangle
for (int i=0; i < 10; i++) { //draws 9 more triangles
fill(random(0,255),random(0,255), random(0,255)); // makes a new random color for each triangle
moved = translateShape(moved, translator); // draws a new translated triangle
}

println("Rotated Coords");
rotateShape(moved,rotScaler); //draws rotated triangle
} // end setup

void draw() {
}


float [][] translateShape (float [][] A , float [][] B){ // translate function
float translated [][] = matrixAdd(A, B);
triangle(translated[0][0], translated[0][1], translated[1][0], translated[1][1],translated[2][0],translated[2][1]); // draws translated triangle
drawMatrix(translated); // writes out coordinats
return translated;
}

float [][] rotateShape (float [][] A , float [][] B){ //rotate function
fill(255,0,0);
float rotated [][] = matrixMul(A, B);
triangle(rotated[0][0], rotated[0][1], rotated[1][0], rotated[1][1],rotated[2][0],rotated[2][1]); // draws rotated triangle
drawMatrix(rotated); //writes out coordinates
return rotated;
}


float[][] matrixMul(float[][] A, float [][] B) { // matrix multiplication function
float[][] product = new float[A.length][B[0].length];
for(int row = 0; row < A.length; row++) {
for(int col = 0; col < B[0].length; col++) {
for(int i = 0; i < B.length; i++){

product[row][col] += A[row][i]*B[i][col];
}
}
}
return product;
} //end matrixMul


float[][] matrixAdd(float[][] A, float [][] B) { // matrix addition function
int row = 0;
int col = 0;
float [][]addSum = new float[A.length][A[row].length];
for(row = 0; row < A.length; row++) {
for(col = 0; col < A[row].length; col++) {
addSum[row][col]+=(A[row][col]+B[row][col]);
}
}
return addSum;
}//end matrix add function


void drawMatrix(float[][] A) { // just prints out the coords of matrices
for(int row = 0; row < A.length; row++) {
for(int col = 0; col < A[row].length; col++) {
print(" "+ A[row][col]);
}
println();
}
}//end drawMulMatrix1




Warning Seizure maker using transform


Seizure Maker






void setup() {
size(800, 800);

smooth();
fill(95);


}

void draw() {
background(random(0,255));
fill(random(0,255),random(0,255), random(0,255));
checkerboard();


}

void checkerboard(){
rect(0,0,100,100);
for (int row = 0; row<8; row++){
for (int col=0; col<4; col++){
translate(200, 0);
rect(0,0,100,100);
}
if(row==0 || row==4 || row==6){
translate(-700, 100);
rect(0,0,100,100);
}
else{
translate(-900, 100);
rect(0,0,100,100);
}

}

}

Monday, February 9, 2009

Link to HW4 program and instructions

Hw4 With opening this link you can access my applet and run it. Hitting the L key will draw a triangle with line clipping. Hitting the T key will draw triangles without clipping. And four mouse clicks will draw a bezier curve. All shape colors are random so you can see the difference between them

Hw4
























int xMax=720;
int yMax=480;
int xclipMax=540;
int yclipMax=360;
int xclipMin=180;
int yclipMin=120;
int top=0;
int bottom = 0;
int right = 0;
int left = 0;
//1001 1000 1010
//0001 0000 0010
//0101 0100 0110



int coord;
int x0, x1,x2, y0,y1,y2,x3,y3;
void setup() {
size(720, 480);
background(0);

smooth();

}

void draw() {

noFill();
stroke(random(0,255),random(0,255), random(0,255));
line(180,0,180, height);
line(540,0,540, height);
line(0,120,width, 120);
line(0,360,width, 360);
stroke(255,0, 0);
rect(180,120,360,240);
stroke(random(0,255),random(0,255), random(0,255)); // draws shapes in random colors to see the diffrent shapes.


}
void keyPressed(){
if (key=='t'){ // draws a triangle using the given triangle function
triangle(random(xMax),random(yMax),random(xMax),random(yMax),random(xMax),random(yMax));
}
if (key=='l'){ // draws a triangle with created function and clips the lines
drawTriangle();
}

}
void mousePressed(){
println("x " +mouseX+" Y "+ mouseY); // test for coordinates

if (coord==0){
x0 = mouseX;
y0 = mouseY;
point(x0,y0);
println("x " +mouseX+" Y "+ mouseY);
coord =1;
}

else if (coord==1){
x1 = mouseX;
y1 = mouseY;
println("x " +mouseX+" Y "+ mouseY);
coord =2;
}

else if (coord==2){
x2 = mouseX;
y2 = mouseY;
println("x " +mouseX+" Y "+ mouseY);
coord =3;
}

else if (coord==3){
x3 = mouseX;
y3 = mouseY;
point(x3,y3);
bezier(x0,y0,x1,y1,x2,y2,x3,y3);
println("x " +mouseX+" Y "+ mouseY);
coord =0;
println("Bezier Curve is complete ");
}

}

/***********************************************************
* Draw random Triangles with 3 lines
*/
void drawTriangle(){
float a = random(xMax);
float c = random(xMax);
float e = random(xMax);
float b = random(yMax);
float d = random(yMax);
float f = random(yMax);
lineClip(a,b,c,d);
lineClip(c,d,e,f);
lineClip(e,f,a,b);
}

/***********************************************************
* Cohen-Sutherland Line Clipping Algorithm
*/
void lineClip(float x0, float y0, float x1,float y1){
int[] coord0 = new int[4];
int[] coord1 = new int[4];

//1001 1000 1010
//0001 0000 0010
//0101 0100 0110

for(int i = 0; i <>= xclipMax) { //if greater then 540
coord0[1]=1;
print(" right ");
print(" X0 " +x0);
}

if (y0 <= yclipMin) { //if less then 120 coord0[2]=1; print(" bottom "); print(" Y0 "+ y0); } else if ( y0 >= yclipMax) { //if greater tehn 360
coord0[3]=1;
print(" top ");
print(" Y0 " +y0);
}
/***********************************************************
* Second set of points
*/
if (x1 <= xclipMin) { //if less then 180 coord1[0]=1; print(" left "); print(" X1 " +x1); } else if ( x1 >= xclipMax) { //if greater then 540
coord1[1]=1;
print(" right ");
print(" X1 " +x1);
}

if (y1 <= yclipMin) { //if less then 120 coord1[2]=1; print(" bottom "); print(" Y1 "+ y1); } else if ( y1 >= yclipMax) { //if greater tehn 360
coord1[3]=1;
print(" top ");
print(" Y1 " +y1);
}


if ((coord0[0]coord1[0]) == 0 && (coord0[1]coord1[1]) == 0 && (coord0[2]coord1[2]) == 0 && (coord0[3]coord1[3]) == 0){ // test one check if the line is inside the box
line(x0,y0,x1,y1); //draw the line freely
println("Line completley in the square ");
}
else if (((coord0[0]&coord1[0]) != 0) ((coord0[1]&coord1[1]) != 0) ((coord0[2]&coord1[2]) != 0) ((coord0[3]&coord1[3]) != 0)){
println(" Line not Drawn outside the box ");
}
else {

// huge else start
float modX0 = x0;
float modY0 = y0;
float modX1 = x1;
float modY1 = y1;
//1001 1000 1010
//0001 0000 0010
//0101 0100 0110
//clip first set of points
if (coord0[0] == 1){ //if left
if (modX0 <= xclipMin modX0 >= xclipMax){
modY0 = y0 + (y1 - y0) * (xclipMin - x0) / (x1 - x0);
modX0 = xclipMin;
println(" 0 left ");
}
}
else if (coord0[1] == 1) { //if right
if (modX0 <= xclipMin modX0 >= xclipMax){
modY0 = y0 + (y1 - y0) * (xclipMax - x0) / (x1 - x0);
modX0 = xclipMax;
println(" 0 right ");
}
}
if (coord0[2] == 1 ) { //if bottom
if (modY0 <= yclipMin modY0 >= yclipMax) {
modX0 = x0 + (x1 - x0) * (yclipMin - y0) / (y1 - y0);
modY0 = yclipMin;
println(" 0 bottom ");
}
}
else if (coord0[3] == 1){ //if top
if (modY0 <= yclipMin modY0 >= yclipMax){
modX0 = x0 + (x1 -x0) * (yclipMax - y0) / (y1 - y0);
modY0 = yclipMax;
println( "0 top ");
}
}
//1001 1000 1010
//0001 0000 0010
//0101 0100 0110
//clip first second set of points
if (coord1[0] == 1){ //if left
if (modX1 <= xclipMin modX1 >= xclipMax){
modY1 = y0 + (y1 - y0) * (xclipMin - x0) / (x1 - x0);
modX1 = xclipMin;
println(" 1 left ");
}
}
else if (coord1[1] == 1) { //if right
if (modX1 <= xclipMin modX1 >= xclipMax){
modY1 = y0 + (y1 - y0) * (xclipMax - x0) / (x1 - x0);
modX1 = xclipMax;
println(" 1 right ");
}
}
if (coord1[2] == 1 ) { //if bottom
if (modY1 <= yclipMin modY1 >= yclipMax) {
modX1 = x0 + (x1 - x0) * (yclipMin - y0) / (y1 - y0);
modY1 = yclipMin;
println(" 1 bottom ");
}
}
else if (coord1[3] == 1){ //if top
if (modY1 <= yclipMin modY1 >= yclipMax){
modX1 = x0 + (x1 -x0) * (yclipMax - y0) / (y1 - y0);
modY1 = yclipMax;
println( "1 top ");
}
}
if (modX0 >= xclipMin && modX0 <= xclipMax && modX1 >= xclipMin && modX1 <= xclipMax) { if (modY0 >= yclipMin && modY0 <= yclipMax && modY1 >= yclipMin && modY1 <= yclipMax) { line(modX0,modY0,modX1,modY1); // modded line } } } // end the huge else } // end line clip function

Saturday, January 31, 2009

Project

This graphic looks to be done with a lot of bezier curves. To give the look of dark colors the bezier curves are closer together and a higher quantity.
This drawing is kind of confusing to see which end belongs to which end. Your eyes try to follow a curve and you think you figured it out but then it splits. The drawing kind of reminds me of a bio hazard symbol.

Homework # 3

This program draws a bezier curve with 4 mouse clicks and draws triangles with random cordinates when the "t" key is pressed to draw a triangle with the triangle function and "L" to draw a triangle using 3 lines.

int xMax=720;
int yMax=480;
int coord;
int x0, x1,x2, y0,y1,y2,x3,y3;
void setup() {
size(720, 480);
background(0);
smooth();
}

void draw() {

noFill();
stroke(random(100,255),random(100,255), random(100,255));
//test();
//line(pmouseX, pmouseY, mouseX, mouseY);
}
void keyPressed(){
if (key=='t'){
triangle(random(xMax),random(yMax),random(xMax),random(yMax),random(xMax),random(yMax));
}
if (key=='l'){
drawTriangle();
}

}
void mousePressed(){

if (coord==0){
x0 = mouseX;
y0 = mouseY;
point(x0,y0);
println("x " +mouseX+" Y "+ mouseY);
coord =1;
}

else if (coord==1){
x1 = mouseX;
y1 = mouseY;
println("x " +mouseX+" Y "+ mouseY);
coord =2;
}

else if (coord==2){
x2 = mouseX;
y2 = mouseY;
println("x " +mouseX+" Y "+ mouseY);
coord =3;
}

else if (coord==3){
x3 = mouseX;
y3 = mouseY;
point(x3,y3);
bezier(x0,y0,x1,y1,x2,y2,x3,y3);
println("x " +mouseX+" Y "+ mouseY);
coord =0;
}

}


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

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



Thursday, January 22, 2009

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

void draw() {
stroke(255,mouseX, 0);
bezierLine(0, 0, 400, 400);
bezierLine(400, 0, 0, 400);
bezierLine(width/2, 0, width/2, 400);
bezierLine(0, height/2, 400, height/2);
stroke(mouseX,255, 0);
bezierQuad(100, height/2, width/2, 400, 300, height/2);
bezierQuad(100, height/2, width/2, 0, 300, height/2);
stroke(mouseX,0, 255);
bezierCubic(0, height/2, 100, 100, 300, 300, 400, height/2);
bezierCubic(400, height/2, 100, 100, 300, 300, 0, height/2);
}

void bezierLine(int x0, int y0, int x1, int y1) {
float x, y;
for(float t = 0; t <= 1; t += 0.001){
//p0 = (x0,y0)
// p1 = (x1,y1)
//t= (x,y)
//B(t)=p0+t(p1-p0)
x = x0 +t*(x1-x0);
y = y0 +t*(y1-y0);
point(x, y);
}
}

void bezierQuad(int x0, int y0, int x1, int y1, int x2, int y2){
float x, y;
for(float t = 0; t < 1; t += 0.001){
x = sq(1-t)*x0+2*(1-t)*t*x1 +sq(t)*x2;
y = sq(1-t)*y0+2*(1-t)*t*y1 +sq(t)*y2;
point(x, y);
}
}

void bezierCubic(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3){
float x, y;
for(float t=0; t < 1; t += 0.001){
x=pow((1-t),3) * x0 + 3 * sq(1-t) * t * x1 + 3*(1-t)*sq(t)* x2 + pow(t,3) *x3;
y=pow((1-t),3) * y0 + 3 * sq(1-t) * t * y1 + 3*(1-t)*sq(t)* y2 + pow(t,3) *y3;
point(x, y);
}
}

Monday, January 12, 2009

Homework # 2


void setup() {
size(400, 400);
stroke(255);

}

void draw() {
background(0);
stroke(100);
drawLine(0,165,0,200);

//Draw A spider body
stroke(200);
drawCircle(width/2, height/2, 50); //body
drawCircle(width/2+(20), height/2-(20), 10); //right eye
drawCircle(width/2-(20), height/2-(20), 10); //left eye
stroke(255,0,0);
arc(width/2,height/2,40,40,0,PI); //mouth
noFill();
stroke(mouseX,mouseX,mouseY);
//right legs
arc(305,height/2-20,120,40,PI,0);
arc(310,height/2,120,40,PI,0);
arc(305,height/2+20,120,40,PI,0);
arc(295,height/2+40,120,40,PI,0);
//left legs
arc(95,height/2-20,120,40,PI,0);
arc(90,height/2,120,40,PI,0);
arc(95,height/2+20,120,40,PI,0);
arc(105,height/2+40,120,40,PI,0);

stroke(100);
drawWeb(400);
stroke(255,0,0);
drawCircle(width/2+(20), height/2-(20), 5); //right eye
drawCircle(width/2-(20), height/2-(20), 5); //left eye

}
/***************************************************************
*Draw A Line
***************************************************************/
void drawLine(int x0,int x1,int y0,int y1)
{

int changeX = x1-x0;
int changeY = y1-y0;
float slope;
if((x1-x0)!=0){
slope = changeY/changeX;
int y=y0;
if (changeX !=0)
{
for (int x=x0; x {
point(x,y);
y=y+1;
}
}
}
else println("error");
}
/***************************************************************
*Draw A Circle
***************************************************************/

void drawCircle(int x0, int y0, int radius)
{
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;

point(x0, y0 + radius);
point(x0, y0 - radius);
point(x0 + radius, y0);
point(x0 - radius, y0);

while(x < y)
{
// assert(ddF_x == 2 * x + 1);
// assert(ddF_y == -2 * y);
// assert(f == x*x + y*y - radius*radius + 2*x - y + 1);
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
point(x0 + x, y0 + y);
point(x0 - x, y0 + y);
point(x0 + x, y0 - y);
point(x0 - x, y0 - y);
point(x0 + y, y0 + x);
point(x0 - y, y0 + x);
point(x0 + y, y0 - x);
point(x0 - y, y0 - x);
}
}

/***************************************************************
*Draw A Web
***************************************************************/

void drawWeb(int n)
{

for(int i = 0; i < n; i++)
{
if(i%9==0)
line(0, n-i, i, 0);

}
}

Thursday, January 8, 2009

Processing 1.0 Simple Sketch




void setup() {
size(400, 400);
stroke(255);
background(192, 64, 0);
}

void draw() {
background(0, 255, mouseX, mouseY);
fill(99, 40, mouseX, mouseY);

//Draw Head
ellipse(width/2,height/2,50,50);
fill(200, 90, mouseX, mouseY);
ellipse(190,190, mouseX/16, mouseY/16);
fill(200, 200, mouseX, mouseY);
ellipse(210,190, mouseX/16, mouseY/16);
fill(50, 50, mouseX, mouseY);
ellipse(200,210, mouseX/10, mouseY/10);

//Draw Body
fill(40, 90, mouseX, mouseY);
rect(((width/2)-10),((height/2)+25),20,60);

//Limbs
line(170,260, ((width/2)-10),250); //left arm
line(170,260, mouseX,250); //left arm
line(260,height/2, ((width/2)+10),250); //right arm
line(190,((height/2)+85), 170,325); //left leg
line(210,((height/2)+85), 230,325); //right leg
}