Mariana Oyanedel: recursividad

De Casiopea




TítuloMariana Oyanedel: recursividad
AsignaturaImagen Escrita
Del CursoImagen Escrita 2017
Alumno(s)Mariana Oyanedel


<processingjs> float REC = PI/10;


void setup() {

 fullScreen();
stroke(255, 100);
 noLoop();
 smooth();

}

void mouseMoved() {

 redraw();

}

void draw() {

 background(0);
 drawYr(width/2, height, 100, mouseX / 10);
 println(mouseX / 10);

}

void drawYr(float x, float y, float t, int l) {

 strokeWeight(t/7);      // grosor de la línea proporcional a 't'
 float amp = t/7;        // aleatoreidad proporcional a 't'
 l = constrain(l, 0, 10); // mantener niveles razonables
 // definir punto del ramaje
 float x0 = x + random(-amp, amp*2);
 float y0 = y - t/2 + + random(-amp, amp*2);
 line(x, y, x0, y0);             // tronco
 // definir número de ramas
 int b = round(random(0, 4)); // número de ramas
 for (int i = 0; i < b; i++) {
   float x1 = x + random(-t, t);
   float y1 = y - t + random(-amp, amp); 
   strokeWeight(t/7); 
   line(x0, y0, x1, y1);
   // Recursión
   if (l > 0) {
     drawYr(x1, y1, random(t/2, t), l-1);
   }
 }
 //probar con cur-rec-ramlength
 
 if (mousePressed){
 REC = map (mouseX, 0, width, 0, PI);
 }
   
   translate(width / 2, height);
   rotate(-HALF_PI);
   CUR(100,REC);

}

void CUR(float ramLength, float angulo) {

// line (0,0,100, ramLength);
 
 translate (0, ramLength);
 ramLength = ramLength * 0.5;

if (ramLength < 5) {

 pushMatrix();
 rotate(angulo);
 CUR(ramLength, angulo);
 popMatrix();
 pushMatrix();
 rotate(-angulo);
 CUR(ramLength, angulo);
popMatrix();}

}


// función primera, no recursiva void drawY(float x, float y, float t) {

 line(x, y, x, y - t/2);               // tronco
 line(x, y - t/2, x - t/2, y - t);   // rama izq
 line(x, y - t/2, x + t/2, y - t);   // rama der

}

</processingjs>