Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill: the kernel's index says which corner is near, that fit only centres and how to choose S, what put maps, and the limits of seg, rings, fillet, tween and tset
Lucas Marques8b6b316b7caf
diff --git a/scripts/kernel.mjs b/scripts/kernel.mjsindex 9f73e0a..1b3a3f1 100644--- a/scripts/kernel.mjs+++ b/scripts/kernel.mjs@@ -25,11 +25,16 @@ const INDEX = `/*** Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the* ground and z up. Plates are filled with the ground colour and painted back- * to front, so a nearer one covers a farther one: append in that order.+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.** Camera* Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale* fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall* proj(C) returns P(x, y, z), which gives [sx, sy]* unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z* facing(C) returns front(sample): whether a ring sample faces the camera@@ -37,17 +42,21 @@ const INDEX = `/** rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}* circ(R, n) a circle, as a ring* rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out* prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings* ringAt(P, ring, z) the ring's points, projected at height z* run(ring, keep) the one cyclic run of samples that pass keep* hull(points) the convex hull of screen points* extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from- * fillet(points, radii, n) rounds every vertex of a closed polygon+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points* ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you* Paths and numbers* poly(points) a closed path string* open(points) an open polyline string- * seg(a, b) one segment, as its own subpath+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first* clamp(v, a, b)* lerp(a, b, t)* rad(deg)@@ -56,8 +65,9 @@ const INDEX = `/** spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1* stepS(sp, dt) advances by dt seconds; returns whether it is still moving* The discrete clock: a 700ms tween on (.32, .72, 0, 1)- * tween(v, dur) at rest on v+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)* tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe* tval(tw, now) its value at now* tdone(tw, now) whether it has landed* bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress@@ -67,7 +77,7 @@ const INDEX = `/** Drawing* mk(tag, attrs, parent) one svg element: the only way a figure makes a node* solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path- * put(solid, paths) writes prism()'s paths into solid()'s elements+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr* flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"* place(el, point) moves a dot or a circle to [sx, sy]* reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a soliddiff --git a/skills/hairline-create/kernel.js b/skills/hairline-create/kernel.jsindex b50abeb..7f6febf 100644--- a/skills/hairline-create/kernel.js+++ b/skills/hairline-create/kernel.js@@ -1,15 +1,20 @@-/* hairline kernel sha256:8009504ebe24d93229ddab8b890d826807aa5d147c43237a11828cc5600417ea */+/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.** Every figure is drawn in a 400 × 320 viewBox. World space is x/y on the* ground and z up. Plates are filled with the ground colour and painted back- * to front, so a nearer one covers a farther one: append in that order.+ * to front, so a nearer one covers a farther one: append in that order. At+ * the default camera, Cam(45, 0.5, S), +x runs down to the right and +y down+ * to the left, so the corner with the largest x and y is nearest the viewer:+ * append by ascending x + y, from the far corner (smallest x and y) to it.** Camera* Cam(azDeg, k, S) a camera: azimuth in degrees, k = sin(elevation) (0.5 is the 2:1 view), S = scale* fit(C, points, cx, cy) centres the box of [x, y, z] points on (cx, cy); call it once, before proj+ * it only centres, it never scales: choose S by trying values, with the most extreme pose in points.+ * The six figures use S 1.42 to 2.12; the boxes they fit come out 230 to 310 wide and 180 to 245 tall* proj(C) returns P(x, y, z), which gives [sx, sy]* unproj(C, sx, sy, z) the world [x, y] under a screen point, on the plane at height z* facing(C) returns front(sample): whether a ring sample faces the camera@@ -17,17 +22,21 @@* rrect(u0, v0, u1, v1, r, n) a rounded rectangle, as a ring of samples {u, v, nu, nv}* circ(R, n) a circle, as a ring* rings(x0, y0, x1, y1, r, b) [ring, inner]: a rounded footprint and its crease ring, inset by b+ * r, the corner radius, is cut to half the shorter side. b, the crease's inset in world units+ * (0.6 to 2.2 in the figures), must stay under half the shorter side or the crease turns inside out* prism(P, front, ring, inner, z0, z1) {sil, crease}: a solid standing from z0 to z1, as two path strings* ringAt(P, ring, z) the ring's points, projected at height z* run(ring, keep) the one cyclic run of samples that pass keep* hull(points) the convex hull of screen points* extremes(P, ring) [left, right, nearest] samples: where dashed drops fall from- * fillet(points, radii, n) rounds every vertex of a closed polygon+ * fillet(points, radii, n) rounds every vertex of a closed polygon; returns the new points+ * radii is an array, one radius per vertex, each cut to half its shorter edge; a single number gives NaN.+ * n is the steps round each corner, default 4: each vertex becomes n + 1 points* ghost(P, front, ring, z0, depth) a reflection's path {d, y0, y1}; reflect() draws it for you* Paths and numbers* poly(points) a closed path string* open(points) an open polyline string- * seg(a, b) one segment, as its own subpath+ * seg(a, b) one segment between two screen points [sx, sy], as its own subpath; project world points with P first* clamp(v, a, b)* lerp(a, b, t)* rad(deg)@@ -36,8 +45,9 @@* spring(x, opts) at rest on x; write .t to retarget; opts {k, c, m, eps}, default k 100, c 18, m 1* stepS(sp, dt) advances by dt seconds; returns whether it is still moving* The discrete clock: a 700ms tween on (.32, .72, 0, 1)- * tween(v, dur) at rest on v+ * tween(v, dur) at rest on v; dur defaults to 700 (ms)* tset(tw, to, now, delay) retargets from where it is, after delay ms: the stagger+ * the same target again does nothing, so calling it on every pointer move is safe* tval(tw, now) its value at now* tdone(tw, now) whether it has landed* bezier(x1, y1, x2, y2) a CSS cubic-bezier, as a function of progress@@ -47,7 +57,7 @@* Drawing* mk(tag, attrs, parent) one svg element: the only way a figure makes a node* solid(parent) {g, sil, cr}: a group holding a silhouette path and a crease path- * put(solid, paths) writes prism()'s paths into solid()'s elements+ * put(solid, paths) writes prism()'s {sil, crease} into solid()'s {sil, cr}: sil into sil, crease into cr* flatDot(parent, C, r, cls) a dot lying on the ground plane; cls is "dot", "dot m" or "dot off"* place(el, point) moves a dot or a circle to [sx, sy]* reflect(svg, parent, P, front, ring, z0, depth) a fading mirror under a solid