birth: Lorenzian Loops in Dust
This commit is contained in:
parent
5dfc19cc8e
commit
c634da2c2c
1 changed files with 164 additions and 0 deletions
164
index.html
Normal file
164
index.html
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Strange Attractor</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: monospace;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: flex-end;
|
||||
height: 100vh;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 11px;
|
||||
opacity: 0.6;
|
||||
text-align: center;
|
||||
}
|
||||
</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();
|
||||
|
||||
// Strange attractor parameters (Lorenz-like system)
|
||||
let time = 0;
|
||||
const params = {
|
||||
a: 10,
|
||||
b: 28,
|
||||
c: 8/3,
|
||||
dt: 0.01,
|
||||
scale: 10,
|
||||
speed: 0.5,
|
||||
colorPhase: 0
|
||||
};
|
||||
|
||||
// Drawing parameters
|
||||
const maxPoints = 5000;
|
||||
const points = [];
|
||||
const trails = [];
|
||||
let hueShift = 0;
|
||||
|
||||
// Initialize points in a small sphere
|
||||
for (let i = 0; i < maxPoints; i++) {
|
||||
points.push({
|
||||
x: (Math.random() - 0.5) * 0.1,
|
||||
y: (Math.random() - 0.5) * 0.1,
|
||||
z: (Math.random() - 0.5) * 0.1,
|
||||
color: Math.random() * 360
|
||||
});
|
||||
}
|
||||
|
||||
function updatePoints() {
|
||||
params.colorPhase += 0.005;
|
||||
hueShift += 0.001;
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const p = points[i];
|
||||
|
||||
// Lorenz system equations
|
||||
const dx = params.a * (p.y - p.x);
|
||||
const dy = p.x * (params.b - p.z) - p.y;
|
||||
const dz = p.x * p.y - params.c * p.z;
|
||||
|
||||
p.x += dx * params.dt * params.speed;
|
||||
p.y += dy * params.dt * params.speed;
|
||||
p.z += dz * params.dt * params.speed;
|
||||
|
||||
// Wrap around if needed
|
||||
if (Math.abs(p.x) > 10) p.x *= -1;
|
||||
if (Math.abs(p.y) > 10) p.y *= -1;
|
||||
if (Math.abs(p.z) > 10) p.z *= -1;
|
||||
|
||||
// Store trail points
|
||||
if (trails[i] === undefined) trails[i] = [];
|
||||
trails[i].push({
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
z: p.z,
|
||||
time: time
|
||||
});
|
||||
|
||||
// Keep only recent trail points
|
||||
if (trails[i].length > 100) trails[i].shift();
|
||||
}
|
||||
|
||||
time += params.dt;
|
||||
}
|
||||
|
||||
function draw() {
|
||||
// Fade effect
|
||||
ctx.fillStyle = `rgba(0, 0, 0, 0.05)`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Center and scale
|
||||
const centerX = canvas.width / 2;
|
||||
const centerY = canvas.height / 2;
|
||||
|
||||
// Draw trails
|
||||
for (let i = 0; i < trails.length; i++) {
|
||||
if (trails[i]) {
|
||||
const p = trails[i][trails[i].length - 1];
|
||||
const trail = trails[i];
|
||||
|
||||
// Calculate color based on position and time
|
||||
const hue = (p.z * 30 + params.colorPhase * 360) % 360;
|
||||
const saturation = Math.min(100, Math.abs(p.z * 10));
|
||||
const lightness = 50 + Math.sin(p.time * 0.1) * 20;
|
||||
const alpha = Math.min(1, trail.length / 100);
|
||||
|
||||
// Draw trail
|
||||
ctx.strokeStyle = `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
||||
ctx.lineWidth = 1.5;
|
||||
|
||||
ctx.beginPath();
|
||||
for (let j = 0; j < trail.length; j++) {
|
||||
const t = trail[j];
|
||||
const x = centerX + t.x * params.scale;
|
||||
const y = centerY + t.y * params.scale;
|
||||
|
||||
if (j === 0) {
|
||||
ctx.moveTo(x, y);
|
||||
} else {
|
||||
ctx.lineTo(x, y);
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
updatePoints();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue