Thursday, January 22, 2009

Web Assignment 1 - Bezier curve: Line, Quadratic, and Cubic


Wow, this was very interesting assignment to do. I was confused at first but now it makes sense.

- I had to create another formula to draw a line without using y=mx+b formula, but using a parametric/Bezier equation to draw the line.
- Also, I had to create a formula to draw a quadratic curve using Bezier's formula.
- Finally, I used the cubic formula from Bezier to create the cubic curve.

//Brandon Hilton
//CSC 370
//Eric Patterson
//Web Assignment #1

void setup() {
size(300, 300);
}

void draw() {
stroke(255, 255, 255);
myLine(10, 40, 50, 90);

stroke(255, 0, 0);
myquad(10, 150, 30, 200, 210, 210);

stroke(0, 0, 255);
mycubic(20, 30, 90, 15, 85, 60, 20, 60);
}

void myLine(int x0, int y0, int x1, int y1) {
float x, y;
for(float t = 0.0f; t < 1; t += 0.00001){
x = x0 + t*(x1 - x0);
y = y0 + t*(y1 - y0);
point(x, y);
}
}

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

void mycubic(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.00001){
x = (1-t)*(1-t)*(1-t)*x0 + 3*(1-t)*(1-t)*t*t*x1 + 3*(1-t)*t*t*x2 + t*t*t*x3;
y = (1-t)*(1-t)*(1-t)*y0 + 3*(1-t)*(1-t)*t*t*y1 + 3*(1-t)*t*t*y2 + t*t*t*y3;
point(x, y);
}
}

No comments:

Post a Comment