aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian cully <bjc@spork.org>2025-12-29 14:39:12 -0500
committerbrian cully <bjc@spork.org>2025-12-29 14:39:12 -0500
commit4c3b55529838e8c9d42f9ebb43c95f5020f22b21 (patch)
tree66e1304b17195920d4d66108b84138cceb2e1ba5
parent65d1301072a7f9223ce2ffe420b6f2784b8bbe04 (diff)
downloadpolyring-4c3b55529838e8c9d42f9ebb43c95f5020f22b21.tar.gz
polyring-4c3b55529838e8c9d42f9ebb43c95f5020f22b21.zip
pure: dot count from input
-rw-r--r--site/pure.mjs32
1 files changed, 20 insertions, 12 deletions
diff --git a/site/pure.mjs b/site/pure.mjs
index bc3f8a4..fdece47 100644
--- a/site/pure.mjs
+++ b/site/pure.mjs
@@ -1,5 +1,3 @@
-const NUM_POINTS = 40;
-
// thanks vihart
const TAU = 2 * Math.PI;
@@ -100,6 +98,15 @@ class Line {
}
}
+let points = [];
+// const points = [
+// new Point(0.5, 0.1),
+// new Point(0.75, 0.2),
+// new Point(0.9, 0.9),
+// new Point(0.2, 0.5),
+// new Point(0.6, 0.4), // should be inside
+// ];
+
// assume points is sorted min first.
function findPoly3(points) {
// console.debug('findPoly()', ...points.map(p => { return {x: p.x, y: p.y} }));
@@ -141,15 +148,6 @@ function findPoly3(points) {
return res;
}
-const points = [...Array(NUM_POINTS)].map(_ => new Point());
-// const points = [
-// new Point(0.5, 0.1),
-// new Point(0.75, 0.2),
-// new Point(0.9, 0.9),
-// new Point(0.2, 0.5),
-// new Point(0.6, 0.4), // should be inside
-// ];
-
function randColor() {
const [r, g, b] = [...Array(3)].map(_ => Math.random() * 255);
return `rgb(${r} ${g} ${b})`
@@ -239,6 +237,10 @@ function update(points) {
movePoints(points);
}
+function setDotCount(n) {
+ points = [...Array(n)].map(_ => new Point());
+}
+
export default async function () {
const canvas = document.querySelector('section.watch canvas');
const ctx = canvas.getContext('2d');
@@ -246,6 +248,12 @@ export default async function () {
ctx.scale(canvas.width, canvas.height);
const fps = document.querySelector('section.watch .fps');
+ const dotCount = document.querySelector('#dots');
+ dotCount.onchange = e => {
+ console.debug('dot count changed', e);
+ setDotCount(Number(dotCount.value));
+ renderFrame(document.timeline.currentTime, canvas, ctx, fps);
+ };
const goButton = document.querySelector('section.watch button');
let paused = true;
@@ -287,5 +295,5 @@ export default async function () {
self.requestAnimationFrame(render);
}
}
- renderFrame(document.timeline.currentTime, canvas, ctx, fps);
+ dotCount.onchange({ target: dotCount });
}