> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.TZV33UvCsMk/rev.2631
 * 
 * authors: 
 *   scudly
 *   
 *   

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



float cloudx;
float cloudy;

// mid-point of tower base is at (x,y)
void drawTower( int id ) {
    float TOWER_WIDTH = 40;
    float TOWER_HEIGHT = 200;
    pushMatrix();
    noStroke();
    // wall
    fill( 150 );
    rect( -TOWER_WIDTH/2, -TOWER_HEIGHT, TOWER_WIDTH, TOWER_HEIGHT );
    ellipse( 0, 0, TOWER_WIDTH, 10 );
    // windows
    fill( 60 );
    rect( -TOWER_WIDTH/4,   -TOWER_HEIGHT*0.9, 4, 12 );
    rect(  TOWER_WIDTH/4-4, -TOWER_HEIGHT*0.7, 4, 12 );
    rect( -TOWER_WIDTH/4+4, -TOWER_HEIGHT*0.5, 4, 12 );
    // roof
    fill( 160, 120, 80 );
    translate( 0, -TOWER_HEIGHT );
    triangle( 0, -40, -TOWER_WIDTH/2-10, 0, TOWER_WIDTH/2+10, 0 );
    fill(255, 0, 0);
    triangle(0, -40, 0, -50,
            -20+5*noise(frameCount*0.02,137+id*0.2), -45+15.0*noise(frameCount*0.02, 0.5, id*0.2) );
    popMatrix();
}

void drawGate(float x, float y) {
    pushMatrix();
    translate( x, y );
    fill( 80 );
    rect( -20, -40, 40, 40 );
    ellipse( 0, -40, 40, 40 );
    fill( 60 );
    rect( -17, -40, 34, 40 );
    ellipse( 0, -40, 34, 34 );
    popMatrix();
}

void drawCastle() {
    float WALL_WIDTH = 300;
    float WALL_HEIGHT = 120;
    noStroke();

    // back towers
    pushMatrix();
    translate( -90, -20 );
    scale( 0.8, 0.8 );
    drawTower( 1 );
    popMatrix();
    pushMatrix();
    translate( 90, -20 );
    scale( 0.8, 0.8 );
    drawTower( 2 );
    popMatrix();
    
    // middle tower
    pushMatrix();
    translate(0, -20);
    scale(1.4, 1.0);
    drawTower(3);
    popMatrix();
    
    // front wall
    fill( 130 );
    rect( -WALL_WIDTH/2, -WALL_HEIGHT, WALL_WIDTH, WALL_HEIGHT );
    for( float x=-WALL_WIDTH/2; x<WALL_WIDTH/2; x+=8 ) {
        rect( x, -WALL_HEIGHT-4, 4, 4 );
    }
    drawGate( 0, 0 );

    // windows
    fill( 60 );
    for( float i=0; i<240; i+=60 ) {
        rect( i-95, -90, 10, 10 );
        ellipse( i-90, -90, 10, 10 );
    }

    // front towers
    pushMatrix();
    translate( -150, 0 );
    drawTower( 4 );
    popMatrix();
    pushMatrix();
    translate( 150, 0 );
    drawTower( 5 );
    popMatrix();
}

void setup() {
    size( 500, 400 );
    smooth();
    cloudx = width+40;
    cloudy = random( 20, 40 );
}

void draw() {
    background( 160, 180, 250 );

    // clouds
    noStroke();
    fill( 235 );
    ellipse( cloudx, cloudy, 40, 20 );
    ellipse( cloudx+15, cloudy+5, 45, 15 );
    cloudx -= 0.5;
    if( cloudx < -40) {
        cloudx = width + 30;
        cloudy = random( 20, 40 );
    }
    
    // ground
    fill( 64, 140, 80 );
    ellipse( width / 4, height * 5 / 6, width*2, height / 2 );
    
    pushMatrix();
    translate( 250, 300 );
    //scale(0.25);
    drawCastle();
    popMatrix();
    
    // road
    fill( 100, 90, 70 );
    beginShape();
    vertex( 266, 300 );
    bezierVertex( 266, 350, 240, 350, 220, 400 );
    vertex( 150, 400 );
    bezierVertex( 180, 350, 230, 350, 234, 300 );
    endShape();

    // tree
    stroke( 128, 96, 32 );
    noFill();
    strokeWeight( 2 );
    pushMatrix();
    translate( width*0.9, height * 0.9 );
    float treex1 = noise(frameCount*0.02, 0.2);
    float treex2 = noise(frameCount*0.02, 0.4);
    bezier( 0.0, 0.0,  treex1*8, -50,  treex1*12-20, -50,  treex1*18-20, -30 );
    bezier( 0.0, 0.0,  treex2*5, -50,  treex2*15+20, -50,  treex2*20+20, treex2*10-80 );
    popMatrix();
}