Thursday, January 22, 2009

Web Assignment #1

Bezier Curves (Linear, Quadratic, Cubic)

My Curves




void setup() {
size(400, 400);
background(0);
saveFrame("bezier.png");

}

void draw() {
stroke(233, 34, 300);
myBeZier(200, 300, 180, 95);
stroke(150, 20, 300);
myBeZquad(300, 200, 50, 270, 210, 310);
stroke(10, 30, 403);
myBeZcubic(350, 100, 350, 200, 150, 65, 90, 120);
}

//Linear Bezier Curve
//From formula B(t) = p0 + t(p1-p0) = (1-t)p0+tp1
void myBeZier(int x0, int y0, int x1, int y1) {
float x, y;
for(float t=0.0; t<=1; t+=0.0000005) {
x = x0 + t*(x1-x0);
y = y0 + t*(y1-y0);
point(x,y);
}

}
//Quadratic Bezier Curve
//From formula B(t) = (1-t)^2 p0+2(1-t)t p1+ t^2 p2
void myBeZquad(int x0, int y0, int x1, int y1, int x2, int y2) {
float x, y;
for(float t=0.0; t<=1; t+=0.0000005) {
x = pow((1-t), 2)*x0+ 2*(1-t)*t*x1+ pow(t, 2) * x2;
y = pow((1-t), 2)*y0+ 2*(1-t)*t*y1+ pow(t, 2) * y2;
point(x,y);

}

}
//Cubic Bezier Cube
//From formula B(t) = (1-t)^3 p0 + 3(1-t)^2 tp1+3(1-t)p2+t^3p3
void myBeZcubic(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) {
float x, y;
for(float t=0.0; t<=1; t+=0.0000005) {
x = pow((1-t), 3) * x0+3*(pow((1-t),2))*t*x1 + 3*(1-t)*t*t*x2 + (t*t*t)*x3;
y = pow((1-t), 3) * y0+3*(pow((1-t),2))*t*y1 + 3*(1-t)*t*t*y2 + (t*t*t)*y3;
point(x,y);

}
}

Thursday, January 15, 2009

**Homework 2** Hooray for the long weekend coming up! :-)


Homework #2
For this assignment we experimented with Bresenham's line algorithm and the midpoint circle algorithm. We then could either use the line algorithm or Processing's line function to draw a web. This is what I created!!!

Source code:
void setup() {
size(400, 400);
background(0);
int x0, x1, y0, y1;


}
void myLine(int x0, int x1, int y0, int y1) {
int changeX = x1-x0;
int changeY = y1-y0;
float bresenham = (float)changeY / changeX;
float error = 0;
int y = y0;

for(int x = x0; x <= x1; x++) {
point(x,y);
error = error + bresenham;
if(abs(error) >= 0.5) {
y = y + 1;
error = error - 1.0;
}

}

}

void drawWeb() {
stroke(255, 0, 128);
line(0, 100, 10, 0);
line(0, 90, 20, 0);
line(0, 80, 30, 0);
line(0, 70, 40, 0);
line(0, 60, 50, 0);
line(0, 50, 60, 0);
line(0, 40, 70, 0);
line(0, 30, 80, 0);
line(0, 20, 90, 0);
line(0, 10, 100, 0);


}

void myCircle(int x0, int y0, int radius) {


int f = 1 - radius;
int fxx = 1;
int fyy = -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)
{
if(f >= 0)
{
y--;
fyy += 2;
f += fyy;
}
x++;
fxx += 2;
f += fxx;
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);
}
}



void draw() {
//Changes the stroke of my line to Pink
stroke(255, 0, 128);
//Draws myLine (x0<=x1, y0<=y1)
myLine(150, 300, 100, 300);

//Draws myWeb
drawWeb();

//Draws myCirle
myCircle(190, 290, 100);

}

Thursday, January 8, 2009

My First Image !!!

Source Code:
size(400, 400);
background(68, 68, 68);
fill(188, 3, 133);
ellipseMode(CENTER);
ellipse(200,200,200,200);
fill(252, 241, 112);
ellipse(160, 160, 27, 27);
ellipse(240, 160, 27, 27);
fill(128, 236, 131);
ellipse(200, 200, 19, 19);
stroke(243, 141, 252);
line(150, 250, 250, 250);
fill(0);
ellipse(160, 160, 10, 10);
ellipse(240, 160, 10, 10);
stroke(45, 222, 236);
line(200, 300, 200, 400);
line(200, 350, 100, 270);
line(200, 350, 300, 270);
fill(128, 0, 255);
ellipse(150, 95, 30, 30);
ellipse(248, 95, 30, 30);









I had to do a print screen to save the image, is there an easier way?