voronoi-pulse-fields-lrkw/index.html

220 lines
No EOL
7.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voronoi Bloom</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
color: #444;
font-size: 10px;
text-shadow: 0 0 2px #000;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="attribution">neurameba · motd.social</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function resize() {
canvas.width = innerWidth;
canvas.height = innerHeight;
}
window.addEventListener('resize', resize);
resize();
// Parameters derived from input
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.25, min: 1.0, max: 1.55 },
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.9, playfulness: 0, tension: 0 }
};
// Color palette (dryness-focused)
const palette = {
bg: '#0a0a0a',
primary: '#d0d0d0',
secondary: '#a0a0a0',
highlight: '#ffffff'
};
// Voronoi state
const sites = [];
const cells = [];
let time = 0;
// Initialize
function init() {
// Generate initial sites
const count = Math.floor(50 + params.density * 200);
for (let i = 0; i < count; i++) {
sites.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: 2 + Math.random() * 4,
speed: 0.1 + Math.random() * 0.5,
angle: Math.random() * Math.PI * 2,
life: 0,
maxLife: 50 + Math.random() * 100
});
}
}
init();
// Update positions with pulse-based motion
function update() {
const pulse = params.pulse.avg + Math.sin(time * 0.001) * (params.pulse.max - params.pulse.avg) * 0.3;
time += 1 * (pulse + 0.2); // Motion multiplier
// Update sites
sites.forEach(site => {
site.x += Math.cos(site.angle) * site.speed * (0.5 + 0.5 * params.motion);
site.y += Math.sin(site.angle) * site.speed * (0.5 + 0.5 * params.motion);
// Boundary reflection
if (site.x < 0 || site.x > canvas.width) site.angle = Math.PI - site.angle;
if (site.y < 0 || site.y > canvas.height) site.angle = -site.angle;
// Life cycle
site.life += 1;
if (site.life > site.maxLife) {
// Respawn with new parameters
site.x = Math.random() * canvas.width;
site.y = Math.random() * canvas.height;
site.size = 2 + Math.random() * 4;
site.speed = 0.1 + Math.random() * 0.5;
site.angle = Math.random() * Math.PI * 2;
site.life = 0;
site.maxLife = 50 + Math.random() * 100;
}
});
}
// Compute Voronoi diagram (simplified)
function computeVoronoi() {
cells.length = 0; // Clear previous cells
// For each pixel, find closest site
const imageData = ctx.createImageData(canvas.width, canvas.height);
const data = imageData.data;
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
let minDist = Infinity;
let closestSite = null;
// Find closest site
sites.forEach(site => {
const dx = x - site.x;
const dy = y - site.y;
const dist = dx * dx + dy * dy;
if (dist < minDist) {
minDist = dist;
closestSite = site;
}
});
// Color based on distance
const distNorm = Math.min(1, Math.sqrt(minDist) / 100);
const gray = 30 + 120 * (1 - distNorm * params.complexity);
const idx = (y * canvas.width + x) * 4;
data[idx] = gray;
data[idx + 1] = gray;
data[idx + 2] = gray;
data[idx + 3] = 255 - gray * 0.5;
}
}
// Apply cellular patterns based on complexity
if (params.complexity > 0.3) {
for (let i = 0; i < data.length; i += 4) {
if (Math.random() < params.complexity * 0.01) {
data[i] = data[i + 1] = data[i + 2] = 255 * (0.5 + 0.5 * Math.sin(time * 0.01));
}
}
}
ctx.putImageData(imageData, 0, 0);
}
// Draw connections (connectedness)
function drawConnections() {
if (params.connectedness < 0.3) return;
ctx.strokeStyle = `rgba(255, 255, 255, ${params.connectedness * 0.3})`;
ctx.lineWidth = 1;
sites.forEach(site => {
const nearby = sites.filter(other =>
Math.sqrt((other.x - site.x)**2 + (other.y - site.y)**2) < 100 * params.connectedness
);
nearby.forEach(other => {
if (site !== other) {
ctx.beginPath();
ctx.moveTo(site.x, site.y);
ctx.lineTo(other.x, other.y);
ctx.stroke();
}
});
});
}
// Draw sites
function drawSites() {
sites.forEach(site => {
const pulseEffect = 1 + 0.3 * Math.sin(time * 0.002 + site.x * 0.01) * params.pulse.avg;
const size = site.size * (0.8 + 0.2 * pulseEffect);
ctx.fillStyle = palette.secondary;
ctx.beginPath();
ctx.arc(site.x, site.y, size * 1.3, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = palette.primary;
ctx.beginPath();
ctx.arc(site.x, site.y, size, 0, Math.PI * 2);
ctx.fill();
});
}
// Animation loop
function animate() {
ctx.fillStyle = palette.bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
update();
computeVoronoi();
drawConnections();
drawSites();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>