Lion_Kor

Recursive Tree (Processing, Java)

Feb 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. //made using processing 3.3.6 http://processing.org (Java)
  2. //after https://www.youtube.com/watch?v=0jjeOYMjmDU
  3.  
  4. float fac;
  5. float angle;
  6. boolean pause;
  7. int counter;
  8.  
  9. void setup() {
  10.   size(800, 700);
  11.   noSmooth();
  12.   frameRate(120);
  13.   background(0);
  14.   fac = 0.665;
  15.   angle = radians(0);
  16.   pause = false;
  17.   counter = 0;
  18. }
  19.  
  20. void draw() {
  21.   String file = "frames/####.tif";
  22.   saveFrame(file);
  23.   counter += 1;
  24.   if (!pause) {
  25.     background(0);
  26.     if ( degrees(angle) >= 360 ) {
  27.       angle = 0;
  28.       exit();
  29.     }
  30.     angle += 0.01;
  31.     float f = (float)((int)(degrees(angle) * 10)) / 10;
  32.     textSize(20);
  33.     fill(255);
  34.     text(f + "°", 10, 60);
  35.     translate(width/2, height);
  36.     stroke(255);
  37.     branch(height/3);
  38.   }
  39. }
  40.  
  41. void branch(float len) {
  42.   if (len >= 1) {
  43.     line(0, 0, 0, -len);
  44.     translate(0, -len);
  45.     pushMatrix();
  46.     rotate(angle);
  47.     branch(len * fac);
  48.     popMatrix();
  49.     pushMatrix();
  50.     rotate(-angle);
  51.     branch(len * fac);
  52.     popMatrix();
  53.   }
  54. }
  55.  
  56. void mousePressed() {
  57.   if ( pause ) {
  58.     pause = false;
  59.   } else {
  60.     pause = true;
  61.   }
  62. }
  63. //inspired by https://www.youtube.com/watch?v=0jjeOYMjmDU
Advertisement
Add Comment
Please, Sign In to add comment