xxxxxxxxxx
63
let moonSize = 100;
let moonColor;
let moonParticles = [];
function setup() {
createCanvas(400, 200);
moonColor = color("white");
//change the number to add more particles
for (let i = 0; i < 10000; i++) {
let x = random(width);
let y = random(height);
moonParticles.push({ x: x, y: y });
}
}
function draw() {
background("black");
let newSize = map(mouseY, 0, height, 50, 200);
moonSize = lerp(moonSize, newSize, 0.1);
let particleSize = map(mouseX, 0, width, 0.5, 2);
drawMoonParticles(particleSize);
drawLogo();
}
function drawMoonParticles(particleSize) {
noStroke();
for (let i = 0; i < moonParticles.length; i++) {
let d = dist(moonParticles[i].x, moonParticles[i].y, width / 2, height / 2);
let density = map(d, 0, moonSize / 2, 1, 10);
if (random(1) < density / 10) {
if (d < moonSize / 2) {
fill(255, 100);
ellipse(moonParticles[i].x, moonParticles[i].y, particleSize + 0.5);
ellipse(moonParticles[i].x, moonParticles[i].y, particleSize);
}
}
}
}
function drawLogo() {
textSize(13);
fill(255);
text("The Moon", 130, 140);
textSize(24);
textFont("Futura");
textStyle("BOLD");
fill(255);
text("Museum", 100, 160);
}
function keyPressed() {
if (key === "s" || key === "s") {
saveCanvas("moon_museum_black", "png");
}
}