mmirho – Project 10 – Inside a Submarine

This is supposed to show what it would be like to look out of a submarine!

Different color and sized fish fly by at different speeds, as you peek through the portholes.

I will admit, however, I was unable to figure out how to use objects effectively without blatantly copying the format given to me. Instead, I used loops and if statements, and I understand I did this project incorrectly. However, I hope it satisfies the requirement for a landscape! 🙂

I plan to schedule some office hours to more fully understand how objects function. Sorry!

sketch

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

//Creates fish x location for each 
//fish to increment with speed
var fishX1 = 0;
var fishX2 = 0;
var fishX3 = 0;

//Assigns speed values for each fish
var speed1 = 0;
var speed2 = 0;
var speed3 = 0;

//Assigns vertical location values for each fish
var up1 = 0;
var up2 = 0;
var up3 = 0;


//Assigns r, g, and b values for each fish
var r1 = 0;
var r2 = 0;
var r3 = 0;
var g1 = 0;
var g2 = 0;
var g3 = 0;
var b1 = 0;
var b2 = 0;
var b3 = 0;

//Assigns size variables to each of the three fish
var big1 = 0;
var big2 = 0;
var big3 = 0;


function draw() {
    background(255);

    //This assigns random variables to each fish
    //so they are a random size, speed, location, and color
    if (fishX1 < 1) {
        speed1 = random(0.1,2);
        up1 = height/2 + random(-50,50);
        r1 = random(0,200);
        g1 = random(0,200);
        b1 = random(0,200);
        big1 = random(10,30);
    } else if (fishX2 < 1) {
        speed2 = random(0.1,2);
        up2 = height/2 + random(-50,50);
        r2 = random(0,200);
        g2 = random(0,200);
        b2 = random(0,200);
        big2 = random(10,30);
    } else if (fishX3 < 1) {
        speed3 = random(0.1,2);
        up3 = height/2 + random(-50,50);
        r3 = random(0,200);
        g3 = random(0,200);
        b3 = random(0,200);
        big3 = random(10,30);
    }

    //Moves the fish at a random speed
    fishX1 += speed1;
    fishX2 += speed2;
    fishX3 += speed3;

    //Makes each fish
    fish(fishX1, up1, big1, r1,g1,b1)
    fish(fishX2, up2, big2, r2,g2,b2)
    fish(fishX3, up3, big3, r3,g3,b3)



    //Makes the submarine inside background
    subBackground();


    porthole(width/4, height/2);
    porthole(3*width/4, height/2);

    //resets the location of the fish at 0 when it 
    //reaches the end

    if (fishX1 > width) {
        fishX1 = 0;
    } else if (fishX2 > width) {
        fishX2 = 0;
    } else if (fishX3 > width) {
        fishX3 = 0;
    }
}

function porthole(x,y) {

    //Makes a porthole, with the inside slightly blue
    //but translucent, so it acts like a window

    fill(0, 0, 200, 80);
    strokeWeight(30);
    stroke(200);
    ellipse(x,y,height/3,height/3);

}

function fish(x,y,big,r,g,b) {

    //Makes a fish with an ellipse and a triangle

    fill(r,g,b);
    noStroke();
    ellipse(x,y,big*2,big)
    triangle(x-big/2,y,   x-big*1.5,y+big/2,   x-big*1.5,y-big/2);
    fill(0);

    //adds a little eye
    ellipse(x+3*big/5, y-big/4.5, 3,3);

}

function subBackground() {

    //Fills in the outside of the portholes with
    //green, indicating the inside of the submarine

    fill(0,70,0);
    rectMode(CENTER);
    rect(width/2, height/2, 100, height);
    rect(width/2 - 237, height/2, 100, height);
    rect(width/2 + 237, height/2, 100, height);
    rect(width/2, height/2-215, width, 300);
    rect(width/2, height/2+215, width, 300);

}

Leave a Reply