birth: Fractured Echo Chamber
This commit is contained in:
parent
62026bc970
commit
11f7f9e51d
1 changed files with 234 additions and 0 deletions
234
index.html
Normal file
234
index.html
Normal file
|
|
@ -0,0 +1,234 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>neurameba · motd.social cellular automata</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0a0a;
|
||||||
|
color: #f0f0f0;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
#info {
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
text-align: right;
|
||||||
|
background: rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="c"></canvas>
|
||||||
|
<div id="info">neurameba · motd.social</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const canvas = document.getElementById('c');
|
||||||
|
const c = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// Resize canvas
|
||||||
|
function resize() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', resize);
|
||||||
|
resize();
|
||||||
|
|
||||||
|
// Configuration from parameters
|
||||||
|
const config = {
|
||||||
|
motion: 0.545,
|
||||||
|
density: 0.487,
|
||||||
|
complexity: 0.459,
|
||||||
|
connectedness: 0.544,
|
||||||
|
lifespan: 0.496,
|
||||||
|
pulse: {
|
||||||
|
avg: 0.42,
|
||||||
|
min: 0.30,
|
||||||
|
max: 1.80
|
||||||
|
},
|
||||||
|
tone: {
|
||||||
|
anger: 0.00,
|
||||||
|
sadness: 0.00,
|
||||||
|
curiosity: 0.20,
|
||||||
|
dryness: 0.90,
|
||||||
|
playfulness: 0.10,
|
||||||
|
tension: 0.00
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cellular automata grid
|
||||||
|
const gridSize = 32;
|
||||||
|
const cellSize = Math.max(2, Math.floor(Math.min(canvas.width, canvas.height) / gridSize / 2));
|
||||||
|
const cols = Math.floor(canvas.width / cellSize);
|
||||||
|
const rows = Math.floor(canvas.height / cellSize);
|
||||||
|
|
||||||
|
// Initialize grid
|
||||||
|
let grid = Array(rows).fill().map(() =>
|
||||||
|
Array(cols).fill().map(() =>
|
||||||
|
Math.random() < config.density * 0.3 ? 1 : 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// State for cellular automata
|
||||||
|
let currentState = grid;
|
||||||
|
let nextState = Array(rows).fill().map(() => Array(cols).fill(0));
|
||||||
|
let generations = 0;
|
||||||
|
|
||||||
|
// Rule set based on parameters
|
||||||
|
const birthRules = [3];
|
||||||
|
const survivalRules = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
// Cellular automata update
|
||||||
|
function update() {
|
||||||
|
// Smooth pulse effect
|
||||||
|
const pulse = config.pulse.avg + (config.pulse.max - config.pulse.min) *
|
||||||
|
Math.sin(Date.now() * 0.001 * config.motion) * 0.5;
|
||||||
|
const densityFactor = config.density * pulse * 0.7;
|
||||||
|
|
||||||
|
// Reset next state
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
nextState[y][x] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cellular automata rules
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
const neighbors = countNeighbors(x, y);
|
||||||
|
|
||||||
|
if (currentState[y][x] === 1) {
|
||||||
|
// Survival rule
|
||||||
|
if (survivalRules.includes(neighbors)) {
|
||||||
|
nextState[y][x] = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Birth rule
|
||||||
|
if (birthRules.includes(neighbors)) {
|
||||||
|
nextState[y][x] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap buffers
|
||||||
|
[currentState, nextState] = [nextState, currentState];
|
||||||
|
|
||||||
|
// Occasionally add new cells based on density
|
||||||
|
if (Math.random() < densityFactor * 0.05) {
|
||||||
|
const x = Math.floor(Math.random() * cols);
|
||||||
|
const y = Math.floor(Math.random() * rows);
|
||||||
|
currentState[y][x] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
generations++;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countNeighbors(x, y) {
|
||||||
|
let count = 0;
|
||||||
|
for (let dy = -1; dy <= 1; dy++) {
|
||||||
|
for (let dx = -1; dx <= 1; dx++) {
|
||||||
|
if (dx === 0 && dy === 0) continue;
|
||||||
|
const nx = (x + dx + cols) % cols;
|
||||||
|
const ny = (y + dy + rows) % rows;
|
||||||
|
count += currentState[ny][nx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drawing
|
||||||
|
function draw() {
|
||||||
|
// Dark background (already set in CSS)
|
||||||
|
c.fillStyle = '#0a0a0a';
|
||||||
|
c.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Cellular automata cells
|
||||||
|
const spacing = cellSize * 1.5;
|
||||||
|
const alpha = config.dryness > 0.5 ? 0.8 : 0.9;
|
||||||
|
|
||||||
|
// Monochrome palette for dryness
|
||||||
|
const baseHue = 0; // Red for anger (though angry=0)
|
||||||
|
const saturation = config.dryness > 0.5 ? 0 : 0;
|
||||||
|
const lightness = 80 + Math.sin(Date.now() * 0.0005) * 10;
|
||||||
|
|
||||||
|
for (let y = 0; y < rows; y++) {
|
||||||
|
for (let x = 0; x < cols; x++) {
|
||||||
|
if (currentState[y][x] === 1) {
|
||||||
|
const hue = baseHue;
|
||||||
|
const sat = saturation + Math.random() * 0.1;
|
||||||
|
const lum = lightness + Math.random() * 10;
|
||||||
|
|
||||||
|
c.fillStyle = `hsla(${hue}, ${sat}%, ${lum}%, ${alpha})`;
|
||||||
|
c.fillRect(
|
||||||
|
x * spacing - cellSize/2 + Math.sin(Date.now() * 0.001 * config.motion + x * 0.1) * 2,
|
||||||
|
y * spacing - cellSize/2 + Math.cos(Date.now() * 0.001 * config.motion + y * 0.1) * 2,
|
||||||
|
cellSize, cellSize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add some connectedness with lines
|
||||||
|
if (config.connectedness > 0.3) {
|
||||||
|
const lineAlpha = config.connectedness * 0.7 * alpha;
|
||||||
|
c.strokeStyle = `hsla(${baseHue}, ${saturation}%, ${lightness + 20}%, ${lineAlpha})`;
|
||||||
|
c.lineWidth = config.connectedness * 0.5;
|
||||||
|
|
||||||
|
for (let y = 0; y < rows; y += Math.max(1, Math.floor(8 / config.density))) {
|
||||||
|
for (let x = 0; x < cols; x += Math.max(1, Math.floor(8 / config.density))) {
|
||||||
|
if (currentState[y][x] === 1) {
|
||||||
|
const neighbors = [];
|
||||||
|
for (let dy = -1; dy <= 1; dy++) {
|
||||||
|
for (let dx = -1; dx <= 1; dx++) {
|
||||||
|
if (dx === 0 && dy === 0) continue;
|
||||||
|
const nx = (x + dx + cols) % cols;
|
||||||
|
const ny = (y + dy + rows) % rows;
|
||||||
|
if (currentState[ny][nx] === 1) {
|
||||||
|
neighbors.push([nx, ny]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw lines to nearby neighbors
|
||||||
|
for (let i = 0; i < Math.min(2, neighbors.length); i++) {
|
||||||
|
const [nx, ny] = neighbors[i];
|
||||||
|
const dist = Math.sqrt(Math.pow(nx - x, 2) + Math.pow(ny - y, 2));
|
||||||
|
if (dist < 8) {
|
||||||
|
c.beginPath();
|
||||||
|
c.moveTo(
|
||||||
|
x * spacing + Math.sin(Date.now() * 0.001 * config.motion + x * 0.1) * 2,
|
||||||
|
y * spacing + Math.cos(Date.now() * 0.001 * config.motion + y * 0.1) * 2
|
||||||
|
);
|
||||||
|
c.lineTo(
|
||||||
|
nx * spacing + Math.sin(Date.now() * 0.001 * config.motion + nx * 0.1) * 2,
|
||||||
|
ny * spacing + Math.cos(Date.now() * 0.001 * config.motion + ny * 0.1) * 2
|
||||||
|
);
|
||||||
|
c.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Animation loop
|
||||||
|
function animate() {
|
||||||
|
update();
|
||||||
|
draw();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue