first commit - found it not working

the dots just wobble back and forth one stop
This commit is contained in:
Christian Lawson-Perfect 2025-05-04 13:00:58 +00:00
commit e42a570690
4 changed files with 105 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.make.*

28
index.html Normal file
View file

@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>A thing made by CLP</title>
<script type="module" src="script.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>A thing made by CLP</h1>
</header>
<main>
<svg id="board" viewBox="-0.1 -0.1 1.2 1.2">
<defs>
<linearGradient id="dots-gradient">
<stop offset="0%" stop-color="green" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<rect x="-100" y="-100" width="200" height="200" fill="hsl(120,30%,70%)"/>
<path id="curve" fill="none" stroke="black" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="square"/>
<path id="dots" fill="none" stroke="hsl(120,50%,70%)" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="round"/>
</svg>
</main>
</body>
</html>

71
script.js Normal file
View file

@ -0,0 +1,71 @@
/*
Duration: 52 seconds.0:52
Hilbert curve at its sixth iteration
Alphabet : A, B
Constants : F +
Axiom : A
Production rules:
*/
console.clear();
const rules = {
"A": "+BF-AFA-FB+",
"B": "-AF+BFB+FA-",
};
let steps = 5;
let s = "A";
for(let i=0;i<steps;i++) {
let ns = "";
for(let c of s) {
ns += rules[c] || c;
}
s = ns;
}
let [x,y] = [0,0];
const m = 2**(-steps);
let dir = [m,0];
let d = 'M 0 0 ';
const width = 1.5 * 2**-(steps+1);
const dots = [];
for(let c of s) {
const [dx,dy] = dir;
switch(c) {
case '+':
dir = [-dy,dx];
break;
case '-':
dir = [dy,-dx];
break;
case 'F':
x += dx;
y += dy;
d += `l ${dx} ${dy}`;
}
}
const length = 2**steps - 1;
document.getElementById('curve').setAttribute('stroke-width',width);
document.getElementById('curve').setAttribute('d',d);
document.getElementById('dots').setAttribute('stroke-width',width*0.4);
document.getElementById('dots').setAttribute('d',d);
document.getElementById('dots').setAttribute('stroke-dasharray',`0.0000001 ${2*m}`);
function easeInOutSine(x) {
return -(Math.cos(Math.PI * x) - 1) / 2;
}
function frame() {
const period = 1000;
const t = (new Date()-0)/period % 1000;
document.getElementById('dots').setAttribute('stroke-dashoffset',easeInOutSine(t)*m);
requestAnimationFrame(frame);
}
frame();

5
style.css Normal file
View file

@ -0,0 +1,5 @@
:root {
--spacing: 1em;
color-scheme: light dark;
}