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.

Leave a Reply