birth: Static Pulse of the Grid
This commit is contained in:
parent
fbf3350ab0
commit
30953e4dd3
1 changed files with 156 additions and 0 deletions
156
index.html
Normal file
156
index.html
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<!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 Sketch</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: rgba(255, 255, 255, 0.3);
|
||||
font-size: 10px;
|
||||
text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
padding: 2px 5px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</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 adjusted from input
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
tone: { dryness: 0.8, curiosity: 0.1 },
|
||||
pulse: { avg: 1.06, min: 0.9, max: 1.2 }
|
||||
};
|
||||
|
||||
// Cellular Automata setup
|
||||
const cols = Math.floor(params.density * 20) + 5;
|
||||
const rows = Math.floor(params.density * 20) + 5;
|
||||
const cellSize = Math.max(2, Math.min(20, 15 - params.density * 10));
|
||||
const grid = Array(rows).fill().map(() => Array(cols).fill(0));
|
||||
|
||||
// Initialize grid
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
grid[y][x] = Math.random() > (1 - params.density) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Ruleset (Wolfram-like with some modifications)
|
||||
function applyRules(a, b, c) {
|
||||
const sum = a + b + c;
|
||||
if (a === 1 && b === 0 && c === 0) return 1;
|
||||
if (a === 1 && b === 1 && c === 0) return 0;
|
||||
if (a === 0 && b === 1 && c === 1) return 0;
|
||||
if (sum >= 2) return 1;
|
||||
if (params.complexity > 0.7 && Math.random() < params.complexity * 0.1) {
|
||||
return Math.random() > 0.5 ? 1 : 0;
|
||||
}
|
||||
return sum === 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
// Colors
|
||||
const baseHue = params.tone.dryness > 0.7 ? 0 : 180; // monochrome vs teal
|
||||
const hueVariation = params.tone.curiosity * 30;
|
||||
|
||||
function getColor(value, x, y, time) {
|
||||
const pulse = params.pulse.avg + Math.sin(time * 0.001 * params.pulse.min) * 0.05;
|
||||
const brightness = 0.3 + value * (0.7 + Math.sin(time * 0.002) * 0.1) * pulse;
|
||||
const hue = baseHue + hueVariation * Math.sin(x * 0.1 + time * 0.001);
|
||||
return `hsl(${hue}, 10%, ${brightness * 100}%)`;
|
||||
}
|
||||
|
||||
// Drawing
|
||||
let time = 0;
|
||||
|
||||
function draw() {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const cellWidth = cellSize;
|
||||
const cellHeight = cellSize;
|
||||
const offsetX = (canvas.width - cols * cellWidth) / 2;
|
||||
const offsetY = (canvas.height - rows * cellHeight) / 2;
|
||||
|
||||
// Update and draw
|
||||
const newGrid = Array(rows).fill().map(() => Array(cols).fill(0));
|
||||
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const neighbors = [
|
||||
grid[(y - 1 + rows) % rows][(x - 1 + cols) % cols],
|
||||
grid[(y - 1 + rows) % rows][x],
|
||||
grid[(y - 1 + rows) % rows][(x + 1) % cols],
|
||||
grid[y][(x - 1 + cols) % cols],
|
||||
grid[y][(x + 1) % cols],
|
||||
grid[(y + 1) % rows][(x - 1 + cols) % cols],
|
||||
grid[(y + 1) % rows][x],
|
||||
grid[(y + 1) % rows][(x + 1) % cols]
|
||||
];
|
||||
|
||||
const sum = neighbors.reduce((a, b) => a + b, 0);
|
||||
const ruleResult = applyRules(grid[y][(x - 1 + cols) % cols], grid[y][x], grid[y][(x + 1) % cols]);
|
||||
|
||||
// Update state
|
||||
newGrid[y][x] = ruleResult;
|
||||
|
||||
// Draw
|
||||
if (ruleResult) {
|
||||
const size = cellSize * (0.3 + 0.7 * (sum / 8));
|
||||
const color = getColor(1, x, y, time);
|
||||
ctx.fillStyle = color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
offsetX + x * cellWidth + cellWidth/2,
|
||||
offsetY + y * cellHeight + cellHeight/2,
|
||||
size * 0.5,
|
||||
0, Math.PI * 2
|
||||
);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grid.length = 0;
|
||||
for (let y = 0; y < rows; y++) {
|
||||
grid.push([...newGrid[y]]);
|
||||
}
|
||||
|
||||
time++;
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
|
||||
draw();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue