xxxxxxxxxx
72
let amplitude;
let amplitudeMin = 10;
let amplitudeMax = 200;
let period;
let periodMin = 40;
let periodMax = 300;
let shiftX;
let shiftY;
let dotRadiusMin = 2.5;
let dotRadiusMax = 7.5;
let powerBase = 1.6;
let allDots;
function setup()
{
createCanvas(400, 400);
fill(40);
Begin();
}
function keyPressed()
{
if (keyCode === 32)
Begin();
}
function draw()
{
if (allDots == undefined)
return;
if (mouseX >= width || mouseY >= height)
return;
if (allDots[mouseX][mouseY] === true)
return;
allDots[mouseX][mouseY] = true;
let sine = amplitude * sin((mouseX + shiftX) * TAU / period) + shiftY;
let distance = abs(mouseY - sine);
let alpha = pow(powerBase, -distance);
stroke(alpha * 250, alpha * 180, alpha * 50);
strokeWeight( (dotRadiusMax - dotRadiusMin) * Math.random() + dotRadiusMin);
point(mouseX, mouseY);
}
function Begin()
{
blendMode(BLEND);
background(40);
blendMode(ADD);
allDots = [];
for (let i = 0; i < width; ++i)
{
allDots[i] = [];
for (let j = 0; j < height; ++j)
{
allDots[i][j] = false;
}
}
amplitude = (amplitudeMax - amplitudeMin) * Math.random() + amplitudeMin;
period = (periodMax - periodMin) * Math.random() + periodMin;
shiftX = Math.random() * period;
shiftY = Math.random() * height;
}