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

Monday, January 12, 2009

Homework #2 - Line, Circle, Web

For this homework assignment, I had to:
- Create a line using only point commands and without using the line command from Processing.
- Create a circle using only point commands and without using the ellipse command from Processing.
- Create a "web" using a grid of straight lines by calling the line command over and over again.








//Line
void setup() {
size(300, 300);
}
void draw() {
drawMyLine(20, 100, 20, 100);
}

void drawMyLine(int x1, int x2, int y1, int y2){
int dx = x2-x1;
int dy = y2-y1;
float error = 0;
float slope = (float)dy/dx;
int y = y1;

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

//Circle
void setup() {
size(300, 300);
}
void draw() {
drawMyCircle(150, 150, 100);
}

void drawMyCircle(int x1, int y1, int radius){
int f = 1 - radius;
int fx = 1;
int fy = -2*radius;
int x=0;
int y=radius;
point(x1,y1+radius);
point(x1,y1-radius);
point(x1+radius,y1);
point(x1-radius,y1);

while(x <>
if(f>=0){
y--;
fy += 2;
f += fy;
}
x++;
fx += 2;
f += fx;
point(x1 + x,y1 + y);
point(x1 - x,y1 + y);
point(x1 + x,y1 - y);
point(x1 - x,y1 - y);
point(x1 + y,y1 + x);
point(x1 - y,y1 + x);
point(x1 + y,y1 - x);
point(x1 - y,y1 - x);
}
}
//Web
void setup() {
size(300, 300);
}
void draw() {
drawMyWeb(75);
}
void drawMyWeb(int n) {
for(int i=0; i < n; i++){
line(0,n-i,i,0);
}
}

Thursday, January 8, 2009

Homework #1 - Sheep



size(200, 200);
ellipse(100, 100, 100, 70);
ellipse(50, 100, 25, 70);
ellipse(45, 90, 7, 15);
ellipse(50, 131, 13, 7);
line(57, 90, 70, 110);
line(150, 100, 170, 70);
line(75, 130, 60, 160);
line(75, 130, 90, 160);
line(125, 130, 110, 160);
line(125, 130, 140, 160);