Project 10-Chickoff

sketch

//Cora Hickoff
//Section D
//chickoff@andrew.cmu.edu
//Project 10

var terrain = [];

function setup() {

    createCanvas(480, 400); 
    frameRate(13);
    
    // create an initial collection of terrains
    for (var i = 0; i < 10; i++) {
        var rx = random(width);
        //"terrain" is the mountainous 
        //landscape at bottom of screen
        terrain[i] = makeTerrain(rx);
    }
}

function draw() {
    background(190, 140, 20); 
  
    updateAndDisplayTerrain();
    removeTerrainThatHasSlippedOutOfView();
    addNewTerrainWithSomeRandomProbability(); 

    drawTerrain(); 
}

function updateAndDisplayTerrain() {
    // Update the terrain's position, and display them.
    for (var i = 0; i < terrain.length; i++) {
        terrain[i].move();
        terrain[i].display();
    }
}

function removeTerrainThatHasSlippedOutOfView() {

    var terrainToKeep = [];
    for (var i = 0; i < terrain.length; i++) {
        if (terrain[i].x + terrain[i].breadth > 0) {
            terrainToKeep.push(terrain[i]);
        }
    }
    terrain = terrainToKeep; // remember the surviving terrain
}

function addNewTerrainWithSomeRandomProbability() {
    // With a very high probability, add a new terrain to the end.
    var newTerrainLikelihood = 1; 
    if (random(0,3) < newTerrainLikelihood) {
        terrain.push(makeTerrain(width));
    }
}

// method to update position of terrain every frame
function terrainMove() {
    this.x += this.speed;
}
    
// draw the mountain range
function terrainDisplay() {
    
    var floorHeight = 400;
    var bHeight = this.nFloors * floorHeight; 
    
        fill(154, 176, 119); 
        stroke(210, 164, 54); 
        strokeWeight(random(0,9));
        push();
        translate(this.x, height - 40);

        curveVertex(84,  91);
        curveVertex(68,  19);
        curveVertex(21,  107);
        curveVertex(0, -bHeight);

        stroke(74, 115, 119, 80); 
        strokeWeight(random(0,9));

    for (var i = 0; i < this.nFloors; i++) {

        beginShape();
        curveVertex(5, i * floorHeight);
        curveVertex(floorHeight, 34);
        curveVertex(68,  1);
        curveVertex(21,  107);
        curveVertex(400, 100);
        curveVertex(32, 100);
        endShape();

        beginShape();
        curveVertex(04, i * floorHeight);
        curveVertex(84,  91);
        curveVertex(68,  19);
        curveVertex(21,  107);
        curveVertex(3, 100);
        curveVertex(32, 100);
        endShape();
    }
        pop();

}

function makeTerrain(birthLocationX) {
    var trn = {x: birthLocationX,
                breadth: 50,
                speed: -1.0,
                nFloors: round(random(2,8)),
                move: terrainMove,
                display: terrainDisplay}
    return trn;
}

function drawTerrain() {

    fill(230, 160, 190);
    
    beginShape(); 
    for (var x = 10; x < width; x++) {
        var t = (x) + (millis() * 40);
        var y = map(noise(t), 0, 30, 10, height);
        vertex(x, y); 
    }
    endShape();

    //moon
    fill(240, 230, 74, 250);
    strokeWeight(random(0,9));
    ellipse(0, 0, width - 1, height - 1);

    //crater 1
    fill(250, 245, 140, 100)
    strokeWeight(random(0,4));
    ellipse(100, 23, 33, 33);

    //crater 1 faded edge
    fill(250, 245, 230, 100)
    strokeWeight(random(0,4));
    ellipse(100, 23, 23, 26);

    //crater 2
    fill(250, 245, 140, 100)
    strokeWeight(random(0,4));
    ellipse(123, 93, 33);

    //crater 3
    fill(250, 245, 230, 78)
    strokeWeight(random(0,4));
    ellipse(23, 53, 53, 46);

    //crater 4
    fill(250, 245, 230, 78)
    strokeWeight(random(0,4));
    ellipse(23, 153, 13, 16);

    //crater 5
    fill(250, 245, 140, 100)
    strokeWeight(random(0,4));
    ellipse(180, 0, 30, 30);

}

When I started this project, I knew that I wanted to create a landscape that involved nature. I wasn’t sure where to go with this until I started thinking about the idea of doing the opposite of a really lush landscape, and create something a bit more dead or barren. When I sketched, I thought about the idea of an asteroid, planet, or even our moon coming a little too close to Earth, enough to hurt the organisms living there.

I knew that to create this uneasy feeling, I’d have to play with color as well as a dizzying/shaky effect, which usually signals that something is wrong, and not everything is as it should be.

jennyzha – project 10

sketch

//Jenny Zhang
//jennyzha@andrew.cmu.edu
//Section D
//Project 10

var bird1;
var bird2;
var bird3;

var bird1X = 500;
var bird1Y = 150;
var bird2X = -200;
var bird2Y = 100;
var bird3X = 650;
var bird3Y = 200;

var birdWidth = 40;
var birdHeight = 30;

var cloud1;
var cloud2;
var cloud3;

var cloud1X = 700;
var cloud1Y = 60;
var cloud2X = 540;
var cloud2Y = 40;
var cloud3X = 700;
var cloud3Y = 60;

var cloudWidth = 40;
var cloudHeight = 30;

