xxxxxxxxxx
77
let particles = [];
const num = 1000;
const noiseScale = 0.01 / 2;
//for the fish
let img1;
let angle = 0; // Initialize the angle for rotation
let x1; // x-coordinate of the image
let y1; // y-coordinate of the image
let amplitude = 50; // Amplitude of oscillation
// let radius = 100; // Set the radius of the circle
let speed = 0.02; // Set the rotation speed
function preload() {
img1 = loadImage('fish1.png');
}
function setup() {
createCanvas(850, 600);
for (let i = 0; i < num; i++) {
particles.push(createVector(random(width), random(height)));
}
stroke(255, 60); // adjust the last number for the transparency of the strokes
strokeWeight(5); // adjust the thickness of the strokes
clear();
x1 = width / 8; // Initial x-coordinate (center of the canvas)
y1 = height / 8; // Initial y-coordinate (center of the canvas)
// Resize the image to your desired dimensions
let newWidth = 150; // New width in pixels
let newHeight = 150; // New height in pixels
img1.resize(newWidth, newHeight);
}
function draw() {
background(0, random() * 255, random() * 255, 5); //the smaller the last number is, the longer the strokes stay visible + the slower the background color switches.
//fish oscillating
// Calculate the x-coordinate based on oscillation
x1 = width / 8 + cos(angle) * amplitude;
// Calculate the y-coordinate (you can adjust this as needed)
y1 = height / 8 + sin(angle) * amplitude;
// Draw the image at the calculated (x, y) position
image(img1, x1, y1);
// Increment the angle to make the image oscillate
angle += 0.05; // Adjust the speed of oscillation as needed
for (let i = 0; i < num; i++) {
let p = particles[i];
point(p.x, p.y);
let n = noise(
p.x * noiseScale,
p.y * noiseScale,
frameCount * noiseScale * noiseScale
);
let a = TAU * n;
p.x += cos(a);
p.y += sin(a);
if (!onScreen(p)) {
p.x = random(width);
p.y = random(height);
}
}
}
function mouseReleased() {
noiseSeed(millis());
}
function onScreen(v) {
return v.x >= 0 && v.x <= width && v.y >= 0 && v.y <= height;
}