// Sophia S Kim
// Section C 1:30
// sophiaki@andrew.cmu.edu
// Project-09-Portrait
var fish = [];
function setup() {
createCanvas(480, 480);
frameRate(7);
for(var l = 0; l < 10; l++) {
var fx = random(width);
fish[l] = makeFish(fx);
}
frameRate(6);
}
function draw() {
background(212, 211, 234);
sun(); //sun in the sky
mountainBackground(); //mountain
hillInFrontofMountain(); //small hill in front of mountain
waterRiver(); //river at the bottom
updateFish();
removeFish();
randomFish();
fishDisplay();
//randomizes fish in the "river"
}
// displays fish
function updateFish(){
for (var i = 0; i < fish.length; i++){
fish[i].move();
fish[i].display();
}
}
// fish disappear when hitting the edge
function removeFish(){
var fishKeep = [];
for (var q = 0; q < fish.length; q++){
if (fish[q].x + fish[q].breadth > 0) {
fishKeep.push(fish[q]);
}
}
fish = fishKeep;
}
// randomized fish to be added to the end
function randomFish() {
var updatedNewFish = 0.009;
if (random(0, 1) < updatedNewFish) {
fish.push(makeFish(width));
}
}
// update position of fish
function fishMove() {
this.x += this.speed;
}
// drawing the fish
function fishDisplay() {
var floorHeight = 20;
var bHeight = this.nFloors * floorHeight;
push();
noStroke();
translate(this.x, height - 140);
//fish body
fill(255, 161, 210);
ellipse(3, bHeight+20, 35, 25);
//fish tail
fill(255, 161, 210);
triangle(10, bHeight+20, 30, bHeight, 30, bHeight+40);
pop();
}
function makeFish(birthLocationX) {
var fhm = {x: birthLocationX,
breadth: 5,
speed: -3.0,
nFloors: round(random(2,4)),
move: fishMove,
display: fishDisplay}
return fhm;
}
function waterRiver() {
//makes the "river" appear
fill(8, 42, 102);
rect(-1, 350, 480, 130);
}
function hillInFrontofMountain() {
//makes the hill in front of the mountain move
var terrainSpeed3 = 0.0001;
var terrainDetail3 = 0.002;
beginShape();
stroke(44, 87, 181);
for (var x3 = 0; x3 < width; x3++) {
var p = (x3 * terrainDetail3) + (millis() * terrainSpeed3);
var z = map(noise(p), 0, 1, 300, 200);
line(x3, z, x3, height);
}
endShape();
}
function mountainBackground() {
//makes mountains in the back
var terrainSpeed2 = 0.0005;
var terrainDetail2 = 0.01;
stroke(99, 129, 214);
beginShape();
for (var x2 = 0; x2 < width; x2++) {
var t = (x2 * terrainDetail2) + (millis() * terrainSpeed2);
var y2 = map(noise(t), 0, 1, 200, 10);
line(x2, y2, x2, height);
}
endShape();
}
function sun() {
fill(234, 119, 101);
noStroke();
ellipse(417, 60, 80, 80);
fill(255, 146, 128);
noStroke();
ellipse(420, 60, 75, 75);
}
As it gets colder in Pittsburgh, I started to miss the warm weather and my trip to Taiwan. For my landscape, I definitely wanted to make a view of mountains. This photo came to mind.
Among all the projects, this project was the hardest. I had a really hard time with making the fishes and making them move. I had a really hard time making the mountains long and keeping them consistent. Overall, I don’t really like the outcome of the final project. If I had to make changes, I would definitely add more details to the mountain.