xxxxxxxxxx
95
let yoff = 0.0; // 2nd dimension of perlin noise
let img;
fisharray =[]
colorarray = ['#b04119','yellow','magenta']
function preload() {
imgSwimmer = loadImage("Assets/swimmer.png");
imgFish1 = loadImage("Assets/bluefish-small.png");
}
function setup() {
setInterval(spawn,1000)
createCanvas(710, 400);
}
function Fish(x,y,filler,speed,size){
this.x = x
this.y = y
this.filler = filler
this.speed = speed
this.size = size
//movement
this.swim = function(){
this.x -= speed
}
this.drawFish = function(){
fill(this.filler)
ellipse(this.x,this.y,this.size,this.size-((this.size)/2))
triangle(this.x + 15,this.y,this.x+40,this.y-15,this.x+40,this.y+15)
fill(20)
ellipse(this.x-10,this.y,10,10)
}
}
function spawn(){
var h = new Fish(random(500,700),random(250,400),random(colorarray),random(1,4),random(30,50))
fisharray.push(h)
}
function draw() {
background(176, 216, 230);
// SUN
fill(255,255,0);
noStroke();
ellipse(56, 46, 55, 55);
// END SUN
fill(255,165,0);
stroke(100,100,100);
strokeWeight(2);
rect(0, 200, 700, 200);
image(imgSwimmer, 0, 50);
// WATER CODE - We are going to draw a polygon out of the wave points
fill(0,0, 160);
stroke(100,100,100);
strokeWeight(2);
beginShape();
let xoff = 0; // Option #1: 2D Noise
// let xoff = yoff; // Option #2: 1D Noise
// Iterate over horizontal pixels
for (let x = 0; x <= width; x += 10) {
// Calculate a y value according to noise, map to
// Option #1: 2D Noise
let y = map(noise(xoff, yoff), 0, 5, 200, 300);
// Option #2: 1D Noise
// let y = map(noise(xoff), 0, 1, 200,300);
// Set the vertex
vertex(x, y);
// Increment x dimension for noise
xoff += 0.05;
}
// increment y dimension for noise
yoff += 0.01;
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
//END WATER CODE
image(imgFish1, 0, 200);
noStroke()
for(var h of fisharray){
h.drawFish()
h.swim()
}
}