function preload() {
	bird1 = loadImage("https://i.imgur.com/nqLPhAm.png");
	bird2 = loadImage("https://i.imgur.com/nqLPhAm.png");
	bird3 = loadImage("https://i.imgur.com/nqLPhAm.png");
	
	cloud1 = loadImage("https://i.imgur.com/rkkaoGb.png");
	cloud2 = loadImage("https://i.imgur.com/rkkaoGb.png");
	cloud3 = loadImage("https://i.imgur.com/rkkaoGb.png");
}

function setup() {
	createCanvas(480,280);
	frameRate(120);
}

function draw(){
	background(248,248,255);
	drawhill();
	drawhill1();
	drawhill2();
	drawbird();
	drawcloud();
}


//draws the hilly background
var terrainSpeed = 0.00095;
var terrainSpeed1 = 0.0008;
var terrainSpeed2 = 0.00065;
var hill = 0.020;

function drawhill() {  
    noStroke();
    fill(154,205,50); 

    beginShape();
        for (x=0; x < width; x++) {
            var t = (x * hill) + (millis() * terrainSpeed);
            var y = map(noise(t), 0, .95, 120, 300);
            vertex(x, y);
            vertex(0, height);
            vertex(width, height);
        }
    endShape();
}

function drawhill1() {  
    noStroke();
    fill(85,107,47); 

    beginShape();
        for (x=0; x < width; x++) {
            var t = (x * hill) + (millis() * terrainSpeed1);
            var y = map(noise(t), 0, .8, 140, 300);
            vertex(x, y);
            vertex(0, height);
            vertex(width, height);
        }
    endShape();
}

function drawhill2() {  
    noStroke();
    fill(0,100,0); 

    beginShape();
        for (x=0; x < width; x++) {
            var t = (x * hill) + (millis() * terrainSpeed2);
            var y = map(noise(t), 0, .65, 160, 300);
            vertex(x, y);
            vertex(0, height);
            vertex(width, height);
        }
    endShape();
}


//draws the birds
function drawbird() {
	image(bird1, bird1X, bird1Y, birdWidth, birdHeight);
	bird1X -= random(1,2);
	bird1Y -= random(-0.5,0.5);

	if (bird1X < -birdWidth) {
		bird1X = 500;
	}

	image(bird2, bird2X, bird2Y, birdWidth, birdHeight);
	bird2X += random(0,0.5);
	bird2Y += random(-0.5,0.5);

	if (bird2X < -birdWidth) {
		bird2X = -100;
	}

	image(bird3, bird3X, bird3Y, birdWidth, birdHeight);
	bird3X -= random(0,2);
	bird3Y -= random(-0.5,0.5);

	if (bird3X < -birdWidth) {
		bird3X = 650;
	}
}

function drawcloud() {
	
	image(cloud1, cloud1X, cloud1Y, cloudWidth, cloudHeight);
	cloud1X -= random(0,2.5);
	cloud1Y -= random(-.25,.25);

	if (cloud1X < -cloudWidth) {
		cloud1X = 690;
	}

	image(cloud2, cloud2X, cloud2Y, cloudWidth, cloudHeight);
	cloud2X -= random(0,2.5);
	cloud2Y -= random(-.25,.25);

	if (cloud2X < -cloudWidth) {
		cloud2X = 530;
	}

	image(cloud3, cloud3X, cloud3Y, cloudWidth, cloudHeight);
	cloud3X -= random(0,2.5);
	cloud3Y -= random(-.25,.25);

	if (cloud3X < -cloudWidth) {
		cloud3X = 600;
	}	
}

With the cold weather coming upon us, I decided to create a spring theme as I begin to miss the warmer weather. Importing pictures from imgur using the preload function for the birds and clouds, I had them come flying across the screen as the code ran. As for the landscape/background, at first, I only had two hills for the terrain, but didn’t think it was enough and added the third layer. The same was true for the birds and clouds. At first I only had the birds, but then decided to import the clouds as well to create a fuller scene. Ultimately using the noise function, while playing with the inputs each time I was able to create a sense of depth.

dayoungl Project -10

sketch

//Sharon Lee
//dayoungl@andrew.cmu.edu
//Section E
//Assignment 10 - Generative Landscape
var terrainSpeed = 0.00015;
var terrainDetail = 0.001;
var parasol = [];
var cBlue = (115,151,232);
var cWhite = (234,238,247);
var x;
var y;
var location;


function preload(){
    imgParasol = loadImage("https://i.imgur.com/9wvs2bI.png");
    airplane = loadImage("https://i.imgur.com/M6sAe2x.png");
    airplane2 = loadImage("https://i.imgur.com/5j9Uq5v.png");
}

function updateParasols(){
    for (var i = 0; i < parasol.length; i ++){
        parasol[i].move();
        parasol[i].display();  
    }
}

function addParasols(){
    var a = random(1);
    if (a < 0.03){
        parasol.push(makeParasols(width));
        parasol.push(makeParasols(height));
    }
}

function moveParasols(){
    this.x += this.speed;
}


function makeParasols(pointX){
    var parasol1 = {x: pointX,
        number: floor(random(1,3)),
        speed: 0.001,
        height: random(0,50), 
        move: moveParasols,
        display: displayParasols}
    return parasol1;
}

function oceanTerrain(){
    //ocean layer-1
    noStroke();
    fill(77,124,191);
    beginShape();
    for (var x = 0; x < width; x++){
       var t = (x * terrainDetail) + (millis() * terrainSpeed);
       var y = map(noise(t), 0, 1, 0, height - 30);
        vertex(x,y);
    }
    curveVertex(width, height);
    curveVertex(0,width);
    endShape(CLOSE);

    //ocean layer-2
    noStroke();
    fill(77,124,191,120);
    for (var x = 0; x < width; x ++){
        var t = (x* terrainDetail * 2) + (millis() * terrainSpeed);
        var y = map(noise(t/2), 0, 1, 10, height - 50);
        vertex(x,y);    
    }
    curveVertex(width, height);
    curveVertex(0,width);
    endShape(CLOSE);
}

function displayParasols(){
    push();
    translate(this.x, this.height);
    for (var i = 0; i < this.number; i++){
        image(imgParasol, random(0, width),random(30,90));
    }
    pop();
}

function setup() {
    createCanvas(480,300);
    for(var i = 0; i < 5; i ++){
        location = random(width);
        parasol[i] = makeParasols(location);
    }
    frameRate(10);
}

function draw() {
    background(228,211,207);
   
    updateParasols();
    addParasols();
    displayParasols();
    moveParasols();
    makeParasols();
    oceanTerrain();

    image(airplane2, mouseX - 80, mouseY - 50);
    push();
    tint(255,128);
    image(airplane, mouseX + 50, mouseY - 150);
    pop();

}   







For project 10, I aimed to create a bird-eye-view landscape of a beach. Using the given terrain code, I manipulated it and lower the amount of noise so it resembles the smooth curves of the waves instead of pointy and rough terrain of mountains that the code was originally intended for. I added parasols as the elements to show the panning of the “camera”. I also added in airplane and its shadow just as a fun element users could play around by using their mouse.

myoungsh-project-10-houses

sketch

var house = [];
var houseImg = [];
function preload() {
  houseImg[3] = loadImage("https://i.imgur.com/wsrsd27.png");
  houseImg[2] = loadImage("https://i.imgur.com/AG35goZ.png");
  houseImg[1] = loadImage("https://i.imgur.com/PkUvm1J.png");
}  
function setup() {
  createCanvas(480, 480);
  for (var i = 0; i < 1; i++){
    var x = random(0,width);
    house[i] = makeHouse(x);
  }
  frameRate(10);
}
function draw(){
  background(256);
  updateNdisplayHouses();
  newHouses();
}
function updateNdisplayHouses() {
  for (var i = 0; i < house.length; i ++){
    house[i].move();
    house[i].display();
  }
}
function newHouses() {
  var newHouseProb = .015;
  if (random(0,1) < newHouseProb) {
    house.push(makeHouse(width));
  }
}
function houseMove() {
  this.x += this.speed;
}
function houseDisplay() {
  push();
  translate(this.x, 0);
  // var imgNum = floor(random(1, 3.99));
  image(houseImg[1], 0, 0);
  image(houseImg[2], 220, 0);
  image(houseImg[3], 400, 0);
  noStroke();
  fill(0);
  rect(0, 400, 2000, 80);
  for (var i = 0; i < 2000; i += 48) {
    fill(256, 256, 0);
    rect(i, 435, 28, 10);
  }
  pop();
}
function makeHouse(startLocationX) {
  var house = {x: startLocationX,
              speed: -5,
              move: houseMove,
              display: houseDisplay}
  return house;
}

amui1-Project-10-Landscape

amui1-p10

//Allison Mui
//15-104 Section A
//amui1@andrew.cmu.edu
//Project-10
//

//variables for image
var starImg = "https://i.imgur.com/0ns3TvE.png";
var monsterImg = "https://i.imgur.com/hqvDkxx.png";
var star;
var monster;
//variables for star positions
var sx = [];
var sy = [];
//variables for objects
var met = [];
var monst = [];
//variable for points
var counter = 0;


//loads images
function preload() {
  star = loadImage(starImg);
  monster = loadImage(monsterImg);
}


function setup(){
  createCanvas(480,380);
  //intializes meteor by calling make meteor. stores them in meteor array
  for (num = 0; num < 4; num++) {
    var ogX = random(width/2+width/4,width);

    met[num] = makeMet(ogX);

  }
  //intializes monster by calling make monster
  monst[0] = makeMonster();

  //creates random x and y locations for star
  for (s = 0; s < 15; s++) {
    sx.push(random(width));
    sy.push(random(height));
  }

  //loads star picture
  star.loadPixels();

}

function draw(){
  background(6,13,29);
  //shows picture of star in random x and y locations
  for (st = 0; st < 15; st++) {
    image(star,sx[st],sy[st]);
  }

  //displays meteor
  showMet();

  //constrains so space ship won't go off of screen
  var y = constrain(mouseY,45/2,height-38/2);
  var x = 80;
  //space ship
  fill(106,139,189);
  arc(x,y,45,45, PI, 0);
  fill(253,194,74);
  ellipse(x,y+6,50,25);
  ellipse(x,y+4,80,15);
  fill(68,110,172);
  ellipse(x,y,80,15);

  //displays monster
  showMonster();
  //keep tracks of points
  fill(255);
  text("Points:" + counter, 15, 20);
  text("Avoid the meteors!", width/2-50, 20);

}


function showMet() {
  //displays and moves all meteors in meteor array
  for (var i = 0; i < met.length; i++) {
      met[i].move();
      met[i].draw();

  }
}

function showMonster() {
  //displays and moves monster
  monst[0].move();
  monst[0].draw();
}




function drawMet() {
  //overall meteor
  var metSize = this.metSize;


  fill(146,164,174);
  noStroke();
  //meteor body
  ellipse(this.x,this.y,metSize,metSize);
  fill(75,99,107);
  //meteor blimps
  ellipse(this.x - 16, this.y, metSize/8,metSize/8);
  ellipse(this.x, this.y+17, metSize/8,metSize/8);
  ellipse(this.x + 8, this.y - 10, metSize/4, metSize/4);
  ellipse(this.x + 10, this.y + 10, metSize/10, metSize/10);

  //flames behind
  fill(247,223,61);
  rect(this.x+metSize/2+5, this.y-18,this.metSize+10,5,5);
  fill(243,161,28);
  rect(this.x+metSize/2+5,this.y-10,this.metSize+10-10,5,5);
  fill(247,223,61);
  rect(this.x+metSize/2+5, this.y-2, this.metSize+10-20,5,5);
  fill(243,161,28);
  rect(this.x+metSize/2+5,this.y+5,this.metSize+10,5,5);

}

function moveMet() {
  //moves meteor by speed
  this.x += this.speed;
  //moves meteor by meteor object speed
  if (this.x < -this.metSize/2-(this.metSize+10)) {
    //if meteor slips of successfully, increase point
    counter += 1;
    this.x = width+this.metSize/2;
    this.y = random(30,height-25);
  }
}

function makeMet(ogX) {
  //based off of provided code
  //creates meteor object
  meteor = {x: ogX,
            y: random(30,height-25),
            speed: random(-4,-1),
            move: moveMet,
            metSize: int(random(40,80)),
            draw: drawMet}
  return meteor;
}

function drawMonster() {
  //displays monster picture
  image(monster,monty.x,monty.y);
  monster.loadPixels();
}

function moveMonster() {
  //moves monster by monster object speed
  monty.x += monty.speed;
  //if off screen, re start monster
  if (monty.x < -monty.x-200) {
    monty.x = width+1500;
    monty.y = random(30,height-100);
  }
}

function makeMonster() {
  //makes monster object
  monty = {x: width,
             y: random(30,height-100),
             speed: random(-2,-0.5),
             move: moveMonster,
             draw: drawMonster}
  return monty;
}

I enjoyed this project more than the past projects. It had a lot of room for creativity. I first started off by sketching my idea and then went off to coding. For future improvements for this, with more time, I would find a way to incorporate shooting something when the mouse is clicked and if the shot x position reached the meteor or monster, then the monster would disappear. I would also try to find a way to decrease the points if the mouseY was in the same position as a meteor. All in all, I enjoyed this project and am happy with my final result.

Caption: Above is my first sketch of what I wanted the canvas to look like.

Caption: Above is my ugly monster. I drew it Illustrator and then loaded it onto imgur.

 

**edited b/c star image got removed from Imgur.

Jdbrown – Project 10 – Magic

I took a rather simple approach to this project – none of the ideas I came up with was more interesting than this experiment that I made:

sketch

// Joshua Brown
// Jdbrown@andrew.cmu.edu
// Section C
// Project 10 - Landscape

// Joshua Brown
// Jdbrown@andrew.cmu.edu
// Section C
// Project 10 - Landscape

// Simple demonstration of the noise() function. 
// Change these for different effects:

var terrainSpeed = 0.0005;
var terrainDetail = 0.005;
var i;

function setup() {
    createCanvas(480, 480);
    frameRate(30);
}
 
function draw() {
    
    background(255);
    beginShape(); 
    fill(0, 100);

    for (var i = 0; i < width; i++) {
        var t = (i * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 1, 0, height);
        vertex(i, y + 200); 
    }

    for (var i = 0; i < width; i++) {
        fill (0);
        var t = (i * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, -1, 0, height);
        vertex(i, y + 400); 
        fill(0, 10)
        noStroke();
        rect (i, y + 800, i, y + 100);
    }

    endShape();
    drawSun();
}

function drawSun() {
    // making the sun and its lines

    var S = second();
    var H = hour();
    var M = minute();

    //drawLines();

    push ();
    stroke (255);
    strokeWeight (2.5);
    translate (width, 0);
    rotate (radians (S * 6));
    fill (0, 0);
    arc (0, 0, 320, 320, radians (0), radians (45));
    arc (0, 0, 320, 320, radians (55), radians (100));
    arc (0, 0, 320, 320, radians (110), radians (155));
    arc (0, 0, 320, 320, radians (165), radians (210));
    arc (0, 0, 320, 320, radians (220), radians (265));
    arc (0, 0, 320, 320, radians (275), radians (310));
    arc (0, 0, 320, 320, radians (320), radians (350));

    fill (255, 100, 120);
    ellipse (0, 0, 200 + (H * 3), 200 + (H * 3));   // draws the sun
    fill (255);
    ellipse (0, 0, S + 75, S + 75);     // draws the white ball in the sun, growing every second
    pop ();

    push ();
    stroke (255);
    strokeWeight (1.5);
    translate (width, 0);
    rotate (radians (S * -6));
    fill (0, 0);
    arc (0, 0, 300, 300, radians (0), radians (45));
    arc (0, 0, 300, 300, radians (55), radians (100));
    arc (0, 0, 300, 300, radians (110), radians (155));
    arc (0, 0, 300, 300, radians (165), radians (210));
    arc (0, 0, 300, 300, radians (220), radians (265));
    arc (0, 0, 300, 300, radians (275), radians (310));
    arc (0, 0, 300, 300, radians (320), radians (350));
    fill (200, 180, 70);
    pop ();

    push ();
    stroke (255);
    strokeWeight (1);
    translate (width, 0);
    rotate (radians (S * 6));
    fill (0, 0);
    arc (0, 0, 280, 280, radians (0), radians (45));
    arc (0, 0, 280, 280, radians (55), radians (100));
    arc (0, 0, 280, 280, radians (110), radians (155));
    arc (0, 0, 280, 280, radians (165), radians (210));
    arc (0, 0, 280, 280, radians (220), radians (265));
    arc (0, 0, 280, 280, radians (275), radians (310));
    arc (0, 0, 280, 280, radians (320), radians (350));
    fill (200, 180, 70);
    pop ();
    
}

