186 lines
No EOL
6.3 KiB
HTML
186 lines
No EOL
6.3 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 Dreams</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #444;
|
|
font-size: 10px;
|
|
text-align: right;
|
|
}
|
|
</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 resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
// Parameters from abstract input
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.08, min: 1.05, max: 1.10 },
|
|
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.8, playfulness: 0, tension: 0 }
|
|
};
|
|
|
|
// Color palette based on tone
|
|
const hue = 180 + 30 * params.tone.curiosity; // Teal-ish
|
|
const saturation = 20 + 10 * params.tone.playfulness;
|
|
const brightness = 80 - 20 * params.tone.dryness;
|
|
|
|
// Voronoi cell count based on density
|
|
const cellCount = Math.floor(50 + 200 * params.density * params.complexity);
|
|
|
|
// Voronoi points with some motion
|
|
const points = [];
|
|
const velocities = [];
|
|
|
|
function initPoints() {
|
|
for (let i = 0; i < cellCount; i++) {
|
|
points.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height
|
|
});
|
|
velocities.push({
|
|
x: (Math.random() - 0.5) * params.motion,
|
|
y: (Math.random() - 0.5) * params.motion
|
|
});
|
|
}
|
|
}
|
|
|
|
initPoints();
|
|
|
|
// Voronoi diagram implementation (simplified)
|
|
function drawVoronoi() {
|
|
// Clear with slight fade for lifespan effect
|
|
ctx.fillStyle = `rgba(0, 0, 0, ${1 - params.lifespan * 0.5})`;
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Calculate distances for each pixel
|
|
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 closestIndex = 0;
|
|
|
|
for (let i = 0; i < points.length; i++) {
|
|
const dx = x - points[i].x;
|
|
const dy = y - points[i].y;
|
|
const dist = dx * dx + dy * dy;
|
|
|
|
if (dist < minDist) {
|
|
minDist = dist;
|
|
closestIndex = i;
|
|
}
|
|
}
|
|
|
|
// Color based on point
|
|
const colorValue = 30 + 20 * Math.sin(closestIndex) + Math.random() * 20;
|
|
const idx = (y * canvas.width + x) * 4;
|
|
|
|
if (params.tone.dryness > 0.7) {
|
|
// Monochrome with some variation
|
|
const gray = Math.min(255, colorValue);
|
|
data[idx] = gray;
|
|
data[idx + 1] = gray;
|
|
data[idx + 2] = gray;
|
|
} else {
|
|
// Colored version
|
|
data[idx] = Math.min(255, colorValue * 0.8);
|
|
data[idx + 1] = Math.min(255, colorValue);
|
|
data[idx + 2] = Math.min(255, colorValue * 1.2);
|
|
}
|
|
data[idx + 3] = 255;
|
|
}
|
|
}
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
|
|
// Draw some connecting lines for connectedness
|
|
if (params.connectedness > 0.3) {
|
|
ctx.strokeStyle = `hsl(${hue}, ${saturation}%, ${brightness}%)`;
|
|
ctx.lineWidth = 0.5 + params.complexity * 0.5;
|
|
ctx.beginPath();
|
|
|
|
for (let i = 0; i < points.length; i++) {
|
|
const neighbors = [];
|
|
for (let j = 0; j < points.length; j++) {
|
|
if (i !== j) {
|
|
const dx = points[i].x - points[j].x;
|
|
const dy = points[i].y - points[j].y;
|
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
if (dist < 150 * params.connectedness) {
|
|
neighbors.push(j);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (neighbors.length > 0) {
|
|
const start = points[i];
|
|
ctx.moveTo(start.x, start.y);
|
|
for (const j of neighbors) {
|
|
const end = points[j];
|
|
ctx.lineTo(end.x, end.y);
|
|
}
|
|
}
|
|
}
|
|
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
let time = 0;
|
|
function animate() {
|
|
time += 0.01;
|
|
|
|
// Update points with some pulse variation
|
|
const pulse = params.pulse.avg + (Math.random() * 2 - 1) * (params.pulse.max - params.pulse.min) * 0.5;
|
|
for (let i = 0; i < points.length; i++) {
|
|
points[i].x += velocities[i].x * pulse;
|
|
points[i].y += velocities[i].y * pulse;
|
|
|
|
// Bounce off edges
|
|
if (points[i].x < 0 || points[i].x > canvas.width) velocities[i].x *= -1;
|
|
if (points[i].y < 0 || points[i].y > canvas.height) velocities[i].y *= -1;
|
|
}
|
|
|
|
drawVoronoi();
|
|
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |