I've finally gone back and tracked down my errors as well as compiled them into one nice image for homework 2. Here is the code:
void setup(){
size (400, 400);
background (0,0,0);
stroke (255);
}
void myCircle (int x0, int y0, int rad){
int f = 1 - rad;
int ddF_x = 1;
int ddF_y = -2 * rad;
int x = 0;
int y = rad;
point(x0, y0 + rad);
point(x0, y0 - rad);
point(x0 + rad, y0);
point(x0 - rad, y0);
while (x < y){
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);
}
}
void web(){
int x1, x2, y1, y2, n;
n = 500;
x1 = 0;
x2 = n;
y1 = 1;
y2 = 0;
int i;
for (i = 0; i < n; i++){
line (x1, x2, y1, y2);
x2-=10;
y1+=10;
}
}
void myLine(int x0, int y0, int x1, int y1){
boolean steep = (abs(y1 - y0) > abs(x1 - x0));
int temp;
if (steep){
temp = x0;
x0 = y0;
y0 = temp;
temp = x1;
x1 = y1;
y1 = temp;
}
if (x0 > x1){
temp = x0;
x0 = x1;
x1 = temp;
temp = y0;
y0 = y1;
y1 = temp;
}
int delta_x = x1 - x0;
int delta_y = abs(y1 - y0);
float error = 0;
float delta_err = (float)delta_y/delta_x;
int y_step;
int y = y0;
if (y0
}
else{
y_step = -1;
}
for (int x = x0; x < x1; x++){
if (steep){
point (y, x);
}
else{
point (x, y);
}
error += delta_err;
if (error >= 0.5){
y += y_step;
error -= 1.0;
}
}
}
void draw(){
web();
myCircle (200,200,50);
myLine (300, 80, 269, 300);
saveFrame("hw1.jpeg");
}
And now on to homework 3...
No comments:
Post a Comment