xxxxxxxxxx
110
let noiseScale = 0.02;
let points = [];
let fishGroup = [];
let gradientBG;
let gradientBG1;
let type;
function preload(){
// fish=loadImage('seafish.webp');
}
function setup() {
createCanvas(800, 800);
colorMode(HSL, 360, 100, 100, 1);
createGradient();
generatePoints(100);
for (let p of points) {
let randomList=[0,1,1,1,2,2,2,2,2,2]
let types = random (0,10)/1;
if(randomList[types]=0){
type="radical";
}else if(randomList[types]=1){
type="moderate";
}else{
type="shifting";
}
fishGroup.push(new Fish(p.x, p.y,type,20, 'white'));
}
}
function draw() {
image(gradientBG,0,0);
image(gradientBG1,0,0);
createAxis();
sampleColor='white';
for (let fish of fishGroup) {
if (0 < mouseX && mouseX < width*0.8 && 0 < mouseY && mouseY < height*0.8) {
let mouse = createVector(mouseX, mouseY);
fish.attracted(mouse,20,25,400);
} else {
fish.moveFreely();
}
fish.show();
fish.update();
fish.shine();
}
}
function createGradient(){
gradientBG = createGraphics(800,800);
let gradient = {
from : [0, 0],
to : [0, 800],
steps : [
color('hsl(0,100%,95%)'),
color('hsl(0,100%,80%)'),
color('hsl(200,100%,50%)')
]
}
fillGradient('linear', gradient, gradientBG);
gradientBG.noStroke();
gradientBG.rect(0, 0, 800, 800);
gradientBG1 = createGraphics(800,800);
let gradient2 = {
from : [0, 0],
to : [800, 0],
steps : [
color(360,0,100,0.5),
color(360,0,100,0.25),
color(360,0,100,0)
]
}
fillGradient('linear', gradient2, gradientBG1);
gradientBG1.noStroke();
gradientBG1.rect(0, 0, 800, 800);
}
function createAxis(){
strokeWeight(2);
stroke('white');
line(0,400,800,400);
line(400,0,400,800);
}
function generatePoints(num) {
for (let i = 0; i < num; i++) {
let validPoint = false;
let attempts = 0;
while (!validPoint && attempts < 100) {
let candidate = createVector(random(width), random(height));
let noiseVal = noise(candidate.x * noiseScale, candidate.y * noiseScale);
if (noiseVal > 0.6) {
points.push(candidate);
validPoint = true;
}
attempts++;
}
}
}