@cesarvenzac/figures 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/dist/figure-acts.d.ts +55 -0
- package/dist/figure-acts.js +616 -0
- package/dist/figure-curves.d.ts +30 -0
- package/dist/figure-curves.js +44 -0
- package/dist/figure-gl.d.ts +33 -0
- package/dist/figure-gl.js +875 -0
- package/dist/figure-loop.d.ts +3 -0
- package/dist/figure-loop.js +21 -0
- package/dist/figure-motion.d.ts +76 -0
- package/dist/figure-motion.js +260 -0
- package/dist/figure-peers.d.ts +36 -0
- package/dist/figure-peers.js +37 -0
- package/dist/figure-pose.d.ts +77 -0
- package/dist/figure-pose.js +108 -0
- package/dist/figure-scene.d.ts +65 -0
- package/dist/figure-scene.js +210 -0
- package/dist/figure-space.d.ts +233 -0
- package/dist/figure-space.js +151 -0
- package/dist/figure.d.ts +204 -0
- package/dist/figure.js +277 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/react.d.ts +69 -0
- package/dist/react.js +775 -0
- package/dist/rubik.d.ts +34 -0
- package/dist/rubik.js +54 -0
- package/package.json +73 -4
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The curves the figures move by (figure-motion.ts and figure-acts.ts): easing,
|
|
3
|
+
* keyframes, bumps and wobbles, each a pure function of how far through something is.
|
|
4
|
+
*/
|
|
5
|
+
export const clamp01 = (x) => Math.min(1, Math.max(0, x));
|
|
6
|
+
/** Where `p` is between `from` and `to`, 0 to 1. */
|
|
7
|
+
export const span = (p, from, to) => clamp01((p - from) / (to - from));
|
|
8
|
+
export const easeOut = (x) => 1 - (1 - x) ** 3;
|
|
9
|
+
export const easeIn = (x) => x ** 3;
|
|
10
|
+
export const easeInOut = (x) => (x < 0.5 ? 4 * x ** 3 : 1 - (-2 * x + 2) ** 3 / 2);
|
|
11
|
+
/** Past the end and back: an overshoot that settles. */
|
|
12
|
+
export const easeOutBack = (x, s = 1.7) => 1 + (s + 1) * (x - 1) ** 3 + s * (x - 1) ** 2;
|
|
13
|
+
/** Up and down again, 0 at both ends and 1 in the middle. */
|
|
14
|
+
export const bump = (x) => Math.sin(Math.PI * clamp01(x));
|
|
15
|
+
/** A ball's arc, 0 at both ends and 1 in the middle. */
|
|
16
|
+
export const arc = (x) => 4 * clamp01(x) * (1 - clamp01(x));
|
|
17
|
+
/** A wobble that dies away: `cycles` swings over 0–1. */
|
|
18
|
+
export const wobble = (x, cycles) => Math.sin(2 * Math.PI * cycles * clamp01(x)) * (1 - clamp01(x)) ** 1.4;
|
|
19
|
+
/** A value through keyframes, eased in and out between each: [p, value] pairs, p rising. */
|
|
20
|
+
export function keys(p, frames) {
|
|
21
|
+
if (p <= frames[0][0])
|
|
22
|
+
return frames[0][1];
|
|
23
|
+
for (let i = 1; i < frames.length; i++) {
|
|
24
|
+
const [p1, v1] = frames[i];
|
|
25
|
+
const [p0, v0] = frames[i - 1];
|
|
26
|
+
if (p <= p1)
|
|
27
|
+
return v0 + (v1 - v0) * easeInOut(span(p, p0, p1));
|
|
28
|
+
}
|
|
29
|
+
return frames[frames.length - 1][1];
|
|
30
|
+
}
|
|
31
|
+
/** In and out again, held between: 0 to 1 from `start` to `full`, back to 0 from `leave` to `end`, eased both ways. */
|
|
32
|
+
export const hold = (p, start, full, leave, end) => Math.min(easeInOut(span(p, start, full)), 1 - easeInOut(span(p, leave, end)));
|
|
33
|
+
/** Into a morph and out again, held at the top: 0 to 1 by `full`, back to 0 from `leave` to `end`, overshooting on the way in. */
|
|
34
|
+
export const into = (p, start, full, leave, end = 1) => Math.min(easeOutBack(span(p, start, full), 1.2), 1 - easeInOut(span(p, leave, end)));
|
|
35
|
+
/** A number from a seed and an index, the same every time, 0 to 1. */
|
|
36
|
+
export const noise = (seed, index) => {
|
|
37
|
+
const x = Math.sin(seed * 12.9898 + index * 78.233) * 43758.5453;
|
|
38
|
+
return x - Math.floor(x);
|
|
39
|
+
};
|
|
40
|
+
/** Where `t` is in a cycle of `period`, 0 to 1. */
|
|
41
|
+
export const phaseOf = (t, period) => ((t % period) + period) % period / period;
|
|
42
|
+
const TAU = Math.PI * 2;
|
|
43
|
+
/** A whole turn in radians. */
|
|
44
|
+
export const TURN = TAU;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type FigureScene } from "./figure-space.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The figures, drawn: real 3D shapes (a cube, a sphere, a pyramid, a block, a cloud) found
|
|
4
|
+
* by raymarching their distance fields in one fragment shader, in the original Aura's material, the
|
|
5
|
+
* eyes painted on their surface. No geometry and no textures: every pixel asks the shapes how far
|
|
6
|
+
* it is from them.
|
|
7
|
+
*
|
|
8
|
+
* Aura's material, as its experiment drew it on a sphere: colour as noise warped by noise
|
|
9
|
+
* (MaterialX's Perlin noise, as Three's TSL gave it), flowing, through a cosine palette; a rainbow
|
|
10
|
+
* running round the rim, turned from the direction itself so it has no seam; milky towards the
|
|
11
|
+
* middle like a ball of thick glass lit from inside; a gloss where the light lands; and a halo of
|
|
12
|
+
* the rim's own colour outside, with rings while it listens and a light running round while it
|
|
13
|
+
* thinks. Here the rim follows each shape's surface (how far it faces away), so a cube's front is
|
|
14
|
+
* milky and its edges and faces turned away run with colour.
|
|
15
|
+
*
|
|
16
|
+
* Everything that moves arrives as numbers (`FigureScene`, figure-space.ts): how the
|
|
17
|
+
* body is turned, lifted and squashed, a morph into a blob, a star or a heart, where the eyes are
|
|
18
|
+
* and how their lids sit; and each shape's own parts: the cube's cubelets (turning a layer, as a
|
|
19
|
+
* Rubik's cube does, or flying apart), the block's three dials, the pyramid's slabs and capstone,
|
|
20
|
+
* the sphere's size, ripples and moons, the cloud's puffs and raindrops. In front of it, hearts,
|
|
21
|
+
* stars, z's and sparks; behind and under a cloud, its rainbow and its lightning. One WebGL 2 context for every figure on the
|
|
22
|
+
* page (a browser keeps only a few): each figure is drawn into it and copied onto its own canvas
|
|
23
|
+
* straight away. Where WebGL 2 is missing or lost, `drawFigure` says so and the figure keeps its
|
|
24
|
+
* still drawing.
|
|
25
|
+
*/
|
|
26
|
+
/** The largest figure drawn, in device pixels; a bigger one is drawn at this and scaled. */
|
|
27
|
+
export declare const MOST_PIXELS = 512;
|
|
28
|
+
/** Whether figures can be drawn here at all (WebGL 2, and the shader compiled). */
|
|
29
|
+
export declare function canDraw(): boolean;
|
|
30
|
+
/** Draws a figure's scene onto `target` (its own canvas, in device pixels). False when there's no WebGL 2, or it was lost. */
|
|
31
|
+
export declare function drawFigure(target: HTMLCanvasElement, scene: FigureScene): boolean;
|
|
32
|
+
/** Calls `redraw` when a lost context comes back, so a figure can draw again. */
|
|
33
|
+
export declare function onRestored(redraw: () => void): () => void;
|