Sean Leo – Project 11 – generative skyscape

sleo-project_11

//Sean B. Leo
//sleo@andrew.cmu.edu
//Section C

//Project 11 - generative landscape
var terrainSpeed = 0.0005;
var terrainDetail = 0.001;
var clouds = []; //background clouds
var clouds2 = []; //foreground clouds
var c1, c2;

function setup() {
  createCanvas(480, 480);
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        clouds[i] = makeClouds(rx);
        clouds2[i] = makeClouds2(rx);
    }
   frameRate(30);
}

function draw() {
  //background gradient colors
  c1 = color(40, 90, 255,10);
  c2 = color(250, 250, 240);
  setGradient(c1, c2);
   
    updateClouds();
    removeClouds();
    addRandomClouds(); 
    
}

function setGradient(c1, c2) {
  noFill();
  for (var y = 0; y < height; y++) {
    var inter = map(y, 0, height, 0, 1);
    var c = lerpColor(c1, c2, inter);
    stroke(c);
    line(0, y, width, y);
  }
}


function updateClouds(){
    // Update the cloud positions
    for (var i = 0; i < clouds.length; i++){
        clouds[i].move();
        clouds[i].display();
    }
  for (var i = 0; i < clouds2.length; i++){
        clouds2[i].move();
        clouds2[i].display();
    }
}


function removeClouds(){
  var cloudsToKeep = [];
   var cloudsToKeep2 = [];
    for (var i = 0; i < clouds.length; i++){
        if (clouds[i].x + clouds[i].breadth > 0) {
            cloudsToKeep.push(clouds[i]);
        }
    }
    clouds = cloudsToKeep;
  for (var i = 0; i < clouds2.length; i++){
        if (clouds2[i].x + clouds2[i].breadth > 0) {
            cloudsToKeep2.push(clouds2[i]);
        }
    }
  clouds2 = cloudsToKeep2;
}


function addRandomClouds() {
    // probability of new cloud
    var newCloudLikelihood = 0.01; 
    if (random(0,1) < newCloudLikelihood) {
        clouds.push(makeClouds(width));
      clouds2.push(makeClouds2(width));
    }
}


//cloud positions
function cloudMove() {
    this.x += this.speed;
}
    

//draw clouds
function cloudDisplay() {
    //var bHeight = this.x; 
    fill(230, 230, 230, 155); 
    noStroke(); 
  
    push();
    translate(this.x, this.y+20);
    ellipse(0, 0, this.d/2, this.d/3);
    fill(220, 220, 220, 155); 
    noStroke();
    ellipse(0 - 10, 0 + 5, this.d*2, this.d* 1.3);
    fill(240, 240, 240, 190); 
    noStroke();
    ellipse(0 + 15, 0, this.d*1.2, this.d/2);
    pop();
}
function cloudDisplay2() {
    //var bHeight = this.x; 
    fill(255, 255, 255, 200); 
    noStroke(); 
    push();
    translate(this.x, this.y+20);
    ellipse(0, 0, this.d*1.1, this.d/1.2);
    fill(245, 245, 245, 200); 
    noStroke();
    ellipse(0 - 10, 0 + 5, this.d*3, this.d/ 1.3);
    fill(255, 255, 255, 200); 
    noStroke();
    ellipse(0 + 15, 0, this.d*1.2, this.d/2);
    pop();
}

function makeClouds(birthLocationX) {
    var cloud = {x: birthLocationX,
                y: random(0, height / 2),
    	        d: random(20, 80),
                breadth: 100,
                speed: -.1,
                move: cloudMove,
                display: cloudDisplay}
    return cloud;
}
function makeClouds2(birthLocationX) {
    var cloud2 = {x: birthLocationX,
                y: random(0, height / 2),
    	        d: random(20, 80),
                breadth: 100,
                speed: -.1,
                move: cloudMove,
                display: cloudDisplay2}
    return cloud2;
}



Leave a Reply