birth: Fractal Haze in Motion
This commit is contained in:
parent
035e17b1e3
commit
9daa955338
1 changed files with 159 additions and 0 deletions
159
index.html
Normal file
159
index.html
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Fractal Haze</title>
|
||||
<style>
|
||||
body { margin: 0; overflow: hidden; background: #000; }
|
||||
canvas { display: block; }
|
||||
.credit { position: fixed; bottom: 10px; right: 10px; color: #333; font-family: monospace; font-size: 10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div class="credit">neurameba · motd.social</div>
|
||||
<script>
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
function resize() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resize);
|
||||
resize();
|
||||
|
||||
// System parameters
|
||||
const params = {
|
||||
motion: 0.451,
|
||||
density: 0.495,
|
||||
complexity: 0.507,
|
||||
connectedness: 0.470,
|
||||
lifespan: 0.548,
|
||||
loops: 886,
|
||||
maxDepth: 30,
|
||||
thicknessRatio: 1.50,
|
||||
fractalDim: 1.161,
|
||||
pulse: { avg: 0.45, min: 0.30, max: 2.00 },
|
||||
survivors: 130,
|
||||
branches: 108
|
||||
};
|
||||
|
||||
// Cellular automaton grid
|
||||
const cols = Math.floor(params.density * 60) + 10;
|
||||
const rows = Math.floor(params.density * 40) + 10;
|
||||
let grid = Array(rows).fill().map(() => Array(cols).fill(0));
|
||||
let nextGrid = Array(rows).fill().map(() => Array(cols).fill(0));
|
||||
|
||||
// Set initial state based on complexity
|
||||
function initGrid() {
|
||||
const initialDensity = params.complexity * 0.7 + 0.1;
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
grid[y][x] = (Math.random() < initialDensity) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initGrid();
|
||||
|
||||
// Game of Life rules with modifications
|
||||
function updateGrid() {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
let neighbors = countNeighbors(x, y);
|
||||
|
||||
if (grid[y][x] === 1) {
|
||||
// Survival depends on connectedness and motion
|
||||
const survivalChance = 0.6 - params.connectedness * 0.3 + params.motion * 0.1;
|
||||
nextGrid[y][x] = (Math.random() < survivalChance) ? 1 : 0;
|
||||
} else {
|
||||
// Birth depends on complexity
|
||||
const birthChance = params.complexity * 0.4;
|
||||
nextGrid[y][x] = (Math.random() < birthChance) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Swap grids
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
|
||||
// Add some random changes based on pulse
|
||||
if (Math.random() < params.pulse.avg) {
|
||||
const x = Math.floor(Math.random() * cols);
|
||||
const y = Math.floor(Math.random() * rows);
|
||||
if (Math.random() < 0.3) {
|
||||
grid[y][x] = 1;
|
||||
} else {
|
||||
grid[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
const ny = y + dy;
|
||||
if (nx >= 0 && nx < cols && ny >= 0 && ny < rows) {
|
||||
count += grid[ny][nx];
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Drawing parameters
|
||||
const cellSize = Math.max(1, Math.floor(20 * params.density));
|
||||
const pulseScl = params.pulse.avg * 3 + 0.5;
|
||||
|
||||
function draw() {
|
||||
// Draw background
|
||||
ctx.fillStyle = `rgba(10, 10, 20, ${0.1 + params.motion * 0.05})`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw grid
|
||||
const centerX = canvas.width / 2;
|
||||
const centerY = canvas.height / 2;
|
||||
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
if (grid[y][x] === 1) {
|
||||
// Calculate position with some organic movement
|
||||
const targetX = centerX + (x - cols/2) * cellSize * 1.5;
|
||||
const targetY = centerY + (y - rows/2) * cellSize * 1.5;
|
||||
|
||||
// Add pulse effect
|
||||
const pulse = 1 + Math.sin(Date.now() * 0.001 * (1 + (x + y) * 0.01)) * params.pulse.avg * 0.3;
|
||||
const size = cellSize * pulse * pulseScl;
|
||||
|
||||
// Draw cell with varying opacity based on lifespan
|
||||
const lifeAlpha = 0.3 + params.lifespan * 0.7;
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${lifeAlpha})`;
|
||||
|
||||
const dx = targetX + (Math.random() - 0.5) * 2 * params.motion;
|
||||
const dy = targetY + (Math.random() - 0.5) * 2 * params.motion;
|
||||
|
||||
const cornerSize = size * (0.5 + Math.random() * 0.5);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(dx - cornerSize, dy - cornerSize);
|
||||
ctx.lineTo(dx + cornerSize, dy - cornerSize);
|
||||
ctx.lineTo(dx + cornerSize, dy + cornerSize);
|
||||
ctx.lineTo(dx - cornerSize, dy + cornerSize);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update grid
|
||||
updateGrid();
|
||||
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
|
||||
draw();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue