yushano_Project 10

sketch

var choice = [];
var buildings = [];
var trees = [];
var cars = [];
var terrainSpeed = 0.0005;
var terrainDetail = 0.005;
 


function setup() {
    createCanvas(480, 240); 
    
    // create an initial collection of buildings
    for (var i = 0; i < 5; i++){
        var rx = random(width);
        buildings[i] = makeBuilding(rx);
    }
    frameRate(10);
}

function draw() {
    background(205,233,233); 


    // display the background
    stroke(0);
    strokeWeight(1);
    drawMountain();
    displayHorizon();
    

    // draw objects
    // Buildings
    updateAndDisplayBuildings();
    removeBuildingsThatHaveSlippedOutOfView();
    addNewBuildingsWithSomeRandomProbability(); 
    // Trees
    updateAndDisplayTrees();
    removeTreesThatHaveSlippedOutOfView();
    addNewTreesWithSomeRandomProbability();
    // Cars
    updateAndDisplayCars();
    removeCarsThatHaveSlippedOutOfView();
    addNewCarsWithSomeRandomProbability();


    // snow
    drawSnow();

    // window frame
    strokeWeight(40);
    stroke(230);
    line(0,0,width,0);
    line(0,0,0,height);
    line(0,height,width,height);
    line(width,0,width,height);
}

function drawMountain() {
    fill(246,255,223); 
    beginShape(); 
    vertex(0, 200);
    for (var x = 0; x < width; x++) {
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0,1, 30, 200);
        vertex(x, y);    
    }
    vertex(width, 200);   
    endShape();
}

function drawSnow() {
    var xS = 10;
    var yS;
    for (var i=0; i< 50; i++) {
        yS = 0;
        for (var j=0; j< 25; j++){
            fill(255);
            noStroke();
            ellipse(xS, yS, 5);
            yS += random(5,20);
        }
        xS += random(8,25);    
    }
}

    

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


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


function addNewBuildingsWithSomeRandomProbability() {
    // With a very tiny probability, add a new building to the end.
    var newBuildingLikelihood = 0.02; 
    if (random(0,1) < newBuildingLikelihood) {
        buildings.push(makeBuilding(width));
    }
}


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

// draw the building and some windows
function buildingDisplay() {
    var floorHeight = 20;
    var bHeight = this.nFloors * floorHeight; 
    fill(255,255,0); 
    stroke(0); 
    push();
    translate(this.x, height - 40);
    rect(0, -bHeight, this.breadth, bHeight);
    stroke(200); 
    var wGap = this.breadth/16;
    var xW = this.breadth/16;
    //draw the windows
    for (var j=0; j < 5; j++) {
        for (var i = 0; i < this.nFloors; i++) {
            fill(153,204,255);
            stroke(102,178,255);
            rect(xW, -15 - (i * floorHeight), wGap*2 , 10);
        }
        xW += wGap*3;
    }
    pop();
}


function makeBuilding(birthLocationX) {
    var bldg = {x: birthLocationX,
                breadth: 50,
                speed: -5.0,
                nFloors: round(random(3,8)),
                move: buildingMove,
                display: buildingDisplay}
    return bldg;
}

// DRAW THE CHRISTMAS TREE
function updateAndDisplayTrees() {
    // Update the tree's positions, and display them.
    for (var i = 0; i < trees.length; i++){
        trees[i].move();
        trees[i].display();
    }
}


function removeTreesThatHaveSlippedOutOfView() {
    var treesToKeep = [];
    for (var i = 0; i < trees.length; i++){
        if (trees[i].x + trees[i].breadth > 0) {
            treesToKeep.push(trees[i]);
        }
    }
    trees = treesToKeep; // remember the current trees
}


function addNewTreesWithSomeRandomProbability() {
    // With a very tiny probability, add a new tree to the end.
    var newTreeLikelihood = 0.03; 
    if (random(0,1) < newTreeLikelihood) {
        trees.push(makeTree(width));
    }
}


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

// draw the tree and some ornaments
function treeDisplay() { 
    stroke(0); 
    push();
    translate(this.x, 0-this.treeH/3);
    fill(0,102,51)
    triangle(0, height-40, this.breadth/2, height-this.treeH-80, this.breadth, height-40); 
    fill(108,22,22)
    rect(this.breadth/2-10, height-40, 20, this.treeH/3);
    var x0 = this.breadth/6;
    for (var i=0; i<5; i++){
        fill(255,0,0);
        ellipse(x0, height-40-5, 6);
        x0 += this.breadth/6;
    }
    pop();
}


function makeTree(birthLocationX) {
    var tree = {x: birthLocationX,
                breadth: 50,
                speed: -5.0,
                treeH: round(random(30,80)),
                move: treeMove,
                display: treeDisplay}
    return tree;
}

// DRAW VEHICLES
function updateAndDisplayCars() {
    // Update the car's positions, and display them.
    for (var i = 0; i < cars.length; i++){
        cars[i].move();
        cars[i].display();
    }
}


function removeCarsThatHaveSlippedOutOfView() {
    var carsToKeep = [];
    for (var i = 0; i < cars.length; i++){
        if (cars[i].x + cars[i].breadth > 0) {
            carsToKeep.push(cars[i]);
        }
    }
    cars = carsToKeep; // remember the current cars
}


function addNewCarsWithSomeRandomProbability() {
    // With a very tiny probability, add a new car to the end.
    var newCarLikelihood = 0.02; 
    if (random(0,1) < newCarLikelihood) {
        cars.push(makeCar(width));
    }
}


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

// draw the car
function carDisplay() {
    stroke(0); 
    push();
    translate(this.x, 0);
    fill(180)
    rect(0, height-40-this.carWid/6, this.carWid, this.carWid/6);
    rect(this.carWid/4, height-40-this.carWid/30*11, this.carWid/5*3, this.carWid/5); 
    ellipse(this.carWid/6, height-40, this.carWid/6);
    ellipse(this.carWid/6*5, height-40, this.carWid/6);
    
    
    pop();
}


function makeCar(birthLocationX) {
    var car = {x: birthLocationX,
                breadth: 50,
                speed: -5.0,
                carWid: round(random(30,50)),
                move: carMove,
                display: carDisplay}
    return car;
}


// Draw the soil 
function displayHorizon(){
    stroke(0);
    line (0,height-50, width, height-50); 
    fill(132, 75,47);
    rect (0, height-50, width, 50);
}

So, I started from the example code that professor provided for us. I tried to understand how all the things work. Then, I added more elements into the landscape. First, I added the mountain landscape in the background. Then, I change the orientations of the windows in the house. Then, I added the Christmas trees into the scene. Next, I added vehicles- cars to make the picture more fun. At last, I was inspired by the movie “The Power of Ten”. So, I give the animation a picture frame, making it look like people watching outside of a window. Also, I simulated the feeling of snowing to add more fun.

ashleyc1-Section C-Project-10-Landscape

sketch

//Ashley Chan
//Section C
//ashleyc1@andrew.cmu.edu
//Project-10-Landscape

var flowers = [];

var boatX = 440;
var boatY = 280;
var floatHeight;


function setup() {
    createCanvas(480, 480);
    frameRate(10);

    // create an initial collection of buildings
    for (var i = 0; i < 10; i++){

        var rx = random(width);
        var ry = random(height);

        flowers[i] = makeFlower(rx, ry);
    }

    frameRate(10);

}
 
function draw() {
    background(252, 220, 255);

    drawMountains();
    drawWater();
    drawBoat();

    
    displayHorizon();

    updateAndDisplayFlowers();
    removeFlowersThatHaveSlippedOutOfView();
    addNewFlowersWithSomeRandomProbability(); 

    
}

function updateAndDisplayFlowers(){
    // Update the flower's positions, and display them.
    for (var i = 0; i < flowers.length; i++){

        flowers[i].move();
        flowers[i].display();
    }
}

function removeFlowersThatHaveSlippedOutOfView(){

    var flowersToKeep = [];
    
    for (var i = 0; i < flowers.length; i++){

        if (flowers[i].x + flowers[i].stemThickness > 0) {

            flowersToKeep.push(flowers[i]);
        
        }
    }

    flowers = flowersToKeep; // remember the surviving flowers
}


function addNewFlowersWithSomeRandomProbability() {

    // With a very tiny probability, add a new flower to the end.
    var newFlowerLikelihood = 0.01; 

    if (random(0,1) < newFlowerLikelihood) {

        flowers.push(makeFlower(width));
    }
}


// method to update position of flower every frame
function flowerMove() {
    this.x += this.speed;
    this.y += this.speed;

}
    

// draw the flower and some windows
function flowerDisplay() {

    var floorHeight = -5;
    var stemHeight = this.nFloors * floorHeight; 

    push();
    translate(this.x, height - this.offset);
    
    //draw stems
       fill(210);
       rect(0, 0, this.stemThickness, stemHeight);

       translate(this.stemThickness/2, stemHeight);
        //draw flowers here
        for (var i = 0; i < 100; i++) {

            var g = random(0, 100);
            var b = random(0, 100);

            noStroke();
            fill(206, g, b);
            ellipse(0 , 10, 5, 30);
            rotate(PI/5);

            } 

    pop();
}


function makeFlower(birthLocationX, birthLocationY) {
    var flwr = {x: birthLocationX, 
                y: birthLocationY,
                floatHeight: random(10, 100),
                stemThickness: 5,
                speed: -1.0,
                nFloors: round(random(5, 10)),
                offset: random(10, 40), //allows stems to be drawn at various points
                move: flowerMove,
                display: flowerDisplay}

    return flwr;
}

//horizon that flowers are on
function displayHorizon(){
    noStroke(0);
    fill(81, 64, 137);
    rect(0, height - 100, width, height - 100); 
}


function drawWater() {

    var waterSpeed = 0.00009;
    var waterDetail = 0.0005;

    beginShape(); 

    fill(209, 211, 255);
    noStroke();
   
    for (var xWater = 0; xWater < width; xWater++) {

        var tWater = (xWater * waterDetail) + (millis() * waterSpeed);
        var yWater = map(noise(tWater), 0,1, 180, 280);
        vertex(xWater, yWater); 

        //make it draw to edge of canvas
        vertex(0, height);
        vertex(width, height);

    }

    endShape();

}

function drawMountains() {

    var mountainSpeed = 0.0005;
    var mountainDetail = 0.008;

    //Background Mountains
    beginShape(); 

    fill(101, 101, 202, 150);
    noStroke();
   
    for (var xMount = 0; xMount < width; xMount++) {

        var tMount = (xMount * mountainDetail) + (millis() * mountainSpeed);
        var yMount = map(noise(tMount), 0,1, 20, 100);
        vertex(xMount, yMount); 
        vertex(0, height);
        vertex(width, height);


    }

    //foreground mountains
    endShape();
    beginShape(); 

    fill(204, 204, 255, 150);
    noStroke();
   
    for (var xMount = 0; xMount < width; xMount++) {

        var tMount = (xMount * mountainDetail) + (millis() * mountainSpeed);
        var yMount = map(noise(tMount), 0,1, 80, 180);
        vertex(xMount, yMount); 
        vertex(0, height);
        vertex(width, height);

        //stagger mountain edges
        mountainDetail = .01;
    }

    endShape();

}


function drawBoat() {

    //post and sail
    stroke(255);
    strokeWeight(2);
    fill(255);
    line(boatX, boatY, boatX, boatY - 50);
    triangle(boatX, boatY - 50, boatX + 30, boatY -10, boatX, boatY - 5);

    fill(153, 51, 0);
    noStroke();
    arc(boatX, boatY, 80, 50, TWO_PI, PI);

    boatX -= 1;

    //var constrainY = constrain(boatY, 180, 280); 

    //reset boatX so it can repeat when it goes over edge of canvas
    if (boatX < -40) {

        boatX = width;
    }
}

For this project, I wanted to create a mountainscape because I find those peaceful to look at especially when going through the terrible stress of school in general. My image probably could’ve been pushed further but I had a lot of difficulty understanding what characteristics could automatically be defined within an objet and how those elements interacted with one another so just getting my landscape to this point was a success for me.

 


//Ashley Chan
//Section C
//ashleyc1@andrew.cmu.edu
//Project-10-Landscape

var flowers = [];

var boatX = 440;
var boatY = 280;
var floatHeight;


function setup() {
    createCanvas(480, 480);
    frameRate(10);

    // create an initial collection of buildings
    for (var i = 0; i < 10; i++){

        var rx = random(width);
        var ry = random(height);

        flowers[i] = makeFlower(rx, ry);
    }

    frameRate(10);

}
 
function draw() {
    background(252, 220, 255);

    drawMountains();
    drawWater();
    drawBoat();

    
    displayHorizon();

    updateAndDisplayFlowers();
    removeFlowersThatHaveSlippedOutOfView();
    addNewFlowersWithSomeRandomProbability(); 

    
}

function updateAndDisplayFlowers(){
    // Update the flower's positions, and display them.
    for (var i = 0; i < flowers.length; i++){

        flowers[i].move();
        flowers[i].display();
    }
}

function removeFlowersThatHaveSlippedOutOfView(){

    var flowersToKeep = [];
    
    for (var i = 0; i < flowers.length; i++){

        if (flowers[i].x + flowers[i].stemThickness > 0) {

            flowersToKeep.push(flowers[i]);
        
        }
    }

    flowers = flowersToKeep; // remember the surviving flowers
}


function addNewFlowersWithSomeRandomProbability() {

    // With a very tiny probability, add a new flower to the end.
    var newFlowerLikelihood = 0.01; 

    if (random(0,1) < newFlowerLikelihood) {

        flowers.push(makeFlower(width));
    }
}


// method to update position of flower every frame
function flowerMove() {
    this.x += this.speed;
    this.y += this.speed;

}
    

// draw the flower and some windows
function flowerDisplay() {

    var floorHeight = -5;
    var stemHeight = this.nFloors * floorHeight; 

    push();
    translate(this.x, height - this.offset);
    
    //draw stems
       fill(210);
       rect(0, 0, this.stemThickness, stemHeight);

       translate(this.stemThickness/2, stemHeight);
        //draw flowers here
        for (var i = 0; i < 100; i++) {

            var g = random(0, 100);
            var b = random(0, 100);

            noStroke();
            fill(206, g, b);
            ellipse(0 , 10, 5, 30);
            rotate(PI/5);

            } 

    pop();
}


function makeFlower(birthLocationX, birthLocationY) {
    var flwr = {x: birthLocationX, 
                y: birthLocationY,
                floatHeight: random(10, 100),
                stemThickness: 5,
                speed: -1.0,
                nFloors: round(random(5, 10)),
                offset: random(10, 40), //allows stems to be drawn at various points
                move: flowerMove,
                display: flowerDisplay}

    return flwr;
}

//horizon that flowers are on
function displayHorizon(){
    noStroke(0);
    fill(81, 64, 137);
    rect(0, height - 100, width, height - 100); 
}


function drawWater() {

    var waterSpeed = 0.00009;
    var waterDetail = 0.0005;

    beginShape(); 

    fill(209, 211, 255);
    noStroke();
   
    for (var xWater = 0; xWater < width; xWater++) {

        var tWater = (xWater * waterDetail) + (millis() * waterSpeed);
        var yWater = map(noise(tWater), 0,1, 180, 280);
        vertex(xWater, yWater); 

        //make it draw to edge of canvas
        vertex(0, height);
        vertex(width, height);

    }

    endShape();

}

function drawMountains() {

    var mountainSpeed = 0.0005;
    var mountainDetail = 0.008;

    //Background Mountains
    beginShape(); 

    fill(101, 101, 202, 150);
    noStroke();
   
    for (var xMount = 0; xMount < width; xMount++) {

        var tMount = (xMount * mountainDetail) + (millis() * mountainSpeed);
        var yMount = map(noise(tMount), 0,1, 20, 100);
        vertex(xMount, yMount); 
        vertex(0, height);
        vertex(width, height);


    }

    //foreground mountains
    endShape();
    beginShape(); 

    fill(204, 204, 255, 150);
    noStroke();
   
    for (var xMount = 0; xMount < width; xMount++) {

        var tMount = (xMount * mountainDetail) + (millis() * mountainSpeed);
        var yMount = map(noise(tMount), 0,1, 80, 180);
        vertex(xMount, yMount); 
        vertex(0, height);
        vertex(width, height);

        //stagger mountain edges
        mountainDetail = .01;
    }

    endShape();

}


function drawBoat() {

    //post and sail
    stroke(255);
    strokeWeight(2);
    fill(255);
    line(boatX, boatY, boatX, boatY - 50);
    triangle(boatX, boatY - 50, boatX + 30, boatY -10, boatX, boatY - 5);

    fill(153, 51, 0);
    noStroke();
    arc(boatX, boatY, 80, 50, TWO_PI, PI);

    boatX -= 1;

    //var constrainY = constrain(boatY, 180, 280); 

    //reset boatX so it can repeat when it goes over edge of canvas
    if (boatX < -40) {

        boatX = width;
    }
}

 

ikrsek-SectionC-Project-10-“When Pigs Fly”

“When Pigs Fly”

sketch

//Isadora Krsek
//Ikrsek@andrew.cmu.edu
//Section C
//Project 10: Landscape
//"When Pigs Fly"

var morningStars = [];
var terrainZoom = 0.0099;
var waterZoom = 0.0005;
var terrainSpeed = 0.0004;
var mistZoom = 0.004;

var pigsThatFly = []; // An array to store the images
var pigX;  // The last X location of the character
var pigY;  // The last Y location of the character
var targetX;     // The X goal, from the user's click
var targetY;     // The Y goal, from the user's click
var track = (0); //to keep track fo index in array "pigsThatFly"
var theX; //the current x location of character
var theY; //the current y location of character
 

function preload(){
    // These URLs are for the individual walk cycle images,
    // stored in the imgur album http://imgur.com/a/85DTu
    var filenames = [];
    filenames[0] = "https://i.imgur.com/yHI2wXX.png";
    filenames[1] = "https://i.imgur.com/yHI2wXX.png"
    filenames[2] = "https://i.imgur.com/Z5T1eCI.png";
    filenames[3] = "https://i.imgur.com/xPr6ucE.png";
    filenames[4] = "https://i.imgur.com/knjfg9E.png";
    filenames[5] = "https://i.imgur.com/uh2mgbF.png";
    filenames[6] = "https://i.imgur.com/k76ZBzT.png";
    filenames[7] = "https://i.imgur.com/nfG9mkZ.png";
    filenames[8] = "https://i.imgur.com/UXGbXhS.png";
    filenames[9] = "https://i.imgur.com/UXGbXhS.png";
    filenames[10] = "https://i.imgur.com/yHI2wXX.png";
    
    // PUT CODE HERE TO LOAD THE IMAGES INTO THE frames ARRAY,
    for(var z=0; z < filenames.length; z++) {
    pigsThatFly.push(loadImage(filenames[z]));
    }
}

function setup() {
    createCanvas(640, 240);
    imageMode(CENTER);
    frameRate(35);//natural rate 
  
    // Initialize the character and target positions. 
    pigX = width / 2; 
    pigY = height / 2; 
    targetX = pigX;
    targetY = pigY;
   
    //# which allows for new star to appear
    StarProb = 20; 

  //morningStars inital amount 
    for (var i = 0; i < 22; i++) {
      morningStars[i] = new Star(random(width));
    }  
}


function draw() {
    background(255);
    noStroke();
    
    gradientBack();
    drawStars();
    drawMount();
    drawWater();
    drawPig();
}


function drawStars(){
        //when random # is smaller than probability then new start occurs  
  if (StarProb > random(0,100)) {
    morningStars.push(new Star(width));
  }

  for (var i = 0; i < morningStars.length; i++) {
    morningStars[i].move(); //update star array
    morningStars[i].display(); 

    if (morningStars[i].x < 0) { //if star goes out of boundary, remove it
      morningStars.splice(i, 1);
    }    
  }
}

function drawMount(){
    //first mountain
    push();
    fill(0, 180);
    beginShape(); 
    noStroke();
    for (var x = 0; x < width; x++) {
        var t = (x * terrainZoom) + (millis() * terrainSpeed);
        var y = map(noise(t), 0,1, height/2, height*3/4);
        vertex(x, y); 
    }
    vertex(width, height);
    vertex(0,height);
    endShape();
    pop();
}

function drawWater(){
  //water
    //water main
    push();
    fill(173,216,255,100); 

    beginShape(); 
    noStroke();
    for (var x = 0; x < width; x++) {
        var t = (x * waterZoom) + (millis() * terrainSpeed);
        var y = map(noise(t), 0,1, height/2, height*3/4);
        vertex(x+.2, y+70); 
    }
    vertex(width, height);
    vertex(0,height);
    endShape();
    pop();
    //water layers
    fill(173,216,255,115); 
    beginShape(); 
    for (var a = 0;  a < width; a++) {
        var b = (a * waterZoom) + (millis() * terrainSpeed);
        var c = map(noise(b), 0,1, height/2, height*3/4);
        vertex(a+.2, c+75); 
    }
    vertex(width, height);
    vertex(0,height);
    endShape();
    pop();
        beginShape(); 
    for (var d = 0;  d < width; d++) {
        var e = (d * waterZoom) + (millis() * terrainSpeed);
        var f = map(noise(e), 0,1, height/2, height*3/4);
        vertex(d+.2, f+80); 
    }
    vertex(width, height);
    vertex(0,height);
    endShape();
    pop();
    
    
    

}

function drawPig(){
      // PUT CODE HERE TO MOVE THE CHARACTER TOWARDS THE TARGET
    var dx = targetX - pigX;
    var dy = targetY - pigY;
    var distanceFromCharacterToTarget = sqrt(dx*dx + dy*dy);
    //control how character moves toward target 
    theX = lerp(pigX,targetX,.15);
    theY = lerp(pigY,targetY,.15);
    //keep looping through the images continuously/seamlessly 
    if (track >= pigsThatFly.length){
      track = 0; 
    }
    
    // PUT CODE HERE TO DISPLAY THE CHARACTER, CYCLING THROUGH THE FRAMES.
    // WHEN YOU GET THAT WORKING, FLIP THE IMAGE IF THE CHARACTER'S HEADING LEFT. 
   //if the current x location is smaller than the last x location, it will be walking left 
    if (theX < pigX){
      push();
      scale(-1,1);//flip image 
      image(pigsThatFly[track],theX*-1,theY); //you multiply the X-coordinate by -1 so it walks in the right direction 
      pop();
    }
    //otherwise if it's larger, it will be walking right
    else if (theX >= pigX){
      push();
      image(pigsThatFly[track],theX,theY);
      pop();
    }
    
    //re-fresh values of pigX & pigY (which keep track of last place of character)
    pigX = theX;
    pigY = theY;
    
    //cycle through the walking images 
    track = track + 1
    
    
}

function gradientBack(){
  //Create gradient color for the background
    topGrad = color(117, 118, 195); //top gradient 
    bottomGrad = color(250, 207, 194); //bottom gradient 

    //gradient color steps
    var gradientSteps = (height);
    var gradientSteps2 = (30);

    for (var i = 0; i <= gradientSteps; i++) { //for each gradient strip
      fill(lerpColor(topGrad, bottomGrad, i/height)); //fill color inerpolation
      rect(0, (i/height * height) - (1/height * height), width, 1/height * height); //use the color draw boxes
    }
    
    //other gradient 
    /*
    for (var q = 0; q <= gradientSteps2; q++) { //for each gradient strip
      var sizeHeight = ((1/height * height)/2);
      noStroke();
      fill(lerpColor(topGrad2, bottomGrad2, q/gradientSteps2),80); //fill color inerpolation
      rect(0, (q/height * height) - sizeHeight +195, width, sizeHeight); //use the color draw boxes
      
      fill(lerpColor(topGrad3, topGrad2, q/gradientSteps2),80);
      rect(0, (q/height * height) - sizeHeight+164, width, sizeHeight);
    }  
    */
}

function mousePressed() {
    targetX = mouseX;
    targetY = mouseY;
}

//generate morningStars
function Star(xLocation){
  var randoOpa = random(80,180); //have the brightness of stars vary 
  var randoSize = random(.5,2); //have star size vary 
  
  this.x = xLocation;//controlled above by random width 
  this.y = random(1, 180); //range for stars to appear
  this.speed = (-1.5); //speed       

  this.move = function() {
  	  this.x += this.speed; //move the stars
  }

  this.display = function() {
	//draw the stars here 
	  fill(255,255,255,randoOpa);
	  ellipse(this.x, this.y,randoSize,randoSize);
  }
}






This time around I wanted to do something a little more fun than usual. I had some trouble deciding on what I wanted to do, but eventually decided to just do a pig flying across the water in the early early morning (early enough when you can still see stars). The reason why is because I was inspired by the phrase “when pigs fly”, but not in the traditional sense of the phrase. I was more interested in where pigs would go and what they would do when they fly – why would pigs fly? So I ended up deciding a pig would take the time to go on an early morning flight, beneath the glow of the stars at dawn.
I wanted to do something humorous and beautiful and this is the result.

Also, fun fact:
If you click on the screen, the pig will move to your mouse location.

Here is a picture of the original sketch.

karinac-Project 10

karinac-project10

//Karina Chiu
//Section C
//karinac@andrew.cmu.edu
//Project 10

var fish1;
var fish2;
var fish1X = 500;
var fish1Y = 150;
var fish2X = -200;
var fish2Y = 100;
var fish3X = 650;
var fish3Y = 200;
var fish4X = 700;
var fish4Y = 60;
var fish5X = 540;
var fish5Y = 40;
var fishWidth = 40;
var fishHeight = 30;

function preload() {
	fish1 = loadImage("https://openclipart.org/image/2400px/svg_to_png/263089/fish-3.png");
	fish2 = loadImage("https://openclipart.org/image/2400px/svg_to_png/263085/1475323265.png");
	fish3 = loadImage("https://openclipart.org/image/2400px/svg_to_png/263089/fish-3.png");
	fish4 = loadImage("https://openclipart.org/image/2400px/svg_to_png/263089/fish-3.png");
	fish5 = loadImage("https://openclipart.org/image/2400px/svg_to_png/263089/fish-3.png");
}

function setup() {
	createCanvas(500,300);
	frameRate(100);
}

function draw(){
	background(18,27,180);
	drawSand();
	drawFish();
}


//drawing sea floor
var terrainSpeed = 0.0005;
var sandFloor = 0.010;

function drawSand() {  
    noStroke();
    fill(170,150,120); 

    beginShape();
        for (x=0; x < width; x++) {
            var t = (x*sandFloor) + (millis()*terrainSpeed);
            var y = map(noise(t), 0, 1, 220, 270);
            vertex(x, y);
            vertex(0,height);
            vertex(width,height);
        }
    endShape();
}

function drawFish() {
	image(fish1, fish1X, fish1Y, fishWidth, fishHeight);
	fish1X -= random(1,2);
	fish1Y -= random(-0.5,0.5);

	if (fish1X < -fishWidth) {
		fish1X = 500;
	}

	image(fish2, fish2X, fish2Y, fishWidth, fishHeight);
	fish2X += random(0,0.5);
	fish2Y += random(-0.5,0.5);

	if (fish2X > 700) {
		fish2X = -100;
	}

	image(fish3, fish3X, fish3Y, fishWidth, fishHeight);
	fish3X -= random(0,2);
	fish3Y -= random(-0.5,0.5);

	if (fish3X < -fishWidth) {
		fish3X = 650;
	}

	image(fish4, fish4X, fish4Y, fishWidth, fishHeight);
	fish4X -= random(1,2.5);
	fish4Y -= random(-1,1);

	if (fish4X < -fishWidth) {
		fish4X = 700;
	}

	image(fish5, fish5X, fish5Y, fishWidth, fishHeight);
	fish5X -= random(1,2.5);
	fish5Y -= random(-1,1);

	if (fish5X < -fishWidth) {
		fish5X = 540;
	}
}

I wanted to create an ocean floor. At first, I was only going to draw the orange fishes going to the left. However, I decided to add more. Drawing the terrain was definitely the most difficult part of the process, but I had learned a lot from it.

Project-10 Thomas Wrabetz

sketch
The landscape is space with planets that have varying orbiting moons.

//Thomas Wrabetz
//Section C
//twrabetz@andrew.cmu.edu
//Project-10

planetArray = [];
planetFrames = 0;
planetFrequency = 110;

function stepPlanet()
{
    this.x += this.xspeed;
    this.y += this.yspeed;
    return ((this.x < width + this.radius * 2) & (this.y < height + this.radius * 2) && (this.y > 0));
}

function drawPlanet()
{
    push();
    translate( this.x, this.y );
    rotate( this.tilt );
    for( var i = 0; i < this.moonArray.length; i++ )
    {
        val = (this.moonArray[i].orbitFrames * this.moonArray[i].orbitSpeed) % TWO_PI;
        if( val < PI / 2 || val > 3 * PI / 2 )
        {
            this.moonArray[i].draw( this );
        } 
    }
    fill( this.planetColor );
    ellipse( 0, 0, this.radius, this.radius );
    fill( this.ringColor );
    ellipse( 0, 0, this.radius * this.ringWidth, this.radius * this.ringWidth / 10 );
    fill( this.planetColor );
    ellipse( 0, 0, this.radius * (this.ringWidth - 1) / 2 + this.radius, this.radius * (this.ringWidth - 1) / 20 );
    fill( 0 );
    arc( this.radius / 2, 0, this.radius * (this.ringWidth - 1) / 2, this.radius * (this.ringWidth - 1) / 20, -HALF_PI, HALF_PI);
    arc( -this.radius / 2, 0, this.radius * (this.ringWidth - 1) / 2, this.radius * (this.ringWidth - 1) / 20, HALF_PI, PI+HALF_PI);
    fill( this.planetColor );
    arc( 0, 0, this.radius, this.radius, PI, TWO_PI );
    for( var j = 0; j < this.moonArray.length; j++ )
    {
        val = (this.moonArray[j].orbitFrames * this.moonArray[j].orbitSpeed) % TWO_PI;
        if( val > PI / 2 & val < 3 * PI / 2 )
        { 
            this.moonArray[j].draw( this );
        }
    }
    pop();
}

function makePlanet()
{
    planet = { radius: random( 50, 125 ), x: 0, y: 0, 
               planetColor: color( random(256), random(256), random(256) ), ringColor: color( random(256), random(256), random(256), ), ringWidth: random( 1.15, 2 ), 
               tilt: random( 360 ), xspeed: random( 0.75, 2 ), yspeed: random( -0.5, 0.5 ), moonArray: [], draw: drawPlanet, step: stepPlanet };
    numMoons = random( -2, 4.5 );
    for( var i = 0; i < numMoons; i++ )
    {
        planet.moonArray.push( makeMoon() );
    } 
    planet.y = random( planet.radius, width - planet.radius );
    planet.x = - planet.radius * 2;
    return planet;
}

function drawMoon( planet )
{
    moonDist = planet.radius * this.orbitDistance * sin( this.orbitFrames * this.orbitSpeed );
    moonPerp = planet.radius * this.orbitDistance * cos( this.orbitFrames * this.orbitSpeed ) * this.orbitAxis2;
    sizeModifier = 1 - cos( this.orbitFrames * this.orbitSpeed )/4;
    moonX = moonDist * cos( this.orbitAxis ) - moonPerp * sin( this.orbitAxis );
    moonY = moonDist * sin( this.orbitAxis ) + moonPerp * cos( this.orbitAxis );
    fill( this.moonColor );
    ellipse( moonX, moonY, this.radius * sizeModifier, this.radius * sizeModifier );
    this.orbitFrames++;
}

function makeMoon()
{
    moon = { radius: random( 10, 20 ), orbitSpeed: random( 0.025, 0.05 ), orbitDistance: random( 1, 2 ), orbitAxis: random(0,TWO_PI), orbitAxis2: random(0,1), orbitFrames: 0,
             moonColor: random( 125, 255 ), draw: drawMoon };
    return moon;
}

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

function draw()
{
    background( 0 );
    if( planetFrames <= 0 )
    {
        planetArray.push( makePlanet() );
        planetFrames = random( 90, 130 );
    }
    planetFrames--;
    for( var i = 0; i < planetArray.length; i++ )
    {
        planetArray[i].draw();
        if( !planetArray[i].step() )
        {
            planetArray.splice( i, 1 );
            i -= 1;
        }
    }
}

kyungak-project-10-generative-landscape

sketch

//Kyunga Ko
//15104B
//kyungak@andrew.cmu.edu
//Project 10

var terrainspeed = 0.0005;
var terraincurve = 0.025;
var binocular;
var cactus = [];

//loads the images from imgur (binoculars and cactus)
function preload() {
    binocular = loadImage("https://i.imgur.com/bVzNOic.png");
    cactus1 = loadImage("https://i.imgur.com/E2dHw8Y.png")
}

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

    //initially iterates cactus
    for (var i = 0; i < 5; i++){
        var location = random(width);
        cactus[i] = makeCactus(location);
    }

    frameRate(10);
}
 
function draw() {
    background(214,196,211,200);

    backgroundmountain();
    bottomsand();

    updateCactus();
    displayCactus();
    addCactus();
    makeCactus(); 
    moveCactus();

    // structure of sun
    fill(255,0,0,150);
    noStroke();
    ellipse(70,70,50,50);
    stroke(255,0,0,150);
    strokeWeight(3);
    line(70,30,70,45);
    line(70,95,70,110);
    line(30,70,45,70);
    line(95,70,110,70);

    //Binoculars
    image(binocular,mouseX-500,mouseY-500); 
}

//updating cactus location and movement
function updateCactus(){
    for (var i = 0; i < cactus.length; i++){
        cactus[i].move();
        cactus[i].display();
    }
}

// adding new cactus from the left side of the canvas
function addCactus() {
    var a = random(1);
    if (a < 0.03) {
        cactus.push(makeCactus(width));
    }
}

//moving the position of cactus 
function moveCactus() {
    this.x += this.speed;
}
    

//drawing and displaying cactus
function displayCactus() {
    push();
    translate(this.x, this.height);
    for(var i=0; i<this.number; i++) {
        image(cactus1,this.x*i, 100);
    }
    pop();
}

//making cactus + variables needed to make cactus
function makeCactus(birthx) {
    var cactus2 = {x: birthx,
                number: floor(random(1,2)),
                speed: -3,
                height: random(90,100),
                move: moveCactus,
                display: displayCactus}
    return cactus2;
}

//function that draws the mountains
function backgroundmountain() {  

    //back mountain
    noStroke();
    fill(9, 69, 32); 
    beginShape(); 
    //for loop makes back layer of mountain
    for (var x = 0; x < width; x++) {
        var t = (terraincurve * 2 * x) + (millis() * terrainspeed);
        var y = map(noise(t/2), 0, 1, 70, height);
        curveVertex(x, y); 
    }
    curveVertex(width, height);
    curveVertex(0,width);
    endShape(CLOSE);  

    //front mountain
    noStroke();
    fill(89, 107, 89,200); 
    beginShape(); 
    //for loop makes front layer of mountain
    for (var x = 0; x < width; x++) {
        var t = (terraincurve * x) + (millis() * terrainspeed);
        var y = map(noise(t/2), 0, 1, 0, height);
        curveVertex(x, y); 
    }
    curveVertex(width, height);
    curveVertex(0,width);
    endShape(CLOSE);

}

//function that draws the sand layer on the bottom
function bottomsand() { 

    //front mountain
    noStroke();
    fill(179,145,86); 
    beginShape(); 
    //for loop makes the sand layers on the bottom
    for (var x = 0; x < width; x++) {
        var t = (terraincurve * x) + (millis() * terrainspeed);
        var y = map(noise(t/2), 0, 1, 370, height);
        curveVertex(x, y); 
    }
    curveVertex(width, height);
    curveVertex(0,width);
    endShape(CLOSE); 

}

For this project, I wanted to make a landscape that contained both a desert and a forest. On the bottom desert layer, I altered the original terrain function by reducing the amount of noise. This allowed me to make a smoother surface of sand. For the random cactuses, I made them into javascript objects and coded accordingly. The cactus image was photoshopped by me and embedded through imgur. I then utilized the provided terrain code to slightly alter and make the forest layers. I then gave a little twist by photoshopping a binocular image and putting it on top of the landscape function. It made it as if you are looking through the binoculars from a distance. Although the process was a bit rocky, I managed to understand and use the javascript object function. I was able to learn a lot through this project.

 

afukuda-Project10-Landscape

sketch

/* 
 * Name | Ai Fukuda 
 * Course Section | C 
 * Email | afukuda@andrew.cmu.edu
 * Project| 10
 */ 

var clouds = [];  // array containing clouds 
var boat;         // variable containing boat image 
var boatX;        // x-coordinate of boat 

function preload() {               // load boat image 
    boat = loadImage("https://i.imgur.com/Z33aV9X.png")  
}

function setup() {
    createCanvas(400, 200); 
    
    for (var i=0; i<8; i++) {      // create initial collection of the clouds
        var rx = random(width);
        clouds[i] = makeCloud(rx); 
    }
    frameRate(10);

    boatX = 0;                     // initial position (x-coord) of boat 
}


function draw() {   
    background(214, 233, 248);     // sky color setting 

    updateClouds();    // calling cloud functions       (background)
    addClouds(); 

    drawTerrain();     // calling terrain draw function (middle ground)
    drawWaveDistant(); // calling wave draw function    (foreground)
    drawBoat();        // calling boat draw function    (adding element)
    drawWaveClose();   // calling wave draw function    (foreground)
}


// ---- ELEMENT - BOAT ----
function drawBoat() {
    image(boat, boatX, 102, boat.width/10, boat.height/10);  // draw boat image at 1/10 scale 
    
    boatX = boatX + 2;    // move boat across the canvas at constant speed 
    
    if (boatX > width) {  // reset boat once it hits the right edge of canvas 
        boatX = 0;
    }
}


// ---- UPDATE FUNCTION ----
function updateClouds() {  // update position of clouds & draw them 
    for (i=0; i<clouds.length; i++) {
        clouds[i].move();
        clouds[i].display();
    }
}


// ---- ADD FUNCTION ----
function addClouds() {    // add more clouds 
    var newCloudLikelihood = 0.005; 
    if (random(0,1) < newCloudLikelihood) { 
        clouds.push(makeCloud(width));        // add new cloud to start of cloud array 
    }
}


// ---- ADDING MOTION TO OBJECT ----
function cloudMove() {    // add motion to clouds 
    this.x += this.speed;
}
    

// ---- DEFINING WHAT IS GOING TO BE DISPLAYED ----
function cloudDisplay() { 
    var u = 10;                      // constant unit (multiply depth to show clouds better)
    var cloudDepth = this.depth * u; // depth of cloud 

    noStroke();
    fill(252);                       // color setting - white 

    push();
        translate(this.x, height-90);
        beginShape();
            ellipse(0, -cloudDepth,  this.x * 0.25, u*1.25);
        endShape(); 
    pop();
}


// ---- DEFINING OBJECT ----
// ---- BACKGROUND - CLOUDS ----   
function makeCloud(cl) {
    var cloud = {
                x: cl,
                speed: -1,
                depth: round(random(6,12)), // need to adjust 
                move: cloudMove,
                display: cloudDisplay
                }
    return cloud;
}


// ---- MIDDLE GROUND - TERRAIN ----
var terrainSpeed = 0.0005;
var terrainDetail = 0.007;

function drawTerrain() {  
    noStroke();
    fill(147, 183, 147, 180); 

    beginShape();
        for (x=0; x<width; x++) {
            var t = (x * terrainDetail) + (millis() * terrainSpeed);
            var y = map(noise(t), 0, 1, 40, 120);
            vertex(x, y);
            vertex(0,height);
            vertex(width,height);
        }
    endShape();
}


// ---- FOREGROUND - WAVES ---- based on stevenraysimon sine wave script 
var offset = 0;
var amplitude = 1;

function drawWaveDistant() {   // function drawing waves (distant)
    stroke(256);
    strokeWeight(2);
    fill(90, 185, 224);  // color setting - blue 

    beginShape();
        vertex(0, height);
        for (x=0; x<width; x++) {       
            var angle = offset + x * 0.04; 
            var y = map(cos(angle), -amplitude*2, amplitude*2, 120, 160); 
            vertex(x, y);
        }
        vertex(width, height);
    endShape();
    offset += 0.2;
}

function drawWaveClose() {   // function drawing waves (close) 
    stroke(256);
    strokeWeight(4);
    fill(1, 106, 161, 250);  // color setting - dark blue 

    beginShape();
        vertex(0, height);
        for (x=0; x<width; x++) {       
            var angle = offset + x * 0.03; 
            var y = map(sin(angle), -amplitude, amplitude, 120, 160); 
            vertex(x, y);
        }
        vertex(width, height);
    endShape();
    offset += 0.4;
}













For this project I wanted to create a generative sea landscape from the perspective of someone on a boat ride. This was inspired by a boat ride during my Asia trip over the summer. Something I had difficulty with was to oscillate the waves in the vertical direction simultaneously; as a result the waves are simply moving in the horizontal direction. What is intriguing, however, is that if you stare at the waves for some time you get an illusion that the waves are moving in their “wave-like” manner. I made the landscape elements be of continuous motion, and experimented with using images (rather than generating the geometries through p5js) to add the boat element into the program.

Initial sketch of my generative landscape

ghou-Project-10-Landscape

sketch

//Grace Wanying Hou
//15-104 Section D
//ghou@andrew.cmu.edu
//Project 10


//global variables
var frames = [];
var sm1 = 0.0003;
var sm2 = 0.00035;
var sm3 = 0.0005;
var detail1 = 0.03;
var detail2 = 0.015;
var detail3 = 0.01;

var birds = [];

function preload(){
//AW MY CUTE BIRDS 😀
    var filenames = [];
    filenames[0] = "https://i.imgur.com/TMM2wDR.png";
    filenames[1] = "https://i.imgur.com/yl73pp4.png";
    filenames[2] = "https://i.imgur.com/XihpVMA.png";
    filenames[3] = "https://i.imgur.com/yl73pp4.png";
    filenames[4] = "https://i.imgur.com/TMM2wDR.png";
    filenames[5] = "https://i.imgur.com/OY3iZ36.png";
    filenames[6] = "https://i.imgur.com/nGeaANh.png";
    filenames[7] = "https://i.imgur.com/OY3iZ36.png";
    
    for (i=0; i<filenames.length; i++){
        frames[i] = loadImage(filenames[i]);
    }
}


function setup() {
    createCanvas(250,400);
    frameRate(10);
    //there should be some birds on screen when the sketch is first opened
    for (var i=0; i<5; i++){
        var randoPosition = random(width+100);
        birds[i] = makeBird(randoPosition);
    }
    

}
 
function draw() {
    //loading the functions
    makeBackground();
    maybeAddNewBird(); 
    makeMountains();
    updateDisplayBirds();
    
}


function makeBackground(){//making a gradient for the background
    strokeWeight(1);
    for (var i=0;i<height; i++){
        stroke(255-i/8);
        line(0, i, width, i);
    }
}
function makeMountains(){
    noStroke();
    
    //back mountain
    fill(210);
    beginShape(); 
    for (var x1 = 0; x1 < width; x1++) {
        var t1 = (x1 * detail1) + (millis() * sm1);
        var y1 = map(noise(t1), 0,1, 0, height);
        vertex(x1,y1-80); 
    }
    vertex(width,height);
    vertex(0,height);
    endShape();
    
    //middle mountain
    fill(190);
    beginShape(); 
    for (var x2 = 0; x2 < width; x2++) {
        var t2 = (x2 * detail2) + (millis() * sm2);
        var y2 = map(noise(t2), 0,1, 0, height);
        vertex(x2,y2+80); 
    }
    vertex(width,height);
    vertex(0,height);
    endShape();
        
    //front mountain
    fill(170);
    beginShape(); 
    for (var x3 = 0; x3 < width; x3++) {
        var t3 = (x3 * detail3) + (millis() * sm3);
        var y3 = map(noise(t3), 0,1, 0, height);
        vertex(x3,y3+150); 
    }
    vertex(width,height);
    vertex(0,height);
    endShape();
}

function updateDisplayBirds(){//keep the birds in display
    for (var i=0; i<birds.length; i++){
        birds[i].move();
        birds[i].display();
    }
}

function maybeAddNewBird(){//low chance a new bird will be added each frame
    if (random(1) < 0.015){
        birds.push(makeBird(width+100));
    }
}
function birdMove(){//updating the bird speed
    this.x += this.speed;
}

function displayBird(){ //drawing the birds
    push();
    fill(255,255,255,this.trans);
    noStroke();
    translate(this.x,this.floatHeight);
    for (var i=0; i<this.size; i++){
        tint(255, this.trans+i*20);//a group of birds will have different transparencies
        var fc = frameCount % 5; //animating the birds
        image(frames[fc+i],this.x-this.disX*i,0-this.disY*i);// the birds will flap their wings staggered
    }
    pop();
}

function makeBird(birthplace){ //making the birds
    var bird = {x: birthplace,
                 disX: random(10,50),
                 disY: random(30),
                 size: floor(random(1,4)),
                 trans: random(30,150),
                 speed: random(-4,-2),
                 floatHeight: random(40,150),
                 move: birdMove,
                 display: displayBird,
                }
    return bird;
}

I went for a monotoned landscape for this week’s project inspired by Pittsburgh’s insanely gloomy weather the past two weeks. I created the three layers of mountains using the noise() function provided to us and altering the colour, speed, and detail to create the layered effect. I used Javascript Objects to control my birds; they are frames of individual images Photoshopped and uploaded onto imgur.com. I also tried to make clouds using ellipse() functions and stored objects but it did not give me the desired effect so I decided to take them out.

sntong-Project 10- Generative Landscape

sketch

//Scqrlet Tong
//sntong@andrew.cmu.edu
//Section A
// Project 10: Generative Landscape

var sheeps = [];
var sSheeps = [];


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

    // create an initial collection of objects
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        sheeps[i] = makeSheep(rx);
        sSheeps[i] = makeSmallSheep(rx);
    }
    frameRate(10);
}


function draw() {
    background(170,215,230);
    // changing hillscape
    Hill();
    // moving sun position
    Sun();
    // draw existing to new locationlarge sheeps
    updateSheeps();
    // draw new large sheeps
    addNewSheeps();
    updateSmallSheeps();
    addNewSmallSheeps();
}


function updateSheeps(){
    // Update and draw the large sheep positions
    for (var i = 0; i < sheeps.length; i++){
        sheeps[i].move();
        sheeps[i].display();
    }
}

function addNewSheeps() {
    // With a very tiny probability, add a new building to the end.
    var newSheepLikelihood = 0.05;
    if (random(0,1) < newSheepLikelihood) {
        sheeps.push(makeSheep(width));
    }
}


// shift sheeps
function oMove() {
    this.x += this.speed;
}


// draw large sheeps
function sheepDisplay() {
    push();
    translate(this.x+50,height-80+this.scatter);
    // legs
    stroke(60);
    strokeWeight(2);
    var loc1 = random (5,7);
    line(this.x-10,loc1-10,this.x-10,loc1+12);
    line(this.x+10,loc1-10,this.x+10,loc1+12);
    //body
    strokeWeight(0.5);
    fill(255);
    stroke(200);
    ellipse(this.x, loc1-3, this.fat+20, 20);
    fill(150);
    //head
    ellipse(this.x-18, loc1-6, this.fat-8, 12);
    stroke(120);
    pop();
}

// object large sheep
function makeSheep(make) {
    var sheep = {x: make,
                fat: 20,
                speed: -1.0,
                move: oMove,
                scatter: random(5),
                display: sheepDisplay}
    return sheep;
}


// update location of existing small sheeps
function updateSmallSheeps(){
    // Update the small sheep's positions, and draw them.
    for (var i = 0; i < sSheeps.length; i++){
        sSheeps[i].move();
        sSheeps[i].display();
    }
}

// generate new small sheeps
function addNewSmallSheeps() {
    // add a new small sheep to the end.
    var newSheepLikelihood = 0.05;
    if (random(0,1) < newSheepLikelihood) {
        sSheeps.push(makeSmallSheep(width));
    }
}

// draw farer (smaller) sheeps in the field
function smallSheepDisplay() {
    push();
    translate(this.x+20,height-150+this.scatter);
    // legs
    stroke(60);
    strokeWeight(1);
    var loc1 = random (5,6);
    line(this.x-5,loc1-5,this.x-5,loc1+6);
    line(this.x+5,loc1-5,this.x+5,loc1+6);
    //body
    strokeWeight(0.5);
    fill(255);
    stroke(200);
    ellipse(this.x, loc1-1.5, this.fat+10, 10);
    fill(150);
    //head
    ellipse(this.x-9, loc1-3, this.fat-4, 6);
    stroke(120);
    pop();
}

// smalls sheep object
function makeSmallSheep(pop) {
    var sSheep = {x: pop,
                fat: 10,
                speed: -0.5,
                move: oMove,
                scatter: random(20),
                display: smallSheepDisplay}
    return sSheep;
}

// function for drawing moving sun
function Sun (){
  for (var i = 0; i < width; i++) {
      var t = (i * 0.003) + (millis() * 0.0002);
      fill(250,200,100);
      ellipse(width-t-25,100,50,50);
  } noFill();
}

// to creste Landscape
function Hill(){
  fill(70,175,100);
  noStroke();
  beginShape();
  for (var x = 0; x < width; x++) {
      var t = (x * 0.003) + (millis() * 0.00002);
      var y = map(noise(t), 0,1, 100, height-100);
      vertex(x, y);
      vertex(0,height);
      vertex(width,height);
  }
  endShape();
}

