birth: Voronoi Pulsing Tissue
This commit is contained in:
parent
e1313f14bd
commit
d409ce4186
1 changed files with 248 additions and 0 deletions
248
index.html
Normal file
248
index.html
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Voronoi Organism</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #111;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
color: #888;
|
||||
font-size: 10px;
|
||||
text-shadow: 0 0 5px rgba(0,0,0,0.5);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="info">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 (derived from input)
|
||||
const params = {
|
||||
motion: 0.537,
|
||||
density: 0.533,
|
||||
complexity: 0.443,
|
||||
connectedness: 0.440,
|
||||
lifespan: 0.486,
|
||||
pulse: { avg: 0.58, min: 0.30, max: 1.45 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.60, dryness: 0.80, playfulness: 0.10, tension: 0.00 },
|
||||
topology: { nodes: 87, branches: 59, loops: 168, maxDepth: 19, thicknessRatio: 1.25, fractalDim: 1.616 },
|
||||
energy: 415.2
|
||||
};
|
||||
|
||||
// Color palette based on tone
|
||||
const color = {
|
||||
r: Math.floor(100 + params.tone.curiosity * 155),
|
||||
g: Math.floor(150 + params.tone.curiosity * 105),
|
||||
b: Math.floor(200 + params.tone.curiosity * 55),
|
||||
a: params.tone.dryness > 0.7 ? 0.8 : 0.5
|
||||
};
|
||||
|
||||
// Voronoi parameters
|
||||
const siteCount = Math.floor(87 * (0.5 + params.density * 0.5));
|
||||
const sites = [];
|
||||
const cells = [];
|
||||
const connections = [];
|
||||
let time = 0;
|
||||
|
||||
// Initialize sites
|
||||
function initSites() {
|
||||
sites.length = 0;
|
||||
for (let i = 0; i < siteCount; i++) {
|
||||
sites.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * params.motion * 2,
|
||||
vy: (Math.random() - 0.5) * params.motion * 2,
|
||||
size: 1 + Math.random() * 3 * (1 - params.complexity),
|
||||
pulse: params.pulse.min + (params.pulse.max - params.pulse.min) * params.pulse.avg
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initSites();
|
||||
|
||||
// Calculate Voronoi cells (simplified)
|
||||
function calculateCells() {
|
||||
cells.length = 0;
|
||||
|
||||
// Create a grid for faster neighbor checks
|
||||
const gridSize = 30;
|
||||
const grid = new Array(Math.ceil(canvas.width / gridSize) * Math.ceil(canvas.height / gridSize));
|
||||
|
||||
// Assign sites to grid
|
||||
for (let s = 0; s < sites.length; s++) {
|
||||
const site = sites[s];
|
||||
const gx = Math.floor(site.x / gridSize);
|
||||
const gy = Math.floor(site.y / gridSize);
|
||||
const index = gx + gy * Math.ceil(canvas.width / gridSize);
|
||||
if (!grid[index]) grid[index] = [];
|
||||
grid[index].push(s);
|
||||
}
|
||||
|
||||
// For each pixel, find nearest site
|
||||
for (let y = 0; y < canvas.height; y += 2) {
|
||||
for (let x = 0; x < canvas.width; x += 2) {
|
||||
let minDist = Infinity;
|
||||
let nearestSite = null;
|
||||
|
||||
// Check neighboring grid cells
|
||||
const startGx = Math.max(0, Math.floor(x / gridSize) - 1);
|
||||
const endGx = Math.min(Math.ceil(canvas.width / gridSize) - 1, Math.floor(x / gridSize) + 1);
|
||||
const startGy = Math.max(0, Math.floor(y / gridSize) - 1);
|
||||
const endGy = Math.min(Math.ceil(canvas.height / gridSize) - 1, Math.floor(y / gridSize) + 1);
|
||||
|
||||
for (let gy = startGy; gy <= endGy; gy++) {
|
||||
for (let gx = startGx; gx <= endGx; gx++) {
|
||||
const index = gx + gy * Math.ceil(canvas.width / gridSize);
|
||||
if (grid[index]) {
|
||||
for (const s of grid[index]) {
|
||||
const site = sites[s];
|
||||
const dx = x - site.x;
|
||||
const dy = y - site.y;
|
||||
const dist = dx * dx + dy * dy;
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
nearestSite = site;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nearestSite) {
|
||||
cells.push({
|
||||
x, y,
|
||||
color: {
|
||||
r: color.r,
|
||||
g: color.g,
|
||||
b: color.b,
|
||||
a: color.a * (1 - params.tone.dryness) * 0.7
|
||||
},
|
||||
site: nearestSite
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create connections based on connectedness
|
||||
function createConnections() {
|
||||
connections.length = 0;
|
||||
|
||||
if (params.connectedness < 0.3) return;
|
||||
|
||||
// Sort sites by proximity to create natural connections
|
||||
const sortedSites = [...sites].sort((a, b) => {
|
||||
const dx = a.x - b.x;
|
||||
const dy = a.y - b.y;
|
||||
return dx * dx + dy * dy;
|
||||
});
|
||||
|
||||
for (let i = 0; i < sortedSites.length; i++) {
|
||||
const a = sortedSites[i];
|
||||
for (let j = i + 1; j < Math.min(i + 5, sortedSites.length); j++) {
|
||||
if (Math.random() > params.connectedness) continue;
|
||||
|
||||
const b = sortedSites[j];
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (dist < 200 && dist > 50) {
|
||||
connections.push({
|
||||
from: a,
|
||||
to: b,
|
||||
strength: 0.5 + (params.connectedness * 0.5),
|
||||
width: 1 + params.thicknessRatio * 0.5
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animate sites
|
||||
function animateSites() {
|
||||
sites.forEach(site => {
|
||||
// Move 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;
|
||||
|
||||
// Pulse size
|
||||
site.size = 1 + Math.sin(time * 0.003) * 0.5;
|
||||
});
|
||||
}
|
||||
|
||||
function draw() {
|
||||
// Clear with semi-transparent background for motion trails
|
||||
ctx.fillStyle = `rgba(17, 17, 17, ${0.1 + params.tone.dryness * 0.2})`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw connections
|
||||
connections.forEach(conn => {
|
||||
const gradient = ctx.createLinearGradient(conn.from.x, conn.from.y, conn.to.x, conn.to.y);
|
||||
gradient.addColorStop(0, `rgba(${color.r}, ${color.g}, ${color.b}, ${conn.strength * 0.5})`);
|
||||
gradient.addColorStop(1, `rgba(${color.r}, ${color.g}, ${color.b}, 0)`);
|
||||
|
||||
ctx.strokeStyle = gradient;
|
||||
ctx.lineWidth = conn.width;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(conn.from.x, conn.from.y);
|
||||
ctx.lineTo(conn.to.x, conn.to.y);
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
// Draw cells
|
||||
ctx.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`;
|
||||
cells.forEach(cell => {
|
||||
ctx.fillRect(cell.x, cell.y, 2, 2);
|
||||
});
|
||||
|
||||
// Draw sites
|
||||
sites.forEach(site => {
|
||||
ctx.beginPath();
|
||||
ctx.arc(site.x, site.y, site.size * 2, 0, Math.PI * 2);
|
||||
ctx.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a * 0.7})`;
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
time += 1;
|
||||
}
|
||||
|
||||
function animate() {
|
||||
animateSites();
|
||||
calculateCells();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue