Spaces:
Running
Running
File size: 2,180 Bytes
21d7fc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
export const loadingSketch = `let particles = [];
let numParticles = 28;
let circleRadius = 50;
let rotationSpeed = 0.02;
let particleMinSize = 3;
let particleMaxSize = 7;
let centerX;
let centerY;
let freeformAmplitude = 2;
let freeformSpeed = 0.01;
let color1Hex = "#217BFE";
let color2Hex = "#078BFE";
let color3Hex = "#AC87EB";
let color1;
let color2;
let color3;
function setup() {
createCanvas(500, 500);
background(0);
noStroke();
color1 = color(color1Hex);
color2 = color(color2Hex);
color3 = color(color3Hex);
centerX = width / 2;
centerY = height / 2;
for (let i = 0; i < numParticles; i++) {
particles.push(new Particle(i, numParticles));
}
}
function draw() {
background(0, 50);
for (let particle of particles) {
particle.update();
particle.display();
}
}
class Particle {
constructor(index, totalParticles) {
this.index = index;
this.totalParticles = totalParticles;
this.radiusOffset = (index / totalParticles) * TWO_PI;
this.angle = this.radiusOffset;
this.speedVariation = random(0.7, 1.3);
this.size = random(particleMinSize, particleMaxSize);
this.colorValue = this.getColor(index, totalParticles);
this.pos = createVector(0, 0);
}
getColor(index, totalParticles) {
let normalizedIndex = index / (totalParticles - 1);
let particleColor;
if (normalizedIndex < 0.5) {
particleColor = lerpColor(color1, color2, normalizedIndex * 2);
} else {
particleColor = lerpColor(color2, color3, (normalizedIndex - 0.5) * 2);
}
return particleColor;
}
update() {
this.angle += rotationSpeed * this.speedVariation;
let base_x = centerX + cos(this.angle) * circleRadius;
let base_y = centerY + sin(this.angle) * circleRadius;
let noiseX = map(noise(this.angle * 2 + frameCount * freeformSpeed), 0, 1, -freeformAmplitude, freeformAmplitude);
let noiseY = map(noise(this.angle * 2 + frameCount * freeformSpeed + 100), 0, 1, -freeformAmplitude, freeformAmplitude);
this.pos.set(base_x + noiseX, base_y + noiseY);
}
display() {
fill(this.colorValue);
ellipse(this.pos.x, this.pos.y, this.size, this.size);
}
}`; |