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
}