- 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() {
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() {
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;
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);
}
size(300, 300);
}
void draw() {
drawMyWeb(75);
}
drawMyWeb(75);
}
void drawMyWeb(int n) {
for(int i=0; i < n; i++){
line(0,n-i,i,0);
}
for(int i=0; i < n; i++){
line(0,n-i,i,0);
}
}

No comments:
Post a Comment