yoonyouk-project10-landscape

sketch

//Yoon Young Kim
//Section E
//yoonyouk@andrew.cmu.edu
//Project10


// Simple demonstration of the noise() function. 
// Change these for different effects:
var terrainSpeed = 0.0005;
var terrainDetail = 0.003;

var cacti = [];


function setup() {
    createCanvas(480, 300);
    background(255);

    for(var i = 0; i <5; i++){
        var rx = random(width);
        cacti[i] = makeCacti(rx);
    }
    frameRate(10);

}
 


function draw() {
    background(255, 192, 141);
    
    stroke(255, 231, 101, 80);
    strokeWeight(20);
    fill(250, 212, 87);
    ellipse(width/2, height/2 - 30, 200, 200);




    fill(196, 100, 76);
    noStroke();
    beginShape(); 
    for (var x1 = 0; x1 < width; x1++) {
        var t1 = (x1 * terrainDetail/2) + (millis() * terrainSpeed/3);
        var y1 = map(noise(t1), 0,1, 75, height/2+100);
        vertex(x1, y1); 
    }

    vertex(x1, height);
    vertex(0, height);
    vertex(0, y1);
    endShape();



    fill(102, 36, 39);
    noStroke();
    beginShape(); 
    for (var x = 0; x < width; x++) {
        var t = (x * terrainDetail*1.5) + (millis() * terrainSpeed*1.5);
        var y = map(noise(t), 0,1, 170, 3*height/4);
        vertex(x, y); 


    }
        vertex(x, height);
        vertex(0, height);
        vertex(0, y);
        endShape();



    fill(25, 7, 5);
    noStroke();
    beginShape(); 
    for (var x2 = 0; x2 < width; x2++) {
        var t2 = (x2 * terrainDetail*2) + (millis() * terrainSpeed*3);
        var y2 = map(noise(t2), 0,1, height/2 + 50, height);
        vertex(x2, y2); 

    }
    vertex(x2, height);
    vertex(0, height);
    vertex(0, y2);


    endShape();


    updateAndDisplayCacti();
    addCacti();

}




function updateAndDisplayCacti(){
    // Update the building's positions, and display them.
    for (var i = 0; i < cacti.length; i++){
        cacti[i].move();
        cacti[i].display();
    }
}




function addCacti() {
    // With a very tiny probability, add a new building to the end.
    var newCactiLikelihood = 0.007; 
    if (random(0,1) < newCactiLikelihood) {
        cacti.push(makeCacti(width));
    }
}


// method to update position of building every frame
function cactiMove() {
    this.x += this.speed;
}
    

// draw the building and some windows
function cactiDisplay() {
    fill(25, 7, 5);
    push();
    translate(0, 120);
    rect(width/2+this.x, height/2 -60, 20, 70, 200, 200, 0 ,0);
    rect(width/2+15+ this.x, height/2 - 20, 20, 10);
    rect(width/2+25+ this.x, height/2-30, 10, 20, 200, 200, 0, 0);
    rect(width/2 - 15+ this.x, height/2 - 35, 15, 10);
    rect(width/2-15+ this.x, height/2-50, 10, 20, 200, 200, 0, 0);
    pop();
}


function makeCacti(birthLocationX, birthLocationY) {
    var plant = {x: birthLocationX,
                speed: -1.0,
                r: random(0, 50),
                move: cactiMove,
                display: cactiDisplay,
                }
    return plant;
}


For this week’s landscape project, I decided to do a desert scene. I used the noise part in order to create different layers of the landscape essentially creating a foreground, midground, and a background. The front most layer, or the foreground, displays the most detailed landscape and with cacti silhouettes. I found it a bit challenging to create the randomly generated cacti that would move across the screen. I have yet to figure out how to actually place the cacti on top of the terrain.

aboyle-Project 10-Landscape-Section D

aboyle landscape

var fish = [];
var oceanSpeed = 0.0005;
//ocean detail is low to make it look wavy instead of jagged
var oceanDetail = 0.001;
var floorSpeed=0.0004;
//floor detail is high to simulate rocky bottom
var floorDetail=0.02;

function setup() {
    createCanvas(480, 240);
  }

function draw() {
    background(147,202,243);
//makes ocean
    displayOcean();

//makes fish
    updateAndDisplayFish();
//removes fish that aren't on screen
    removeFishThatHaveSlippedOutOfView();
//adds new fish
    addNewFishWithSomeRandomProbability();

//makes ocean floor
    displayFloor();

}



function updateAndDisplayFish(){
// Update and display the fish
    for (var i = 0; i < fish.length; i++){
        fish[i].move();
        fish[i].display();
    }
}


function removeFishThatHaveSlippedOutOfView(){
//If fish aren't on screen, remove them from the array
//I based this on the provided code
    var fishToKeep = [];
    for (var i = 0; i < fish.length; i++){
        if (fish[i].x + fish[i].breadth > 0) {
            fishToKeep.push(fish[i]);
        }
    }
    fish = fishToKeep;
}


function addNewFishWithSomeRandomProbability() {
//with a low probability, add new fish to array
    var newFishLikelihood = 0.009;
    if (random(0,1) < newFishLikelihood) {
        fish.push(makeFish(width));
    }
}


//change position of fish every frame to make them look like they're moving
function fishMove() {
    this.x += this.speed;
}


// draw the fish
function fishDisplay() {
//randomize the color of the fish
//I kept blue at zero so the fish wouldn't blend into water
    fill(this.fRed, this.fGreen, 0);
    noStroke()
    push();
//translate so 0 means the moving x
    translate(this.x, height);
//makes body of fish
    ellipse(0, -this.fPosition, this.fLength, this.fHeight)
//makes tail of fish
    triangle(this.fLength/2-8, -this.fPosition, this.fLength, -this.fPosition+this.fHeight/2,
      this.fLength, -this.fPosition-this.fHeight/2)
//makes eye of fish
    fill(0);
    ellipse(-6,-this.fPosition,6)
    pop();
}

//makes the object of a fish
function makeFish(birthLocationX) {
    var fsh = {x: birthLocationX,
                breadth: 50,
              //randomizes speed
                speed: random(-2.5, -1),
              //randomizes position in water
                fPosition: round(random(50,150)),
              //randomizes length
                fLength: round (random(20,50)),
              //randomizes height
                fHeight: round (random(10,20)),
              //randomizes color
                fRed: random(0,255),
                fGreen: random(0,255),
                move: fishMove,
                display: fishDisplay}
    return fsh;
}


function displayOcean(){
  noFill();
  stroke(55,122,172)
  beginShape();
//generates the ocean using the noise function
  for (var x = 0; x < width; x++) {
      var t = (x * oceanDetail) + (millis() * oceanSpeed);
      var y = map(noise(t), 0,1, 0, 60);
      vertex(x, y);
      rect (x, y, 1, height)
  }
  endShape();
}

function displayFloor(){
  noFill();
  stroke(104,81,47)
  beginShape();
//generates the ocean floor using the noise function
  for (var x = 0; x < width; x++){
    var z = (x * floorDetail) + (millis() * floorSpeed);
    var v= map(noise(z), 0, 1, 200, height)
    rect(x, v, 1, 50)

  }
  endShape();

}

For this project, I knew I wanted to randomize the speed at which the objects crossed the screen. For this to make sense, the object needed to be something that was moving on its own. I thought about a couple of options, including cars, bees, clouds, and hot air balloons. I ultimately decided on fish because I thought I could have fun making the water look like it was moving. You can see my original sketch below.

Although I based this project on the provided code, I tried my best to insert my original ideas. I made the water have a low detail to look like it was calm but still moving. I made the sea floor have a high detail so it looked jagged and rocky. I made the fish move at different speeds, ensured that they would be between the surface of the water and the sea floor, and randomized their colors to some degree. (I set the blue value equal to zero so they would never be blue and blend into the water.) It took some trial and error to figure out the right proportions of the fish tails and how to color in the water and ground, but I figured out both of those eventually. I had some trouble with making objects in the past, so although the code is simple I’m proud of it. However, I glanced through other projects and noticed a lot of other people decided to something with fish, so in retrospect I wish I could’ve been more original. Overall, though, still a fun project!

daphnel-Project 10-Landscape

landscape

//Daphne Lee
var terrainSpeed = 0.0003;
var terrainCurves = 0.001;
var jx=280;
var jy=300;
var jw=107;
var jh=149;
var jx2=240;
var jy2=280;
var jw2=72;
var jh2=100;
var cx=0;
var cy=390
var cw=113;
var ch=75;
var kx=0;
var ky=350;
var kw=249;
var kh=250;

function preload(){
    jellyfish1 = loadImage("https://i.imgur.com/7ELhX6R.png?1");
    jellyfish2 = loadImage("https://i.imgur.com/Uhau0GX.png?1")
    crab = loadImage("https://i.imgur.com/tPxrvjd.png?1")
    kelp= loadImage("https://i.imgur.com/OZH9VCf.png?1")
}
function setup() {
    createCanvas(480, 480);
}

function drawSeaAndFloor(){
        beginShape();
        noStroke(0);
    //sea
    beginShape();
    fill(51, 204, 204);
    for (var x = 0; x < width; x++) {
        var t = (x * terrainCurves) + (millis() * terrainSpeed*2);
        var y = map(noise(t/2), 0,1, 0, 400);
        vertex(width, height);
        vertex(0,height);
        vertex(x, y);
    }
    endShape();
    //floor
        beginShape();
        fill(204, 153, 102);
        for (var x = 0; x < width; x++) {
        var t = (x * 2* terrainCurves) + (millis() * terrainSpeed);
        var y = map(noise(t), 0,1, 400, height);
        vertex(width, height);
        vertex(0,height);
        vertex(x, y);
    }
    endShape();
}
function drawJellyfish(){
    //the bigger jellyfish moving left
    image(jellyfish1,jx,jy,jw,jh);
    jx-=random(0.5,1);
    jy-=random(-0.5,0.5);
    if(jx<-jw){
        jx=480;
    }
    image(jellyfish2,jx2,jy2,jw2,jh2);
    //smaller jellyfish moving right;
    jx2+=random(-0.5,2);
    jy2+=random(-0.5,0.5);
    if(jx2>width){
        jx2=-100;
    }
}
function drawCrab(){
    //crab
    image(crab,cx,cy,cw,ch);
    cx+=random(0.1,2);
    cy+=random(-0.5,0.5);
    if(cx>width){
        cx=-100;
    }
}
function drawKelp(){
    image(kelp,kx,ky,kw,kh);
    kx+=random(0.5,2);
    ky+=random(-0.5,0.5);
    if(kx>width){
        kx=-250;
    }
}

