let jitterAmount = 5; //the distance particles jitter
let jitterIterations = 5; // Number of jitter iterations
//variables for the particles colors
let galaxyColor = "rgba(200,169,169,0.5)"; //White
let galaxyStroke = "rgba(255,255,255,0.04)";
let heartColor = "rgba(255, 100, 100, 0.5)"; //Pink
let heartStroke = "rgba(255, 150, 150, 0.04)";
let spiralColor = "rgba(184, 134, 11, 0.5)"; // Dark Golden
let spiralStroke = "rgba(255, 215, 0, 0.04)";
let convergenceColor = "rgba(100, 149, 237, 0.5)"; // Blue
let convergenceStroke = "rgba(173, 216, 230, 0.04)";
let scatterColor = "rgba(60, 179, 113, 0.5)"; // Green color
let scatterStroke = "rgba(173, 255, 47, 0.04)";
// function that calculates the center of the particle cluster
function calculateCenter(particleArray) {
for (let i = 0; i < particleArray.length; i++) {
centerX += particleArray[i].x;
centerY += particleArray[i].y;
centerX /= particleArray.length;
centerY /= particleArray.length;
return [centerX, centerY];
this.num = 350; //number of particles in the galaxy
this.rotationSpeed = 0.002;
this.radius = max(width / 2, height / 2);
this.beforeMovement = [];
// initialize the particles to be scattered across the canvas in a circular distribution
for (let i = 0; i < this.num; i++) {
let angle = random(TWO_PI); //generate a random angle btwn 0 and 2π radians
let r = sqrt(random()) * this.radius; // random radius (limited to the MAXRADIUS of the distribution)
//calculate the x and y coordinates for the particle based on polar coordinates (angle and radius), converting them to Cartesian coordinates
let particleX = width / 2 + r * cos(angle);
let particleY = height / 2 + r * sin(angle);
//add the particle to the array
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
//move the entire cluster in a specific direction
moveGalaxy(xMovement, yMovement) {
for (let i = 0; i < this.particles.length; i++) {
this.particles[i].moveInDirection(xMovement, yMovement);
for (let i = 0; i < this.particles.length; i++) {
// Generate random movement for each particle
let xMovement = random(-2, 2); // Random movement along the x-axis
let yMovement = random(-2, 2); // Random movement along the y-axis
this.particles[i].moveInDirection(xMovement, yMovement);
//move the entire galaxy downwards
function moveDown(particleArray) {
// Adjust the number of iterations as needed
for (let i = 0; i < particleArray.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
particleArray[i].y += 2; // Move particles downwards
setTimeout(() => moveDown(particleArray), 10);
moveDown(this.particles);
this.returnToOriginalPositions(prevPositions);
//return the particles to the position that they were in before a certain position was enacted
returnToOriginalPositions() {
for (let i = 0; i < this.particles.length; i++) {
let direction = createVector(
this.beforeMovement[i][0] - this.particles[i].x,
this.beforeMovement[i][1] - this.particles[i].y
this.particles[i].x += direction.x * 0.1;
this.particles[i].y += direction.y * 0.1;
// Function to rotate the galaxy by a given rotation speed
rotateGalaxy(rotationSpeed) {
// Loop through all particles in the galaxy
for (let i = 0; i < this.particles.length; i++) {
// Calculate the angle between the particle's position and the center of the canvas
this.particles[i].y - height / 2, // Y-component distance from the center of the canvas
this.particles[i].x - width / 2 // X-component distance from the center of the canvas
// Add the rotation speed to the angle to rotate the particle
// Calculate the distance from the particle to the center of the canvas
width / 2, // X-coordinate of the center of the canvas
height / 2, // Y-coordinate of the center of the canvas
this.particles[i].x, // X-coordinate of the particle
this.particles[i].y // Y-coordinate of the particle
// Update the particle's position based on the new angle and radius
this.particles[i].x = width / 2 + radius * cos(angle);
this.particles[i].y = height / 2 + radius * sin(angle);
// Calculate the new center of the galaxy based on the updated particle positions
let center = calculateCenter(this.particles);
// Update the center X and Y coordinates of the galaxy
this.centerX = center[0];
this.centerY = center[1];
// Function to jitter (move randomly) particles within a given limit
let iterations = 0; // Variable to track the number of iterations for jittering
let prevPositions = []; // Array to store previous positions of particles
// Inner function to perform the actual jittering of particle positions recursively
function jitter(particleArray) {
// Perform jittering for 10 iterations
for (let i = 0; i < particleArray.length; i++) {
// Store the previous positions of particles before jittering
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Move particles randomly within a specific range (jitterAmount)
particleArray[i].x += random(-jitterAmount, jitterAmount) * 4;
particleArray[i].y += random(-jitterAmount, jitterAmount) * 4;
// On the first iteration, randomly change the color of some particles
let changeColor = random(0, 1);
particleArray[i].particleColor = scatterColor; // Change particle color
particleArray[i].strokeColor = scatterStroke; // Change stroke color
} else if (changeColor < 0.3) {
particleArray[i].particleColor = galaxyColor; // Restore particle color
particleArray[i].strokeColor = galaxyStroke; // Restore stroke color
iterations++; // Increment the iteration count
// Use setTimeout to call the jitter function recursively after a delay of 10 milliseconds
setTimeout(() => jitter(particleArray), 10);
// Start the jittering process for the current set of particles
// Save the positions of particles before the movement for reference
this.beforeMovement = prevPositions;
// Calculate the new center of the particle set after jittering
let center = calculateCenter(this.particles);
// Update the center X and Y coordinates of the particle set
this.centerX = center[0];
this.centerY = center[1];
// Function to jitter particles upwards within a given limit
jitterParticlesUpwards() {
let iterations = 0; // Variable to track the number of iterations for jittering upwards
// Inner function to perform the upward jittering of particle positions recursively
function jitterUpwards(particleArray) {
if (iterations < jitterIterations) {
// Perform upward jittering for a specified number of iterations
for (let i = 0; i < particleArray.length; i++) {
// Move particles randomly within a specific range horizontally (x-axis)
// Move particles upwards by adjusting the y-coordinate (subtracting from y-axis)
particleArray[i].x += random(-jitterAmount, jitterAmount) * 4;
particleArray[i].y -= random(0, jitterAmount) * 4; // Adjusting y coordinate to move particles upwards
iterations++; // Increment the iteration count
// Use setTimeout to call the jitterUpwards function recursively after a delay of 10 milliseconds (adjustable)
setTimeout(() => jitterUpwards(particleArray), 10); // Adjust timeout as needed for speed
// Start the upward jittering process for the current set of particles
jitterUpwards(this.particles);
jitterParticlesCloser() {
function jitterCloser(particleArray) {
if (iterations < jitterIterations) {
for (let i = 0; i < particleArray.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
let xOffset = random(-jitterAmount, jitterAmount) * 0.4;
let yOffset = random(-jitterAmount, jitterAmount) * 0.4;
particleArray[i].x += xOffset * 0.5; // Adjust x-coordinate to bring particles closer
particleArray[i].y += yOffset * 0.5; // Adjust y-coordinate to bring particles closer
setTimeout(() => jitterCloser(particleArray), 10); // Adjust timeout for speed of jittering
jitterCloser(this.particles);
this.beforeMovement = prevPositions;
jitterParticlesTowardsCenter() {
const convergenceRate = 0.05; // Rate at which particles converge towards the center
// console.log("woooo big function");
function jitter(particleArray, centralY, centralX) {
// console.log("woooo function");
if (iterations < totalIterations) {
// console.log("woooo iterations");
for (let i = 0; i < particleArray.length; i++) {
// Calculate distance to the center
const distanceX = centralX - particleArray[i].x;
const distanceY = centralY - particleArray[i].y;
// Move particles closer together
particleArray[i].x += random(-jitterAmnt, jitterAmnt) * 6;
particleArray[i].y += random(-jitterAmnt, jitterAmnt) * 6;
// Move particles towards the center
particleArray[i].x += distanceX * convergenceRate;
particleArray[i].y += distanceY * convergenceRate;
let changeColor = random(0, 1);
particleArray[i].particleColor = convergenceColor;
particleArray[i].strokeColor = convergenceStroke;
setTimeout(() => jitter(particleArray, centralX, centralY), 0.5); // Adjust timeout as needed for speed
jitter(this.particles, this.centerX, this.centerY);
const explodeIterations = 30; // Adjust the number of iterations for the explosion
function explode(particleArray) {
if (iterations < explodeIterations) {
// Calculate the center of the galaxy (average position of all particles)
for (let i = 0; i < particleArray.length; i++) {
centerX += particleArray[i].x;
centerY += particleArray[i].y;
centerX /= particleArray.length;
centerY /= particleArray.length;
for (let i = 0; i < particleArray.length; i++) {
// Move particles away from the center of the galaxy
let deltaX = (particleArray[i].x - centerX) / 15;
let deltaY = (particleArray[i].y - centerY) / 15;
// Adjust the particles' positions
particleArray[i].x += deltaX * 0.1; // Adjust the factor to control the speed of explosion
particleArray[i].y += deltaY * 0.1; // Adjust the factor to control the speed of explosion
setTimeout(() => explode(particleArray), 10); // Adjust timeout as needed
let heartIterations = 30;
function moveTowardsHeart(particleArray, heartParticles) {
if (iterations < heartIterations) {
for (let i = 0; i < heartParticles.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Calculate the movement towards the heart shape
let targetX = heartParticles[i].x;
let targetY = heartParticles[i].y;
// Update particle positions towards the heart shape
particleArray[i].x += (targetX - particleArray[i].x) * 0.4; // Adjust the animation speed as needed
particleArray[i].y += (targetY - particleArray[i].y) * 0.4; // Adjust the animation speed as needed
particleArray[i].particleColor = heartColor; // Change the color to red during animation
particleArray[i].strokeColor = heartStroke; // Change the stroke color to blue during animation
setTimeout(() => moveTowardsHeart(particleArray, heartParticles), 10); // Adjust timeout as needed for speed
let heartParticles = []; // Define heart shape particles here
// Calculate heart shape particles as before
let spacing = 15; // Adjust this for the heart shape
for (let angle = 0; angle < TWO_PI; angle += 0.1) {
// Calculate x and y coordinates for the heart shape using mathematical functions
let x = 16 * pow(sin(angle), 3);
13 * cos(angle) - // First circular pattern
5 * cos(2 * angle) - // Second circular pattern with twice the frequency
2 * cos(3 * angle) - // Third circular pattern with three times the frequency
) // Fourth circular pattern with four times the frequency
// Scale the coordinates by a spacing factor
// Shift the heart shape to the center of the canvas
// Store the calculated x and y coordinates as a vector in the heartParticles array
heartParticles.push(createVector(x, y));
moveTowardsHeart(this.particles, heartParticles);
this.beforeMovement = prevPositions;
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
moveParticlesInSpiral() {
let spiralIterations = 35;
function moveTowardsSpiral(particleArray, spiralParticles) {
if (iterations < spiralIterations) {
for (let i = 0; i < spiralParticles.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Calculate the movement towards the spiral shape
let targetX = spiralParticles[i].x;
let targetY = spiralParticles[i].y;
// Update particle positions towards the spiral shape
particleArray[i].x += (targetX - particleArray[i].x) * 0.4; // Adjust the animation speed as needed
particleArray[i].y += (targetY - particleArray[i].y) * 0.4; // Adjust the animation speed as needed
particleArray[i].particleColor = spiralColor; // Change the color to red during animation
particleArray[i].strokeColor = spiralStroke;
setTimeout(() => moveTowardsSpiral(particleArray, spiralParticles), 10); // Adjust timeout as needed for speed
let spiralParticles = []; // Define spiral shape particles here
// Calculate spiral shape particles
let spacing = 10; // Adjust this for the spiral shape
for (let angle = 0; angle < 6 * PI; angle += 0.1) {
// Calculate x and y coordinates for the spiral shape using trigonometric functions
let x = angle * cos(angle) * spacing + width / 2;
let y = angle * sin(angle) * spacing + height / 2;
spiralParticles.push(createVector(x, y));
moveTowardsSpiral(this.particles, spiralParticles);
this.beforeMovement = prevPositions;
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
//function to actually draw the galaxy
for (let i = 0; i < this.particles.length; i++) {
this.particles[i].createParticle(); // Create a single particle
this.particles[i].joinParticles(this.particles.slice(i)); // Join the created particle with others
let jitterAmount = 5; //the distance particles jitter
let jitterIterations = 5; // Number of jitter iterations
//variables for the particles colors
let galaxyColor = "rgba(200,169,169,0.5)"; //White
let galaxyStroke = "rgba(255,255,255,0.04)";
let heartColor = "rgba(255, 100, 100, 0.5)"; //Pink
let heartStroke = "rgba(255, 150, 150, 0.04)";
let spiralColor = "rgba(184, 134, 11, 0.5)"; // Dark Golden
let spiralStroke = "rgba(255, 215, 0, 0.04)";
let convergenceColor = "rgba(100, 149, 237, 0.5)"; // Blue
let convergenceStroke = "rgba(173, 216, 230, 0.04)";
let scatterColor = "rgba(60, 179, 113, 0.5)"; // Green color
let scatterStroke = "rgba(173, 255, 47, 0.04)";
// function that calculates the center of the particle cluster
function calculateCenter(particleArray) {
let centerX = 0;
let centerY = 0;
for (let i = 0; i < particleArray.length; i++) {
centerX += particleArray[i].x;
centerY += particleArray[i].y;
}
centerX /= particleArray.length;
centerY /= particleArray.length;
return [centerX, centerY];
}
class Galaxy {
constructor() {
this.num = 350; //number of particles in the galaxy
this.rotationSpeed = 0.002;
this.radius = max(width / 2, height / 2);
this.particles = [];
this.centerX = 0;
this.centerY = 0;
this.beforeMovement = [];
// initialize the particles to be scattered across the canvas in a circular distribution
for (let i = 0; i < this.num; i++) {
let angle = random(TWO_PI); //generate a random angle btwn 0 and 2π radians
let r = sqrt(random()) * this.radius; // random radius (limited to the MAXRADIUS of the distribution)
//calculate the x and y coordinates for the particle based on polar coordinates (angle and radius), converting them to Cartesian coordinates
let particleX = width / 2 + r * cos(angle);
let particleY = height / 2 + r * sin(angle);
//add the particle to the array
this.particles.push(
new Particle(
particleX,
particleY,
galaxyColor,
galaxyStroke,
"rgba(255,255,255,0.04)"
)
);
}
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
}
//move the entire cluster in a specific direction
moveGalaxy(xMovement, yMovement) {
for (let i = 0; i < this.particles.length; i++) {
this.particles[i].moveInDirection(xMovement, yMovement);
}
}
moveGalaxyRandom() {
for (let i = 0; i < this.particles.length; i++) {
// Generate random movement for each particle
let xMovement = random(-2, 2); // Random movement along the x-axis
let yMovement = random(-2, 2); // Random movement along the y-axis
this.particles[i].moveInDirection(xMovement, yMovement);
}
}
//move the entire galaxy downwards
moveGalaxyDownwards() {
let iterations = 0;
let prevPositions = [];
function moveDown(particleArray) {
if (iterations < 30) {
// Adjust the number of iterations as needed
for (let i = 0; i < particleArray.length; i++) {
if (iterations == 0) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
}
particleArray[i].y += 2; // Move particles downwards
}
iterations++;
setTimeout(() => moveDown(particleArray), 10);
}
}
moveDown(this.particles);
this.returnToOriginalPositions(prevPositions);
}
//return the particles to the position that they were in before a certain position was enacted
returnToOriginalPositions() {
for (let i = 0; i < this.particles.length; i++) {
let direction = createVector(
this.beforeMovement[i][0] - this.particles[i].x,
this.beforeMovement[i][1] - this.particles[i].y
);
this.particles[i].x += direction.x * 0.1;
this.particles[i].y += direction.y * 0.1;
}
}
//rotate the galaxy
// Function to rotate the galaxy by a given rotation speed
rotateGalaxy(rotationSpeed) {
// Loop through all particles in the galaxy
for (let i = 0; i < this.particles.length; i++) {
// Calculate the angle between the particle's position and the center of the canvas
let angle = atan2(
this.particles[i].y - height / 2, // Y-component distance from the center of the canvas
this.particles[i].x - width / 2 // X-component distance from the center of the canvas
);
// Add the rotation speed to the angle to rotate the particle
angle += rotationSpeed;
// Calculate the distance from the particle to the center of the canvas
let radius = dist(
width / 2, // X-coordinate of the center of the canvas
height / 2, // Y-coordinate of the center of the canvas
this.particles[i].x, // X-coordinate of the particle
this.particles[i].y // Y-coordinate of the particle
);
// Update the particle's position based on the new angle and radius
this.particles[i].x = width / 2 + radius * cos(angle);
this.particles[i].y = height / 2 + radius * sin(angle);
}
// Calculate the new center of the galaxy based on the updated particle positions
let center = calculateCenter(this.particles);
// Update the center X and Y coordinates of the galaxy
this.centerX = center[0];
this.centerY = center[1];
}
// Function to jitter (move randomly) particles within a given limit
jitterParticles() {
let iterations = 0; // Variable to track the number of iterations for jittering
let prevPositions = []; // Array to store previous positions of particles
// Inner function to perform the actual jittering of particle positions recursively
function jitter(particleArray) {
if (iterations < 10) {
// Perform jittering for 10 iterations
for (let i = 0; i < particleArray.length; i++) {
// Store the previous positions of particles before jittering
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Move particles randomly within a specific range (jitterAmount)
particleArray[i].x += random(-jitterAmount, jitterAmount) * 4;
particleArray[i].y += random(-jitterAmount, jitterAmount) * 4;
// On the first iteration, randomly change the color of some particles
if (iterations == 0) {
let changeColor = random(0, 1);
if (changeColor > 0.5) {
particleArray[i].particleColor = scatterColor; // Change particle color
particleArray[i].strokeColor = scatterStroke; // Change stroke color
} else if (changeColor < 0.3) {
particleArray[i].particleColor = galaxyColor; // Restore particle color
particleArray[i].strokeColor = galaxyStroke; // Restore stroke color
}
}
}
iterations++; // Increment the iteration count
// Use setTimeout to call the jitter function recursively after a delay of 10 milliseconds
setTimeout(() => jitter(particleArray), 10);
}
}
// Start the jittering process for the current set of particles
jitter(this.particles);
// Save the positions of particles before the movement for reference
this.beforeMovement = prevPositions;
// Calculate the new center of the particle set after jittering
let center = calculateCenter(this.particles);
// Update the center X and Y coordinates of the particle set
this.centerX = center[0];
this.centerY = center[1];
}
// Function to jitter particles upwards within a given limit
jitterParticlesUpwards() {
let iterations = 0; // Variable to track the number of iterations for jittering upwards
// Inner function to perform the upward jittering of particle positions recursively
function jitterUpwards(particleArray) {
if (iterations < jitterIterations) {
// Perform upward jittering for a specified number of iterations
for (let i = 0; i < particleArray.length; i++) {
// Move particles randomly within a specific range horizontally (x-axis)
// Move particles upwards by adjusting the y-coordinate (subtracting from y-axis)
particleArray[i].x += random(-jitterAmount, jitterAmount) * 4;
particleArray[i].y -= random(0, jitterAmount) * 4; // Adjusting y coordinate to move particles upwards
}
iterations++; // Increment the iteration count
// Use setTimeout to call the jitterUpwards function recursively after a delay of 10 milliseconds (adjustable)
setTimeout(() => jitterUpwards(particleArray), 10); // Adjust timeout as needed for speed
}
}
// Start the upward jittering process for the current set of particles
jitterUpwards(this.particles);
}
jitterParticlesCloser() {
let iterations = 0;
let prevPositions = [];
function jitterCloser(particleArray) {
if (iterations < jitterIterations) {
for (let i = 0; i < particleArray.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
let xOffset = random(-jitterAmount, jitterAmount) * 0.4;
let yOffset = random(-jitterAmount, jitterAmount) * 0.4;
particleArray[i].x += xOffset * 0.5; // Adjust x-coordinate to bring particles closer
particleArray[i].y += yOffset * 0.5; // Adjust y-coordinate to bring particles closer
}
iterations++;
setTimeout(() => jitterCloser(particleArray), 10); // Adjust timeout for speed of jittering
}
}
jitterCloser(this.particles);
this.beforeMovement = prevPositions;
}
jitterParticlesTowardsCenter() {
let iterations = 0;
let totalIterations = 7;
let jitterAmnt = 5;
const convergenceRate = 0.05; // Rate at which particles converge towards the center
// console.log("woooo big function");
function jitter(particleArray, centralY, centralX) {
// console.log("woooo function");
if (iterations < totalIterations) {
// console.log("woooo iterations");
for (let i = 0; i < particleArray.length; i++) {
// Calculate distance to the center
const distanceX = centralX - particleArray[i].x;
const distanceY = centralY - particleArray[i].y;
// Move particles closer together
particleArray[i].x += random(-jitterAmnt, jitterAmnt) * 6;
particleArray[i].y += random(-jitterAmnt, jitterAmnt) * 6;
// Move particles towards the center
particleArray[i].x += distanceX * convergenceRate;
particleArray[i].y += distanceY * convergenceRate;
if (iterations == 0) {
let changeColor = random(0, 1);
if (changeColor > 0.5) {
particleArray[i].particleColor = convergenceColor;
particleArray[i].strokeColor = convergenceStroke;
}
}
}
iterations++;
setTimeout(() => jitter(particleArray, centralX, centralY), 0.5); // Adjust timeout as needed for speed
}
}
jitter(this.particles, this.centerX, this.centerY);
}
explodeParticles() {
let iterations = 0;
const explodeIterations = 30; // Adjust the number of iterations for the explosion
function explode(particleArray) {
if (iterations < explodeIterations) {
// Calculate the center of the galaxy (average position of all particles)
let centerX = 0;
let centerY = 0;
for (let i = 0; i < particleArray.length; i++) {
centerX += particleArray[i].x;
centerY += particleArray[i].y;
}
centerX /= particleArray.length;
centerY /= particleArray.length;
for (let i = 0; i < particleArray.length; i++) {
// Move particles away from the center of the galaxy
let deltaX = (particleArray[i].x - centerX) / 15;
let deltaY = (particleArray[i].y - centerY) / 15;
// Adjust the particles' positions
particleArray[i].x += deltaX * 0.1; // Adjust the factor to control the speed of explosion
particleArray[i].y += deltaY * 0.1; // Adjust the factor to control the speed of explosion
}
iterations++;
setTimeout(() => explode(particleArray), 10); // Adjust timeout as needed
}
}
explode(this.particles);
}
moveParticlesInHeart() {
let iterations = 0;
let prevPositions = [];
let heartIterations = 30;
function moveTowardsHeart(particleArray, heartParticles) {
if (iterations < heartIterations) {
for (let i = 0; i < heartParticles.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Calculate the movement towards the heart shape
let targetX = heartParticles[i].x;
let targetY = heartParticles[i].y;
// Update particle positions towards the heart shape
particleArray[i].x += (targetX - particleArray[i].x) * 0.4; // Adjust the animation speed as needed
particleArray[i].y += (targetY - particleArray[i].y) * 0.4; // Adjust the animation speed as needed
particleArray[i].particleColor = heartColor; // Change the color to red during animation
particleArray[i].strokeColor = heartStroke; // Change the stroke color to blue during animation
}
iterations++;
setTimeout(() => moveTowardsHeart(particleArray, heartParticles), 10); // Adjust timeout as needed for speed
}
}
let heartParticles = []; // Define heart shape particles here
// Calculate heart shape particles as before
let spacing = 15; // Adjust this for the heart shape
for (let angle = 0; angle < TWO_PI; angle += 0.1) {
// Calculate x and y coordinates for the heart shape using mathematical functions
let x = 16 * pow(sin(angle), 3);
let y = -(
(
13 * cos(angle) - // First circular pattern
5 * cos(2 * angle) - // Second circular pattern with twice the frequency
2 * cos(3 * angle) - // Third circular pattern with three times the frequency
cos(4 * angle)
) // Fourth circular pattern with four times the frequency
);
// Scale the coordinates by a spacing factor
x *= spacing;
y *= spacing;
// Shift the heart shape to the center of the canvas
x += width / 2;
y += height / 2;
// Store the calculated x and y coordinates as a vector in the heartParticles array
heartParticles.push(createVector(x, y));
}
moveTowardsHeart(this.particles, heartParticles);
this.beforeMovement = prevPositions;
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
}
moveParticlesInSpiral() {
let iterations = 0;
let prevPositions = [];
let spiralIterations = 35;
function moveTowardsSpiral(particleArray, spiralParticles) {
if (iterations < spiralIterations) {
for (let i = 0; i < spiralParticles.length; i++) {
prevPositions.push([particleArray[i].x, particleArray[i].y]);
// Calculate the movement towards the spiral shape
let targetX = spiralParticles[i].x;
let targetY = spiralParticles[i].y;
// Update particle positions towards the spiral shape
particleArray[i].x += (targetX - particleArray[i].x) * 0.4; // Adjust the animation speed as needed
particleArray[i].y += (targetY - particleArray[i].y) * 0.4; // Adjust the animation speed as needed
particleArray[i].particleColor = spiralColor; // Change the color to red during animation
particleArray[i].strokeColor = spiralStroke;
}
iterations++;
setTimeout(() => moveTowardsSpiral(particleArray, spiralParticles), 10); // Adjust timeout as needed for speed
}
}
let spiralParticles = []; // Define spiral shape particles here
// Calculate spiral shape particles
let spacing = 10; // Adjust this for the spiral shape
for (let angle = 0; angle < 6 * PI; angle += 0.1) {
// Calculate x and y coordinates for the spiral shape using trigonometric functions
let x = angle * cos(angle) * spacing + width / 2;
let y = angle * sin(angle) * spacing + height / 2;
spiralParticles.push(createVector(x, y));
}
moveTowardsSpiral(this.particles, spiralParticles);
this.beforeMovement = prevPositions;
let center = calculateCenter(this.particles);
this.centerX = center[0];
this.centerY = center[1];
}
//function to actually draw the galaxy
drawGalaxy() {
for (let i = 0; i < this.particles.length; i++) {
this.particles[i].createParticle(); // Create a single particle
this.particles[i].joinParticles(this.particles.slice(i)); // Join the created particle with others
}
}
}