xxxxxxxxxx
263
let xSpeed = 0;
let ySpeed = 0;
let pointsL = [];
let count = 0;
let amount = 200;
let cols;
let rows;
let current; // = new float[cols][rows];
let previous; // = new float[cols][rows];
let dampening = 0.999;
let test;
let bgm;
let fish;
let key0,key1,key2,keys,keylong;
let fishx,fishy,fXspeed,fYspeed,rx,ry,eXspeed,rYspeed,y_sq;
let pre_h = 50;
let flag = false;
let angular = 0;
let rotatechange = 'x';
let choice;
function preload(){
bgm = loadSound('bgm.mp3');
fish = loadImage('jellyfishGIF.gif');
//key0 = loadSound('key0.mp3');
key1 = loadSound('key01.mp3');
key2 = loadSound('key02.mp3');
keylong = loadSound('longkeys.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
bgm.setVolume(1.3);
bgm.loop();
keys = [key1,key2];
fishx = -10;
fishy = windowHeight;
fXspeed = 0.5;
fYspeed = -0.5;
rx = 100;
ry = 100;
y_sq = sq(50);
for(let i = 0; i < amount; i++){
let p = new singlePoint();
pointsL.push(p);
}
//test = new singlePoint();
pixelDensity(1);
//createCanvas(600, 400);
cols = windowWidth;
rows = windowHeight;
current = new Array(cols).fill(0).map(n => new Array(rows).fill(0));
previous = new Array(cols).fill(0).map(n => new Array(rows).fill(0));
}
function draw() {
background(0);
/*
for(let i = 0; i < amount; i++){
pointsL[i].pointsShow();
pointsL[i].pointsMove();
if (i%2==0){
pointsL[i].colorPoints();
}
}*/
//jellyfish();
ripples();
if (mouseIsPressed){
//ripples();
previous[mouseX][mouseY] = 1500;
//ripples();
}
//image(fish,50,50);
jellyfish();
//rotateFish();
for(let i = 0; i < amount; i++){
pointsL[i].pointsShow();
pointsL[i].pointsMove();
if (i%2==0){
pointsL[i].colorPoints();
}
}
}
function jellyfish(){
if (fishx >= 50 && fishy >= 50){
flag = true;
}
/*if (flag && (fishx < 0 || fishx > windowWidth)){
fXspeed = -fXspeed;
}
if (flag && (fishy < 0 || fishy > windowHeight)){
fYspeed = -fYspeed;
}*/
fishx += fXspeed;
fishy += fYspeed;
image(fish,fishx,fishy,200,200);
}
function rotateFish(){
//radius 50
rXspeed = 0.5;
y_sq = y_sq - sq(0.5);
rYspeed = pre_h-sqrt(y_sq);
pre_h = pre_h-rYspeed;
if (angular >= 90 || (360 > angular >= 270)){
if (rotatechange == 'x'){
rXspeed = -rXspeed;
}
rotatechange = 'y';
y_sq = 50;
}
if ((270 > angular >= 180) || (angular>=360)) {
if (rotatechange == 'y'){
rYspeed = -rYspeed;
}
if (angular >= 360){
angular = 0;
}
rotatechange = 'x';
}
rx += rXspeed;
ry += rYspeed;
//translate(100, 100);
// rotate(mifdlis()/500);
image(fish,rx,ry,200,200);
angular += 9;
}
class singlePoint{
constructor(){
this.x = random(0,windowWidth);
this.y = random(0,windowHeight);
this.xSpeed = random(-0.8,0.8);
this.ySpeed = random(-0.8,0.8);
if (this.xSpeed == 0){
this.xSpeed = random(-1,1);
}
if (this.ySpeed == 0){
this.ySpeed = random(-1,1);
}
}
speedchange(){
this.xSpeed = -(this.xSpeed);
this.ySpeed = -(this.ySpeed);
}
pointsMove(){
if (this.x < 0 || this.x > windowWidth){
this.xSpeed = -(this.xSpeed);
}
if (this.y < 0 || this.y > windowHeight){
this.ySpeed = -(this.ySpeed);
}
this.x += this.xSpeed;
this.y += this.ySpeed;
}
pointsShow(){
//colorMode(HSB,255);
stroke(255);
strokeWeight(2);
point(this.x,this.y);
}
colorPoints(){
colorMode(RGB, 255, 255, 255, 1);
stroke(random(10,110),random(10,110),random(220,255),0.6);
strokeWeight(2);
point(this.x+random(-0.5,0.5),this.y+random(-0.7,0.7));
}
}
function ripples(){
loadPixels();
for (let i = 1; i < cols - 1; i++) {
for (let j = 1; j < rows - 1; j++) {
current[i][j] =
(previous[i - 1][j] +
previous[i + 1][j] +
previous[i][j - 1] +
previous[i][j + 1]) /
2 -
current[i][j];
current[i][j] = current[i][j] * dampening;
let index = (i + j * cols) * 4;
pixels[index + 0] = current[i][j];
pixels[index + 1] = current[i][j];
pixels[index + 2] = current[i][j];
lag(20);
}
}
updatePixels();
let temp = previous;
previous = current;
current = temp;
}
function mouseDragged() {
previous[mouseX][mouseY] = 500;
//stop();
keylong.setVolume(1.0);
keylong.play();
}
function mousePressed() {
//previous[mouseX][mouseY] = 1500;
choice = random(keys);
choice.setVolume(1.3);
choice.play();
}
function lag(number){
n = 0
while (n < number){
n+=1;
}
return;
}