function draw(){
    background(179, 236, 255);
    drawSeaAndFloor();
    drawJellyfish();
    drawCrab();
    drawKelp();
    //sun
    fill(255, 255, 0);
    ellipse(20,20,150,150)
}

I started off with the idea of wanting to make an ocean with sea creatures swimming inside. I tried starting off with clouds but it didn’t really end up the way I wanted to. I decided to use photos to depict these sea creatures and the first picture I stumbled upon was a jellyfish. I started off with one, and then added another one. It was hard for me to figure out how to work with using objects so I ended up going a simpler route that felt more straightforward in my opinion. I tried to make the ocean more realistic looking so I added some kelp and a crab to add more details to it. I didn’t have enough time to try to incorporate some of the other ideas I had such as working with more objects and creating new functions to relate them to and getting a clearer understanding on how these objects move.

aerubin-Project-10-Landscape

Van Gogh Starry Night

I was inspired by Van Gogh’s Starry Night painting. I thought it would be interesting to see what his painting would look like if it was animated, since he painted a sky with wind that was painted with the intention of motion. I made each aspect of the painting into different functions, so they would be easier to place when each part was complete. I utilized many for loops in order to achieve his brush stroke affect. All in all, I think my code provides insight into what the wind in his painting would look like if it could be animated.

sketch

//Angela Rubin
//Section C
//aerubin@andrew.cmu.edu
//Project-10-Generative Landscape

function setup() {
    createCanvas(480, 350);
}

function draw() {
    background(73, 112, 137);
    //draw funtions, in order of background to foreground
    sky();
    push();
    stars();
    pop();
    push();
    translate(-180, -170);
    stars();
    pop();
    push();
    translate(-270, -20);
    stars();
    pop();
    push();
    wind();
    pop();
    push();
    translate(-300, 100);
    wind();
    pop();
    push();
    translate(-600, -100);
    wind();
    pop();
    push();
    translate(-900, 50);
    wind();
    pop();
    push();
    translate(-1200, -50);
    wind();
    pop();
    push();
    translate(-1500, 0);
    wind();
    pop();
    push();
    translate(-1800, 100);
    wind();
    pop();
    push();
    translate(-2100, -160);
    wind();
    pop();
    push();
    translate(-2500, -100);
    wind();
    pop();
    push();
    translate(-2900, 50);
    wind();
    pop();
    push();
    translate(-3200, -50);
    wind();
    pop();
    push();
    translate(-3500, 0);
    wind();
    pop();
    push();
    translate(-3900, 100);
    wind();
    pop();
    landscape();
    tree();
    
}
    //draws the tree in the foreground
function tree() {
    stroke(29, 47, 41);
    strokeWeight(2);
    fill(40, 32, 28);
    triangle(100, 200, 95, height, 105, height);
    triangle(100+5, 200-20, 95-6, height, 105-6, height);
    triangle(100-2, 200-40, 95+5, height, 105+5, height);
    triangle(100-7, 200+30, 95-3, height, 105-3, height);
    triangle(100+9, 200-10, 95+2, height, 105+2, height);
    triangle(100+3, 200-100, 95+4, height, 105+4, height);
    triangle(100-2, 200-80, 95-2, height, 105-2, height);
    triangle(100-2, 200-140, 95+6, height, 105+6, height);
    triangle(100+5, 200-120, 95-4, height, 105-4, height);
    triangle(100+22, 200+10, 95+15, height, 105+15, height);
    triangle(100+20, 200+30, 95+20, height, 105+20, height);
    triangle(100+14, 200, 95+14, height, 105+14, height);
    triangle(100-17, 200-30, 95, height, 105, height);
    triangle(100+18, 200+60, 95+20, height, 105+20, height);
}
    //draws the landscape of ellipses
function landscape() {
    noStroke();
    push();
    fill(28, 27, 29);
    rotate(radians(-20));
    ellipse(300+30, 310+50, 130, 50);
    pop();
    for(var b = 0; b < 10; b++) {
        fill(45, 58-b*7, 115-b*9);
        ellipse(10+b*60, 320-b*4, 100, 100+b*6);
    }

}

    //draws the dotted lines of the sky
