137 lines
No EOL
4.2 KiB
HTML
137 lines
No EOL
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Rust Patterns</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background-color: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #444;
|
|
font-size: 10px;
|
|
pointer-events: none;
|
|
}
|
|
</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();
|
|
|
|
// Reaction-diffusion parameters
|
|
const params = {
|
|
feedRate: 0.055,
|
|
killRate: 0.062,
|
|
diffusionRateA: 1.0,
|
|
diffusionRateB: 0.5,
|
|
timeStep: 1.0,
|
|
gridSize: 4,
|
|
paleness: 0.3 + Math.random() * 0.2,
|
|
colorVariation: 0.1
|
|
};
|
|
|
|
const width = Math.floor(canvas.width / params.gridSize);
|
|
const height = Math.floor(canvas.height / params.gridSize);
|
|
const size = width * height;
|
|
|
|
// Initialize grids
|
|
let grid = new Float32Array(size * 2);
|
|
let nextGrid = new Float32Array(size * 2);
|
|
|
|
// Initialize with random values
|
|
for (let i = 0; i < size; i++) {
|
|
grid[i] = Math.random();
|
|
grid[i + size] = Math.random();
|
|
}
|
|
|
|
// Reaction-diffusion kernel
|
|
const laplacian = (x, y) => {
|
|
let sum = 0;
|
|
let count = 0;
|
|
|
|
for (let ky = -1; ky <= 1; ky++) {
|
|
for (let kx = -1; kx <= 1; kx++) {
|
|
if (kx === 0 && ky === 0) continue;
|
|
if (x + kx < 0 || x + kx >= width || y + ky < 0 || y + ky >= height) continue;
|
|
|
|
sum += grid[(y + ky) * width + (x + kx)];
|
|
count++;
|
|
}
|
|
}
|
|
return (sum - grid[y * width + x] * count) / (count + 1);
|
|
};
|
|
|
|
function update() {
|
|
// Update reaction-diffusion
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const i = y * width + x;
|
|
|
|
const a = grid[i];
|
|
const b = grid[i + size];
|
|
|
|
const laplacianA = laplacian(x, y);
|
|
const laplacianB = laplacian(x, y);
|
|
|
|
nextGrid[i] = a + params.timeStep *
|
|
(params.diffusionRateA * laplacianA - a * b * b + params.feedRate * (1 - a));
|
|
|
|
nextGrid[i + size] = b + params.timeStep *
|
|
(params.diffusionRateB * laplacianB + a * b * b - (params.killRate + params.feedRate) * b);
|
|
}
|
|
}
|
|
|
|
// Swap grids
|
|
[grid, nextGrid] = [nextGrid, grid];
|
|
|
|
// Draw
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const i = y * width + x;
|
|
const a = grid[i];
|
|
const b = grid[i + size];
|
|
|
|
// Simple dark palette with variation
|
|
const value = Math.min(1, Math.max(0, (a - b) * params.paleness));
|
|
const hue = 0 + (a - b) * params.colorVariation * 120;
|
|
ctx.fillStyle = `hsl(${hue}, 80%, ${Math.max(10, 10 + (value * 40))}%)`;
|
|
ctx.fillRect(
|
|
x * params.gridSize,
|
|
y * params.gridSize,
|
|
params.gridSize + 1,
|
|
params.gridSize + 1
|
|
);
|
|
}
|
|
}
|
|
|
|
requestAnimationFrame(update);
|
|
}
|
|
|
|
update();
|
|
</script>
|
|
</body>
|
|
</html> |