Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- keys:
- UP: more recursion
- DOWN: less recursion
- */
- int aMax = 200;
- int steps = 9;
- void setup(){
- size(700, 700);
- }
- void draw(){
- background(255);
- stroke(0);
- noFill();
- noLoop();
- rTriangle(width/2, height/2, aMax, 0);
- }
- void rTriangle(float x, float y, float a, int step){
- if(step >= steps) return;
- float h = sqrt(3)/2*a;
- triangle(x-a/2, y-h/2, x+a/2, y-h/2, x, y+h/2);
- float hNew = sqrt(3)/2*a/2;
- // top
- rTriangle(x, y-h/2-hNew/2, a/2, step+1);
- // left
- rTriangle(x-a/2, y+hNew/2, a/2, step+1);
- // right
- rTriangle(x+a/2, y+hNew/2, a/2, step+1);
- }
- void keyPressed(){
- if(keyCode == UP) steps++;
- else if(keyCode == DOWN) steps--;
- redraw();
- }
Add Comment
Please, Sign In to add comment