voronoi-fracture-dreams-rzpi/index.html

185 lines
No EOL
5.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neurameba Generative Art</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
color: #333;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 20px;
right: 20px;
font-size: 10px;
color: #555;
pointer-events: none;
}
</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
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: 1.08
};
// Voronoi implementation
class VoronoiCell {
constructor(x, y, points, edges) {
this.x = x;
this.y = y;
this.points = points;
this.edges = edges;
this.age = 0;
this.energy = Math.random();
}
draw() {
if (Math.random() > params.connectedness) return;
ctx.beginPath();
ctx.moveTo(this.points[0].x, this.points[0].y);
for (let i = 1; i < this.points.length; i++) {
const p = this.points[i];
ctx.lineTo(p.x, p.y);
}
ctx.closePath();
const hue = this.energy * 360;
ctx.fillStyle = `hsl(${hue}, 0%, ${20 + this.energy * 30}%)`;
ctx.fill();
if (this.points.length > 3) {
ctx.strokeStyle = `rgba(255, 255, 255, ${0.1 + this.energy * 0.1})`;
ctx.lineWidth = 0.5 * this.energy;
ctx.stroke();
}
}
update() {
this.age++;
this.energy += params.pulse * 0.01;
this.energy = Math.min(1, this.energy);
}
}
class VoronoiSystem {
constructor() {
this.cells = [];
this.points = [];
this.voronoi = null;
this.lastTime = 0;
this.init();
}
init() {
const count = 50 + Math.floor(params.density * 100);
for (let i = 0; i < count; i++) {
this.points.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height
});
}
this.updateVoronoi();
}
updateVoronoi() {
this.cells = [];
// Simple Fortune's algorithm approximation
for (let i = 0; i < this.points.length; i++) {
const p1 = this.points[i];
const neighbors = [];
for (let j = 0; j < this.points.length; j++) {
if (i === j) continue;
const p2 = this.points[j];
const dx = p1.x - p2.x;
const dy = p1.y - p2.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 100 + params.complexity * 50) {
neighbors.push(p2);
}
}
if (neighbors.length >= 3) {
this.cells.push(new VoronoiCell(p1.x, p1.y, neighbors, []));
}
}
}
update(timestamp) {
const deltaTime = timestamp - this.lastTime;
this.lastTime = timestamp;
// Animate points
for (let i = 0; i < this.points.length; i++) {
const p = this.points[i];
p.x += Math.sin(timestamp * 0.001 * params.motion) * Math.random() * 2;
p.y += Math.cos(timestamp * 0.0015 * params.motion) * Math.random() * 2;
// Wrap around edges
if (p.x < 0) p.x = canvas.width;
if (p.x > canvas.width) p.x = 0;
if (p.y < 0) p.y = canvas.height;
if (p.y > canvas.height) p.y = 0;
}
this.updateVoronoi();
// Update and draw cells
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (const cell of this.cells) {
cell.update();
cell.draw();
}
}
}
// Initialize system
const system = new VoronoiSystem();
// Animation loop
function animate(timestamp) {
system.update(timestamp);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>