xxxxxxxxxx
71
let auroras = [];
let stars = [];
let noiseScale = 0.01;
let t = 0; // Time variable for animation
class Aurora {
constructor(r, g, b, minAlpha, maxAlpha) {
this.r = r;
this.g = g;
this.b = b;
//transparency
this.minAlpha = minAlpha;
this.maxAlpha = maxAlpha;
}
draw() {
for (let x = 0; x < width; x++) {
let noiseValX = noise(x * noiseScale, t); // Add time as the third dimension
let noiseValY = noise(x * noiseScale, t + 10); // Add time as the third dimension for Y as well
let offsetY = map(noiseValX, 0, 1, -height * 0.125, height * 0.125);
let baseY = height * 0.7 + offsetY;
let y = baseY + map(noiseValY, 0, 1, -height * 0.125, height * 0.125);
stroke(this.r, this.g, this.b, map(noiseValX, 0, 1, this.minAlpha, this.maxAlpha));
line(x, 0, x, y);
}
}
}
class Star {
draw() {
strokeWeight(1);
for (let x = 0; x < width; x++) {
let n = floor(random(0, 3));
let y = height * 0.7 * random();
for (let i = 0; i < n; i++) {
stroke(255, random(10, 200));
point(x, y);
}
}
}
}
function setup() {
createCanvas(500, 500);
background(0);
noFill();
frameRate(30); // Adjust the frame rate for animation
auroras.push(new Aurora(255, 0, 255, 150, 255)); // Purple
auroras.push(new Aurora(0, 255, 128, 50, 255)); // Green
stars.push(new Star());
}
function draw() {
// trailing effect.
background(0, 10);
for (let aurora of auroras) {
aurora.draw();
}
for (let star of stars) {
star.draw();
}
// Update the time variable for animation
t += 0.01;
}