Recursion Basic Learning Topic Adapted to Triangles
in
Programming Questions
•
8 months ago
Hi Everybody,
I was looking through the basic learning topics and saw recursion and thought I would try adapting it so equilateral triangles would occur inside of one another.
Here is my code:
Here is my code:
void setup() {
size(500, 500);
smooth();
}
void draw() {
translate(width/2, height/2);
background(255);
Triangles(0, -200, 173, 100, -173, 100, 3);
}
void Triangles(int x1, int y1, int x2, int y2, int x3, int y3, int level) {
triangle(x1, y1, x2, y2, x3, y3);
if (level > 1) {
level -= 1;
Triangles((x1+x2/2), (y1+y2)/2, (x2+x3)/2, (y2+y3)/2, (x3+x1)/2, (y3+y1)/2, level);
}
}
The trouble with this is that if I make the number of levels more than 2 it wont work correctly. Can someone help me find the mistake I made in programming this? Thanks!
-Grayson
-Grayson
1