birth: Defrosted Grid Dissolves
This commit is contained in:
parent
66b5c74a19
commit
7cb4f56bbe
1 changed files with 189 additions and 0 deletions
189
index.html
Normal file
189
index.html
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Defrosted Grid</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
}
|
||||
</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();
|
||||
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5
|
||||
};
|
||||
|
||||
function hexToRgb(hex) {
|
||||
const r = parseInt(hex.slice(1, 3), 16) / 255;
|
||||
const g = parseInt(hex.slice(3, 5), 16) / 255;
|
||||
const b = parseInt(hex.slice(5, 7), 16) / 255;
|
||||
return [r, g, b];
|
||||
}
|
||||
|
||||
function interpolate(p, a, b) {
|
||||
return a + (b - a) * p;
|
||||
}
|
||||
|
||||
function getColor(palette, value) {
|
||||
const range = 0.1;
|
||||
const low = Math.max(0, value - range);
|
||||
const high = Math.min(1, value + range);
|
||||
const r = hexToRgb('#' + palette);
|
||||
return `rgba(${Math.floor(r[0] * 255)}, ${Math.floor(r[1] * 255)}, ${Math.floor(r[2] * 255)}, 1)`;
|
||||
}
|
||||
|
||||
function drawTessellatedTerrain() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
const cols = Math.floor(interpolate(params.density, 10, 40));
|
||||
const rows = Math.floor(interpolate(params.density, 10, 40));
|
||||
const cellSize = Math.min(canvas.width / cols, canvas.height / rows);
|
||||
|
||||
const octaves = Math.floor(interpolate(params.complexity, 1, 4));
|
||||
const frequency = interpolate(params.connectedness, 0.5, 2.0);
|
||||
const persistence = 0.5;
|
||||
const lacunarity = 2.0;
|
||||
|
||||
const time = performance.now() * 0.0005 * interpolate(params.motion, 0.5, 1.5) * params.pulse.avg;
|
||||
|
||||
for (let y = 0; y < rows; y++) {
|
||||
for (let x = 0; x < cols; x++) {
|
||||
const nx = x / cols * frequency;
|
||||
const ny = y / rows * frequency;
|
||||
|
||||
let amplitude = 0;
|
||||
let frequencyScale = 1;
|
||||
let maxAmplitude = 0;
|
||||
|
||||
for (let i = 0; i < octaves; i++) {
|
||||
amplitude += Math.abs(noise(nx * frequencyScale, ny * frequencyScale)) * (1 / frequencyScale);
|
||||
maxAmplitude += 1 / frequencyScale;
|
||||
frequencyScale *= lacunarity;
|
||||
}
|
||||
|
||||
const value = amplitude / maxAmplitude;
|
||||
const elevation = interpolate(value, -0.1, 1.1);
|
||||
|
||||
const cellX = x * cellSize;
|
||||
const cellY = y * cellSize;
|
||||
const size = cellSize * 0.9;
|
||||
|
||||
const h = interpolate(elevation, 0.1, 0.9);
|
||||
const s = 0;
|
||||
const l = interpolate(elevation, 0.2, 0.7);
|
||||
const color = `hsl(0, 0%, ${Math.floor(l * 100)}%)`;
|
||||
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(cellX, cellY, size, size);
|
||||
|
||||
// Add some variation to cell shapes based on complexity
|
||||
if (Math.random() < interpolate(params.complexity, 0.1, 0.4)) {
|
||||
ctx.save();
|
||||
ctx.translate(cellX + size/2, cellY + size/2);
|
||||
ctx.rotate(time * 0.3 * interpolate(params.connectedness, 0.5, 1.5));
|
||||
const scale = 1 + Math.sin(time * 0.5) * 0.1 * interpolate(params.motion, 0.1, 0.5);
|
||||
ctx.scale(scale, scale);
|
||||
ctx.fillRect(-size/2 * 0.8, -size/2 * 0.8, size * 0.8, size * 0.8);
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Simple 2D noise function
|
||||
function noise(x, y) {
|
||||
const X = Math.floor(x) & 255;
|
||||
const Y = Math.floor(y) & 255;
|
||||
x -= Math.floor(x);
|
||||
y -= Math.floor(y);
|
||||
|
||||
const u = fade(x);
|
||||
const v = fade(y);
|
||||
|
||||
const A = (perm[X] + Y) & 255;
|
||||
const B = (perm[X + 1] + Y) & 255;
|
||||
|
||||
return lerp(v, lerp(u, grad(perm[A], x, y),
|
||||
grad(perm[B], x - 1, y)),
|
||||
lerp(u, grad(perm[A + 1], x, y - 1),
|
||||
grad(perm[B + 1], x - 1, y - 1)));
|
||||
}
|
||||
|
||||
function fade(t) {
|
||||
return t * t * t * (t * (t * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
function lerp(t, a, b) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
function grad(hash, x, y) {
|
||||
const h = hash & 15;
|
||||
const u = h < 8 ? x : y;
|
||||
const v = h < 4 ? y : h === 12 || h === 14 ? x : 0;
|
||||
return ((h & 1) === 0 ? u : -u) + ((h & 2) === 0 ? v : -v);
|
||||
}
|
||||
|
||||
const perm = new Array(512);
|
||||
const p = new Array(256);
|
||||
for (let i = 0; i < 256; i++) {
|
||||
p[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
for (let i = 0; i < 512; i++) {
|
||||
perm[i] = p[i & 255];
|
||||
}
|
||||
|
||||
let lastTime = 0;
|
||||
function animate(currentTime) {
|
||||
const deltaTime = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
|
||||
// Pulse effect
|
||||
params.pulse.avg = 1.1 + Math.sin(currentTime * 0.002) * 0.1;
|
||||
|
||||
drawTessellatedTerrain();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
params.pulse = { avg: 1.1, min: 1.0, max: 1.3 };
|
||||
requestAnimationFrame(animate);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue