import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 

public class int_arbor extends BApplet {
/*interactive arborization fractal
by Alessandro Capozzo -29 July 2003-
Inspired by Bruno Munari and J.Maeda works
P.S. I used a sample of code by Fry for Y rotation
*/

float xmag=0;
float newXmag=0;
int mod=0;
int ct=0;
void setup() 
{
  size(600, 400);
  
  colorMode(RGB, 255);
  background(230, 230, 230);
  ct=190; 

}

void loop(){
  translate(width/2, 300);

  newXmag = mouseX/(float)(width) * TWO_PI;
  
  
  float diff = xmag-newXmag;
  if (abs(diff) >  0.01f) { 
    xmag -= diff/4.0f; 
  }

 
 rotateY(xmag);
  mod=100 +(int)((height-mouseY)/2);
   translate(0,mod);
  float dd=((mouseX-width/2)*0.0005f);
  drawL(mod,true,1-dd);

}

void drawL (int lung, boolean start,float coef){
    
     if (start){
     
    push();
    stroke(ct-lung,200,ct-lung);
    line(0,-lung,0,0);
    
    
    pop();
    lung=(int)(lung/2);
    drawL(lung,false,coef);
    } else {
     
     push();
     translate(0,-lung*2);
     
     push();
     rotateZ(TWO_PI/coef);
     stroke(ct-lung,200,ct-lung);
      line(0,-lung,0,0);
          if(lung>3){
          drawL(lung/2,false,coef);
     }
    pop();
    
    push();
    rotateZ(TWO_PI/-coef);
    stroke(ct-lung,200,ct-lung);
    line(0,-lung,0,0);
      if(lung>3){
    
      drawL(lung/2,false,coef);
     }
    pop();
         push();
     rotateX(TWO_PI/coef);
     stroke(ct-lung,200,ct-lung);
      line(0,-lung,0,0);
          if(lung>3){
          drawL(lung/2,false,coef);
     }
    pop();
    
    push();
    
    rotateX(TWO_PI/-coef);
    stroke(ct-lung,200,ct-lung);
     line(0,-lung,0,0);
      if(lung>3){
    
      drawL(lung/2,false,coef);
     }
    pop();
    pop();


    }

    
  

}


}