I’m new to Processing, and am trying a short script to become familiar with it. The script draws and bisects right triangles. It works ok, but after the 5th iteration, it starts to print an extra line, and I can’t seem to find any reason why in the code. The code will draw the new triangle and then a line to a distant point.
I understand there may be other shape functions. I just simply wanted to use the line function for this.
Here’s the code. Could someone tell me if I’m approaching this incorrectly:
float x1 = 0;
float y1 = 0;
float x2 = 500;
float y2 = 500;
float x3 = 0;
float y3 = 500;
int count = 0;
int mag = 2;
void setup() {
size(600, 600);
background(255);
}
void drawline() {
line(x1,y1,x2,x2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
void nextpoints() {
float x3new = (x2 + x1) / 2;
float y3new = (y2 + y1) / 2;
x1 = x2;
y1 = y2;
x2 = x3;
y2 = y3;
x3 = x3new;
y3 = y3new;
}
void draw() {
//float pwr = pow(10,mag);
//int intpwr = (int) pwr;
int ptsperframe = 1;
count++;
for (int i = 0; i < ptsperframe; i++) {
drawline();
nextpoints();
}
}