function sky() {
    strokeWeight(6);
    for(var n = 0; n < 20; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(178, 238, 237);
            line(0+(i*20), 3+(n*15), 10+(i*20), 0+(n*15));
        }
    }
    for(var n = 0; n < 20; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(128, 194, 236);
            line(7+(i*20), 4+(n*15), 17+(i*20), 6+(n*15));
        }
    }
    for(var n = 0; n < 20; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(118, 161, 169);
            line(4+(i*20), 2+(n*15), 14+(i*20), 2+(n*15));
        }
    }
    for(var n = 0; n < 18; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(146, 169, 217);
            line(8+(i*20), 7+(n*15), 18+(i*20), 7+(n*15));
        }
    }
    for(var n = 0; n < 20; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(103, 138, 167);
            line(0+(i*20), 10+(n*15), 10+(i*20), 10+(n*15));
        }
    }
    for(var n = 0; n < 15; n++) {
        for(var i = 0; i < 40; i++) {
            stroke(44, 67, 142);
            line(5+(i*20), 7.5+(n*15), 15+(i*20), 8+(n*15));
        }
    }
    
    for(var n = 0; n < 17; n++) {
        for(var i = 0; i < 40;i++) {
            stroke(54, 80, 164);
            line(10+(i*20), 3+(n*15), 20+(i*20), 2+(n*15));
        }
    }

    for(var n = 0; n < 10; n++) {
        for(var i = 0; i < 40; i++) {
            stroke(37, 48, 84);
            line((i*20), 4+(n*15), 10+(i*20), (n*15));
        }
    }
    for(var n = 0; n < 10; n++) {
        for(var i = 0; i < 40; i++) {
            stroke(46, 60, 121);
            line(4+(i*15), 2+(n*15), 14+(i*15), 4+(n*15));
        }
    }
    for(var n = 0; n < 5; n++) {
        for(var i = 0; i < 40; i++) {
            stroke(2, 38, 95);
            line(3+(i*15), 15+(n*15), 13+(i*15), 10+(n*15));
        }
    }
    strokeWeight(3);
    for(var n = 0; n < 20; n++) {
        for(var i = 0; i < 40; i++) {
            stroke(73, 112, 137);
            line(7+(i*15), 10+(n*10), 16+(i*15), 12+(n*10));
        }
    }

    //sun
    push();
    translate(400, 57)
    for(var i = 0; i < 30; i++) {
        stroke(199, 198, 129);
        rotate(.5);
            for(var n = 0; n < 4; n++) {
                line(25+(i*.1), 0+(n*10), 30+(i*.1), 0+(n*10));
        }
    }
    pop();

    noStroke();
    fill(180, 157, 61);
    arc(400, 55, 50, 50, HALF_PI, PI+HALF_PI);
}

    //draws the moving wind
function wind() {
    translate(millis()/70, 0); //rate at which wind moves
    strokeWeight(4);
    for(var n = 0; n < 5; n++) {
        for(var i = 0; i < 10; i++) {
            stroke(255);
            line(10+(i*20), 200-100+(n*10)+i, 20+(i*20), 200-100+(n*10)+i);
        }
    }
    for(var n = 0; n < 5; n++) {
        for(var i = 0; i < 10; i++) {
            stroke(105, 154, 201);
            line(7+(i*20), 203-100+(n*10)+i, 17+(i*20), 203-100+(n*10)+i);
        }
    }
    for(var n = 0; n < 5; n++) {
        for(var i = 0; i < 10; i++) {
            stroke(146, 171, 238);
            line(15+(i*20), 206-100+(n*10)+i, 25+(i*20), 206-100+(n*10)+i);
        }
    }
    for(var n = 0; n < 5; n++) {
        for(var i = 0; i < 10; i++) {
            stroke(29, 66, 124);
            line(20+(i*20), 200-100+(n*12)+i, 30+(i*20), 200-100+(n*12)+i);
        }
    }

    //upper spiral
    push();
    translate(220, 190);
    for(var i = 0; i < 12; i++) {
        stroke(255);
        rotate(-.25);
            for(var n = 0; n < 5; n++) {
                line(20+(i*.3), 30+(n*12), 30+(i*.3), 30+(n*12));
        }
    }
    pop();

    push();
    translate(220, 190);
    for(var i = 0; i < 12; i++) {
        stroke(105, 154, 201);
        rotate(-.25);
            for(var n = 0; n < 5; n++) {
                line(16+(i*.3), 33+(n*12), 26+(i*.3), 33+(n*12));
        }
    }
    pop();

    push();
    translate(220, 190);
    for(var i = 0; i < 12; i++) {
        stroke(146, 171, 238)
        rotate(-.25);
            for(var n = 0; n < 5; n++) {
                line(22+(i*.3), 25+(n*12), 32+(i*.3), 25+(n*12));
        }
    }
    pop();

    push();
    translate(220, 190);
    for(var i = 0; i < 12; i++) {
        stroke(29, 66, 124);
        rotate(-.25);
            for(var n = 0; n < 5; n++) {
                line(24+(i*.3), 32+(n*12), 34+(i*.3), 32+(n*12));
        }
    }
    pop();




    //lower spiral
    push();
    translate(280, 220);
    for(var i = 0; i < 13; i++) {
        stroke(255);
        rotate(.25);
            for(var n = 0; n < 5; n++) {
                line(20+(i*.4), 30+(n*12), 30+(i*.4), 30+(n*12));
        }
    }
    pop();

    push();
    translate(280, 220);
    for(var i = 0; i < 13; i++) {
        stroke(105, 154, 201);
        rotate(.25);
            for(var n = 0; n < 5; n++) {
                line(23+(i*.4), 33+(n*12), 33+(i*.4), 33+(n*12));
        }
    }
    pop();

    push();
    translate(280, 220);
    for(var i = 0; i < 12; i++) {
        stroke(146, 171, 238);
        rotate(.25);
            for(var n = 0; n < 5; n++) {
                line(16+(i*.4), 27+(n*12), 26+(i*.4), 27+(n*12));
        }
    }
    pop();

    push();
    translate(280, 220);
    for(var i = 0; i < 13; i++) {
        stroke(29, 66, 124);
        rotate(.25);
            for(var n = 0; n < 5; n++) {
                line(25+(i*.4), 23+(n*12), 35+(i*.4), 23+(n*12));
        }
    }
    pop();

}

    //draws the starts in the background
function stars() {
    translate(350, 220);
    push();
    for(var i = 0; i < 30; i++) {
        stroke(255);
        rotate(.25);
            for(var n = 0; n < 4; n++) {
                line(25+(i*.1), 0+(n*10), 30+(i*.1), 0+(n*10));
        }
    }
    pop(); 
    //draws the center of stars (yellow) 
    noStroke();
    fill(250, 226, 140);
    ellipse(0, 0, 40, 40);
}