Guest User

Untitled

a guest
May 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. /*
  2. keys:
  3. UP: more recursion
  4. DOWN: less recursion
  5. */
  6.  
  7. int aMax = 200;
  8. int steps = 9;
  9.  
  10. void setup(){
  11. size(700, 700);
  12. }
  13.  
  14. void draw(){
  15. background(255);
  16. stroke(0);
  17. noFill();
  18. noLoop();
  19. rTriangle(width/2, height/2, aMax, 0);
  20. }
  21.  
  22. void rTriangle(float x, float y, float a, int step){
  23. if(step >= steps) return;
  24. float h = sqrt(3)/2*a;
  25. triangle(x-a/2, y-h/2, x+a/2, y-h/2, x, y+h/2);
  26. float hNew = sqrt(3)/2*a/2;
  27. // top
  28. rTriangle(x, y-h/2-hNew/2, a/2, step+1);
  29. // left
  30. rTriangle(x-a/2, y+hNew/2, a/2, step+1);
  31. // right
  32. rTriangle(x+a/2, y+hNew/2, a/2, step+1);
  33. }
  34.  
  35. void keyPressed(){
  36. if(keyCode == UP) steps++;
  37. else if(keyCode == DOWN) steps--;
  38. redraw();
  39. }
Add Comment
Please, Sign In to add comment