birth: Reactive Fractures Emerging
This commit is contained in:
parent
3cb9f87495
commit
5c326d64d2
1 changed files with 168 additions and 0 deletions
168
index.html
Normal file
168
index.html
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Diffusive Dissonance</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #ddd;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
canvas {
|
||||
flex: 1;
|
||||
}
|
||||
.attribution {
|
||||
text-align: right;
|
||||
padding: 8px 16px;
|
||||
font-size: 10px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</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');
|
||||
|
||||
// Full viewport canvas
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters derived from abstract inputs
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.08, min: 1.05, max: 1.10 },
|
||||
tone: { anger: 0, sadness: 0, curiosity: 0.2, dryness: 0.8, playfulness: 0, tension: 0 }
|
||||
};
|
||||
|
||||
// Palette based on tone
|
||||
function getColor() {
|
||||
const dry = params.tone.dryness;
|
||||
if (dry > 0.7) {
|
||||
// Monochrome with slight variation
|
||||
const gray = 50 + Math.floor(Math.random() * 50);
|
||||
return `rgb(${gray}, ${gray}, ${gray})`;
|
||||
} else if (params.tone.curiosity > 0.5) {
|
||||
const teal = 100 + Math.floor(Math.random() * 100);
|
||||
return `rgb(0, ${teal}, ${teal * 1.2})`;
|
||||
}
|
||||
return 'rgb(50, 50, 50)';
|
||||
}
|
||||
|
||||
// Reaction-diffusion grid
|
||||
const GRID_SIZE = 80;
|
||||
const CELL_SIZE = Math.max(2, Math.floor(Math.min(
|
||||
window.innerWidth / GRID_SIZE,
|
||||
window.innerHeight / GRID_SIZE
|
||||
)));
|
||||
|
||||
const cols = Math.floor(window.innerWidth / CELL_SIZE);
|
||||
const rows = Math.floor(window.innerHeight / CELL_SIZE);
|
||||
|
||||
let grid = new Array(cols * rows);
|
||||
let nextGrid = new Array(cols * rows);
|
||||
|
||||
// Initialize with sparse patterns
|
||||
for (let i = 0; i < grid.length; i++) {
|
||||
grid[i] = (Math.random() < 0.2) ? 1 : 0;
|
||||
nextGrid[i] = 0;
|
||||
}
|
||||
|
||||
// Reaction-diffusion rules (Gray-Scott)
|
||||
const DA = 1.0;
|
||||
const DB = 0.5;
|
||||
const feed = 0.055;
|
||||
const kill = 0.062;
|
||||
|
||||
function updateGrid() {
|
||||
for (let x = 1; x < cols - 1; x++) {
|
||||
for (let y = 1; y < rows - 1; y++) {
|
||||
const idx = x + y * cols;
|
||||
|
||||
let a = grid[idx];
|
||||
let b = nextGrid[idx];
|
||||
|
||||
// Apply reaction
|
||||
const ab2 = a * b * b;
|
||||
const reaction = ab2 - (feed + kill) * b;
|
||||
|
||||
nextGrid[idx] = b + (DA * (grid[idx - 1] + grid[idx + 1] +
|
||||
grid[idx - cols] + grid[idx + cols] - 4 * b) -
|
||||
reaction) * params.pulse.avg;
|
||||
}
|
||||
}
|
||||
|
||||
// Swap buffers
|
||||
[grid, nextGrid] = [nextGrid, grid];
|
||||
}
|
||||
|
||||
function drawGrid() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
for (let x = 0; x < cols; x++) {
|
||||
for (let y = 0; y < rows; y++) {
|
||||
const idx = x + y * cols;
|
||||
const value = grid[idx];
|
||||
|
||||
if (value > 0.1) {
|
||||
const size = CELL_SIZE * value * 1.5;
|
||||
const xPos = x * CELL_SIZE + (CELL_SIZE - size) / 2;
|
||||
const yPos = y * CELL_SIZE + (CELL_SIZE - size) / 2;
|
||||
|
||||
ctx.fillStyle = getColor();
|
||||
ctx.globalAlpha = Math.min(1, value * 3);
|
||||
ctx.fillRect(xPos, yPos, size, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
let frameCount = 0;
|
||||
function animate() {
|
||||
frameCount++;
|
||||
|
||||
// Adjust feed/kill based on motion parameter
|
||||
const adjustedFeed = feed * (0.9 + params.motion * 0.2);
|
||||
const adjustedKill = kill * (1.1 - params.motion * 0.2);
|
||||
|
||||
// Random perturbation for complexity
|
||||
if (frameCount % 30 === 0 && Math.random() < params.complexity * 0.3) {
|
||||
const x = Math.floor(Math.random() * cols);
|
||||
const y = Math.floor(Math.random() * rows);
|
||||
grid[x + y * cols] = 1;
|
||||
}
|
||||
|
||||
// Update simulation
|
||||
for (let i = 0; i < 5; i++) {
|
||||
updateGrid();
|
||||
}
|
||||
|
||||
drawGrid();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue