Project-05-Wallpaper

cybergoth dragon recursion!!!

sketch

// Zoe Lin (ID: youlin)
// Section B

function setup() {
  createCanvas(400, 600);
  noLoop();
  strokeWeight(0.025);
}

function draw() {
  callDragon(5, 5, width/1.5, height/2.5, 40);

function callDragon(x, y, width, height, d){
    background(255);
    d = map(40, 0, 60, 10, 16);

    push(); //dragon1
    drawDragon(x + width/3, y-2, width, height, d);
    pop();

    push(); //dragon2
    drawDragon(x + width/3, y+height+2, width, height, d);
    pop();
  
    push(); //dragon3
    drawDragon(x + width/3, y+height*2+2, width, height, d);
    pop();
  
    //push(); //dragon4
    //drawDragon(x + width/4.5, y+height*2.5, width, height, d);
    //pop();
}

function drawDragon(x, y, width, height, d){
    
    //draw
    triangle(x , y+height/2.5, x+width/2, y, x+width, y+height/2);
    translate(x, y+height/2);
  
    push();
    dragon(width, d);
    pop();
}

function dragon(len, d) {
    if (d <= 0) {
        return;
    }

    fill(255);
    triangle(0, 0, len/2, -(len/2), len/2.5, 0);
    push();

    var newLen = len/1.4;
    rotate(- PI/4);
    fill(0);
    triangle(0, 0, newLen, 0, newLen/2.5, -(newLen/2));
    dragon(newLen, d - 1); //recursion
    pop();

    push();
    translate(len, 1.4);
    rotate(-3 * PI/4);
    fill(0);
    triangle(0, 0, newLen, 0, newLen/2.5, -(newLen/3));
    dragon(newLen, d - 1);
    pop();  
}
}

Leave a Reply