I was imagining the view one could get while seating on a train and looking out to the fields in Australia. The larger and smaller sheep suggests their distance to the person. As time passes the sun also moves with the viewer. As I am not familiar with objects, this project is much harder for me as it is working with objects.

A quick sketch I made to visualize how things would look

Project 10- Halloween

Halloween

//Yoonseo(Dave) Choi
//Section B
//yoonseo1@andrew.cmu.edu
//Project 10
var trees = []; //tree array
var houset = []; //house array
function setup() {
    createCanvas(480, 480); //canvas size
    strokeJoin(MITER); //set lines to be rectangular
    strokeCap(PROJECT) //set lines to be rectangular
    angleMode(DEGREES); //set angle to degrees
    // create an initial collection of buildings
    for (var i = 0; i < 10; i++){
        var rx = random(width); // random value of rx
        trees[i] = makeTree(rx); //create tree at random rx 
        houset[i] = makeHouse(rx); //create house at random rx
    }
    
}


function draw() {
    var run = map(mouseX,0,width,20,60); //remap the x value to 20- 60
    frameRate(run);//set frame rate based on mouse position 
    noStroke(); //no stroke
    background(30); //background to 30
    fill(299,149,41,30) //create brown ground plance
    rect(0,280,width,height,80); //ground plane
    noFill(); //remove fill
    fill(0) //black fill
    rect(0,0,width,300); //black sky background
    noFill();
    displaybackground(); //display background elements

    updateAndDisplayobjects(); //display objects
    removeobjects(); //remove when at end
    addNewobjects();  //add new based on probaility
}


function updateAndDisplayobjects(){
    // Update the building's positions, and display them.
    for (var h = 0; h < houset.length; h ++){ // for length of the array, update house move value and display it
        houset[h].hmove();
        houset[h].hdisplay();
    }
    for (var i = 0; i < trees.length; i++){//for length of the array, update htree move value and display it
        trees[i].tmove();
        trees[i].tdisplay();

    }
    
}


function removeobjects(){
    var treesKeep = []; // tree keeping array
    var housekeep = []; //house keeping array
    for (var h =0; h < houset.length; h++){
        if(houset[h].hx + 50 >0){ //if the x value of the house +50 is larger than 0 then keep 
            housekeep.push(houset[h]);
        }
    }
    houset = housekeep;
    for (var i = 0; i < trees.length; i++){ //if the x value of the tree is larger than 0, keep 
        if (trees[i].x>0){
            treesKeep.push(trees[i]);

        }
    }
    trees = treesKeep;
   
// remember the surviving buildings
}


function addNewobjects() {
    var newobjprob = 0.4; //probability of 40 % for tree
    var houseprob =0.02; //probability of 2% for witch housing
    if (random(0,1) < houseprob){ //when number is within probability create
        houset.push(makeHouse(width))
    }
    if (random(0,1) < newobjprob) { //when number is within probability create
        trees.push(makeTree(width))
    }
    
    }
function treeDisplay(){ //tree display method
    var treeheight = 20;
    var tHeight = this.nHeight*treeheight;
    var bcount = 0;
    var branchlen = 60;
    fill(10);
    stroke(50,19,41);
    push();
    strokeWeight(1.5);
    translate(this.x, height-60);
    line(0,0,0,-tHeight);
    translate(0,-tHeight);
    stroke(120,59,41);
    while(bcount < this.branch){
    push();
    translate(0,branchlen)
    bcount+=1;
    branchlen *= 0.67
    if (branchlen > 4){
    push();
    rotate(45);
    line(0,0,0,-branchlen);
    pop();
    push();
    rotate(-70)
    line(0,0,0,-branchlen)
    pop();
    }
    pop();
    }
    pop();
}
function houseDisplay(){ //house display method
    var houseHeight = 40;
    var hwid = this.hwidth;
    var hHeight = this.hfloor*houseHeight;
    push();
    translate(this.hx,height-60);

    stroke(127,152,182,180);
    strokeWeight(3);
    line(0,0,-10*this.flip,-hHeight/2);
    line(0,0,30*this.flip,-hHeight/2);
    push();
    translate(-10*this.flip,-hHeight/3);
    line(0,0,15,-height/5)
    line(0,0,35,-height/5)
    pop();
    push();
    noStroke();
    fill(37,23,3);
    translate(-10,-height/5);
    beginShape();
    vertex(0,0);
    vertex(hwid*4,0);
    vertex(hwid*3,-hHeight);
    vertex(-hwid,-height/6)
    endShape();
    for( var i =0; i <this.hfloor; i += this.hdiv){
        fill(187,121,18,200);
        ellipse(20,-20 - (i*houseHeight/2),this.hwidth*2,this.hwinh);
    }
    pop();
    pop();


}
function treeMove(){
    this.x += this.speed;
}
function houseMove(){
    this.hx += this.hspeed;
}
function makeTree(tx){ //tree object
    var tree = {x: tx,
                speed: random(-7.0,-20),
                nHeight: floor(random(4,8)),
                branch: random(20,30),
                tmove: treeMove,
                tdisplay: treeDisplay
            }
            return tree;
}
function makeHouse(hhx){ //house object
    var house = {hx: hhx, 
                  hspeed: -2.0,
                  flip: random(-1,1),
                  hdiv: random(1,3),
                  hwinh: random(10,20),
                  hfloor: round(random(2,5)),
                  hwidth: random(10,20),
                  hmove: houseMove,
                  hdisplay: houseDisplay
             }
    return house;
}

function displaybackground(){ //background element
    noStroke();
    fill(color(255,235,5,190));
    ellipse(width-80,110,180,180);
    noFill();
    noStroke();
    fill(255,255,255,20);
    ellipse(width-30,70,30,30);
    fill(0,0,0,30);
    ellipse(width-160,130,10,30);
    fill(0,0,0,20);
    ellipse(width-20,160,35,25);
      
          noStroke();
    
    stroke(70,130,170,150);
    beginShape();
    for( var x = 0; x < width; x++){ //using noise in p5.js to create river edge
        var t = (x * 0.005)+(millis()*0.0005);
        var y = map(noise(t),0,1,20,75);
        vertex(x,height-y);
        vertex(0,height+70);
        vertex(width,height+70) ;
    }endShape();
    noStroke();
    fill(239,234,188) //moon reflection
    ellipse(100,height-20,130+random(-1,1),5+random(-1,1));
    noFill();
    fill(239,239,188);//secondary reflection 
    ellipse(80,height-15,80+random(-1,1),4+random(-1,1));
    noFill(); 
}

Since it was Halloween, I wanted to create a landscape that is staged at night with tree landscapes and witch houses on river’s edge. I wanted to give depth to the landscape formation. I have decided to create the river’s edge using the noise function in the p5js. When I tried to convey the sense of the 3D, I realized that giving a different in speed of object passage is very effective. I generated trees that differ in speed and height to convey the depth. Almost giving the sense of when someone walks in forest, they pass in different relative speed. I have created abstracted witch houses behind the trees. I created large moon and its reflection on the river to convey another layer of depth. Frame rate interact with the mouse X position giving a feel of running through the landscape vs. walking