birth: Voronoi Pulse in Silence
This commit is contained in:
parent
493b8bcc76
commit
c13bf71509
1 changed files with 184 additions and 0 deletions
184
index.html
Normal file
184
index.html
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Organism</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
font-family: monospace;
|
||||
color: #fff;
|
||||
pointer-events: none;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
.attribution {
|
||||
text-align: right;
|
||||
padding: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div class="attribution">neurameba · motd.social</div>
|
||||
|
||||
<script>
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Set canvas to full window size
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Organism parameters
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.12, min: 1.05, max: 1.20 }
|
||||
};
|
||||
|
||||
// Tone parameters
|
||||
const tone = {
|
||||
curiosity: 0.5,
|
||||
dryness: 0.8,
|
||||
playfulness: 0.2
|
||||
};
|
||||
|
||||
// Voronoi state
|
||||
const sites = [];
|
||||
const cells = [];
|
||||
const maxSites = 100;
|
||||
const siteSpeed = 0.5;
|
||||
const siteRadius = 1;
|
||||
|
||||
// Initialize sites
|
||||
function initSites() {
|
||||
sites.length = 0;
|
||||
for (let i = 0; i < maxSites * params.density; i++) {
|
||||
sites.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * siteSpeed * params.motion,
|
||||
vy: (Math.random() - 0.5) * siteSpeed * params.motion,
|
||||
lifespan: params.lifespan
|
||||
});
|
||||
}
|
||||
}
|
||||
initSites();
|
||||
|
||||
// Voronoi diagram calculation
|
||||
function computeVoronoi() {
|
||||
cells.length = 0;
|
||||
|
||||
for (const site of sites) {
|
||||
const neighbors = [];
|
||||
const radius = siteRadius + (Math.random() * 20 * params.complexity);
|
||||
|
||||
// Find neighbors within connection radius
|
||||
for (const other of sites) {
|
||||
if (other === site) continue;
|
||||
|
||||
const dx = other.x - site.x;
|
||||
const dy = other.y - site.y;
|
||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (distance < radius) {
|
||||
neighbors.push(other);
|
||||
}
|
||||
}
|
||||
|
||||
cells.push({
|
||||
site: site,
|
||||
neighbors: neighbors,
|
||||
radius: radius,
|
||||
age: 0,
|
||||
maxAge: 100 + Math.random() * 1000 * params.lifespan,
|
||||
color: getCellColor(site)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getCellColor(site) {
|
||||
const hue = 180 + (Math.random() * 60);
|
||||
const saturation = 30 + (Math.random() * 40);
|
||||
const lightness = 40 + (Math.random() * 30);
|
||||
|
||||
// Adjust based on tone parameters
|
||||
const saturate = tone.dryness < 0.5 ? saturation : saturation * (1 - tone.dryness);
|
||||
const light = tone.playfulness > 0.5 ? lightness + 20 : lightness;
|
||||
|
||||
return `hsl(${hue}, ${saturate}%, ${light}%)`;
|
||||
}
|
||||
|
||||
// Update sites
|
||||
function updateSites() {
|
||||
for (const site of sites) {
|
||||
site.x += site.vx;
|
||||
site.y += site.vy;
|
||||
|
||||
// Bounce off edges
|
||||
if (site.x < 0 || site.x > canvas.width) site.vx *= -1;
|
||||
if (site.y < 0 || site.y > canvas.height) site.vy *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw voronoi cells
|
||||
function drawCells() {
|
||||
for (const cell of cells) {
|
||||
// Draw cell outline
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = cell.color;
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
// Draw connections to neighbors
|
||||
for (const neighbor of cell.neighbors) {
|
||||
ctx.moveTo(cell.site.x, cell.site.y);
|
||||
ctx.lineTo(neighbor.x, neighbor.y);
|
||||
}
|
||||
|
||||
ctx.stroke();
|
||||
|
||||
// Draw site
|
||||
ctx.beginPath();
|
||||
ctx.arc(cell.site.x, cell.site.y, 2, 0, Math.PI * 2);
|
||||
ctx.fillStyle = cell.color;
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
// Clear with slightly transparent background for trails
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw
|
||||
computeVoronoi();
|
||||
updateSites();
|
||||
drawCells();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Start animation
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue