retouche-dev 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,72 @@
1
+ // src/hand-arrow.ts
2
+ const TAIL_WOBBLE = .1;
3
+ const BOW = {
4
+ least: .05,
5
+ most: .14
6
+ };
7
+ const HEAD = {
8
+ length: .42,
9
+ spread: .55
10
+ };
11
+ const HEAD_WOBBLE = {
12
+ length: .12,
13
+ spread: .12
14
+ };
15
+ function seeded(seed) {
16
+ let hash = 0;
17
+ for (const char of seed) hash = (hash * 31 + (char.codePointAt(0) ?? 0)) % 1000003;
18
+ let draws = 0;
19
+ return () => {
20
+ draws += 1;
21
+ const wave = Math.sin(hash * 12.9898 + draws * 78.233) * 43758.5453;
22
+ return wave - Math.floor(wave);
23
+ };
24
+ }
25
+ function wobble(random, amount) {
26
+ return (random() * 2 - 1) * amount;
27
+ }
28
+ function at({ x, y }) {
29
+ return `${Math.round(x * 100) / 100} ${Math.round(y * 100) / 100}`;
30
+ }
31
+ function wingOf(random, { angle, length, tip }) {
32
+ const turned = angle + wobble(random, HEAD_WOBBLE.spread);
33
+ const reach = length * (1 + wobble(random, HEAD_WOBBLE.length));
34
+ return {
35
+ x: tip.x - Math.cos(turned) * reach,
36
+ y: tip.y - Math.sin(turned) * reach
37
+ };
38
+ }
39
+ function handArrow(seed, size) {
40
+ const random = seeded(seed);
41
+ const tail = {
42
+ x: wobble(random, size * TAIL_WOBBLE),
43
+ y: wobble(random, size * TAIL_WOBBLE)
44
+ };
45
+ const tip = {
46
+ x: size,
47
+ y: size
48
+ };
49
+ const span = Math.hypot(tip.x - tail.x, tip.y - tail.y);
50
+ const bow = Math.sign(random() - .5) * span * (BOW.least + random() * (BOW.most - BOW.least));
51
+ const control = {
52
+ x: (tail.x + tip.x) / 2 - (tip.y - tail.y) / span * bow,
53
+ y: (tail.y + tip.y) / 2 + (tip.x - tail.x) / span * bow
54
+ };
55
+ const heading = Math.atan2(tip.y - control.y, tip.x - control.x);
56
+ const length = size * HEAD.length;
57
+ const left = wingOf(random, {
58
+ angle: heading - HEAD.spread,
59
+ length,
60
+ tip
61
+ });
62
+ const right = wingOf(random, {
63
+ angle: heading + HEAD.spread,
64
+ length,
65
+ tip
66
+ });
67
+ return {
68
+ head: `M${at(left)}L${at(tip)}L${at(right)}`,
69
+ shaft: `M${at(tail)}Q${at(control)} ${at(tip)}`
70
+ };
71
+ }
72
+ export { handArrow as t };
@@ -0,0 +1,5 @@
1
+ export interface HandArrow {
2
+ head: string;
3
+ shaft: string;
4
+ }
5
+ export declare function handArrow(seed: string, size: number): HandArrow;
@@ -0,0 +1 @@
1
+ export { t as handArrow } from "./hand-arrow-Dc5fTEjK.js";