Zooming in
in
Programming Questions
•
1 years ago
I wanted to make a sketch that draws a triangle, and then finds the midpoint of all three sides and draws a triangle in between those points, so that it's a triangle within a triangle within a triangle etc. That's the best way i can explain but if you run the code you can see what I mean.
Anyways I did make the sketch and it was easier than i thought, and i think that it would make a very cool effect, if you could somehow zoom in while the triangles are being drawn smaller and smaller... This is 2d, and there's no background(); in draw so i guess you could do it somehow with get();, but I'm not sure how to go about this.... here is my code:
float x1, y1, x2, y2, x3, y3;
float avx1, avy1, avx2, avy2, avx3, avy3;
void setup() {
size(700, 700);
background(0);
smooth();
x1=random(0, width);
x2=random(0, width);
x3=random(0, width);
y1=random(0, height);
y2=random(0, height);
y3=random(0, height);
frameRate(5);
}
void draw() {
fill(0);
stroke(255);
triangle(x1, y1, x2, y2, x3, y3); //draw
avx1=(x1+x2)/2; // get the midpoint of each side by averaging the points
avy1=(y1+y2)/2;
avx2=(x2+x3)/2;
avy2=(y2+y3)/2;
avx3=(x3+x1)/2;
avy3=(y3+y1)/2;
x1=avx1; // set the old points to the new midpoints
y1=avy1;
x2=avx2;
y2=avy2;
x3=avx3;
y3=avy3;
}
I know i could find the center of the triangle by averaging the three points, so that would be the place to set the get();... thanks for any ideas
1