xxxxxxxxxx
209
let yoff = 0.0; // 2nd dimension of perlin noise
let img;
fisharray =[];
colorarray = ['#b04119','yellow','magenta'];
var sunYpos = 500;
let cloudx = 100;
let cloudy = 100;
var b1, b2;
//ripples
let current = [];
let previous = [];
let dampening = 0.9;
//end ripples
function preload() {
imgSwimmer = loadImage("Assets/swimmer.png");
imgPoolboy = loadImage("Assets/poolman/poolboy.png");
imgPoolboy = loadImage("Assets/poolman/poolboy2.png");
imgskyline = loadImage("Assets/skyline.png");
}
function setup() {
setInterval(spawn,1000)
createCanvas(710, 400);
//ripples
pixelDensity(1);
// create nested arrays
// set all initial values to black
for (let xrip = 0; xrip < width; xrip++) {
current[xrip] = [];
previous[xrip] = [];
for (let yrip = 0; yrip < height; yrip++) {
current[xrip][yrip] = 0;
previous[xrip][yrip] = 0;
}
}
//end ripples
}
function mouseDragged() {
previous[mouseX][mouseY] = 255;
}
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(5, 5, frameCount);
// SUN
fill(255,255,0);
noStroke();
ellipseMode(CENTER);
ellipse(200, sunYpos, 300);
if (sunYpos > 200)
sunYpos--;
// END SUN
makeCloud(cloudx + 200, cloudy + 20)
image(imgskyline, 200,50);
imgskyline.resize(350,200);
fill(255,165,0);
stroke(100,100,100);
strokeWeight(2);
rect(0, 200, 700, 200);
makeCloud(cloudx, cloudy-25);
makeCloud(cloudx + 100, cloudy + 40)
// makeCloud(cloudx + 200, cloudy + 20)
makeCloud(cloudx + 500, cloudy + 10)
cloudx+=0.1;
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
noStroke()
for(var h of fisharray){
h.drawFish()
h.swim()
}
//ripples
/*
loadPixels();
for (let xrip = 1; xrip < width-1; xrip++) {
for (let yrip = 1; yrip < height-1; yrip++) {
current[xrip][yrip] = (
previous[xrip - 1][yrip] +
previous[xrip + 1][yrip] +
previous[xrip][yrip - 1] +
previous[xrip][yrip + 1] +
previous[xrip - 1][yrip - 1] +
previous[xrip - 1][yrip + 1] +
previous[xrip + 1][yrip - 1] +
previous[xrip + 1][yrip + 1]) / 4 -
current[xrip][yrip];
current[xrip][yrip] = current[xrip][yrip] * dampening;
let index = (yrip*width + xrip) * 4;
pixels[index] = current[xrip][yrip] * 255;
pixels[index+1] = current[xrip][yrip] * 255;
pixels[index+2] = current[xrip][yrip] * 255;
pixels[index+3] = 255;
}
}
updatePixels();
let temp = previous;
previous = current;
current = temp;
*/
//end riples
}
function makeCloud(cloudx, cloudy) {
fill(250)
noStroke();
ellipse(cloudx, cloudy, 70, 50);
ellipse(cloudx + 10, cloudy + 10, 70, 50);
ellipse(cloudx - 20, cloudy + 10, 70, 50);
}