@kerf-js/keel 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.
Files changed (192) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +306 -2
  3. package/package.json +59 -3
  4. package/src/blend-inset.ts +79 -0
  5. package/src/blend.ts +120 -0
  6. package/src/client.d.ts +9 -0
  7. package/src/generate/bust.ts +24 -0
  8. package/src/generate/bust.worker.ts +4 -0
  9. package/src/generate/pack.ts +69 -0
  10. package/src/generate/plate.ts +51 -0
  11. package/src/generate/plate.worker.ts +4 -0
  12. package/src/generate/serve.ts +56 -0
  13. package/src/generate/surface.ts +16 -0
  14. package/src/generate/surface.worker.ts +4 -0
  15. package/src/generate.ts +133 -0
  16. package/src/governor.ts +87 -0
  17. package/src/index.d.ts +15 -0
  18. package/src/index.mjs +63 -0
  19. package/src/lit.d.ts +384 -0
  20. package/src/paint-live.ts +60 -0
  21. package/src/paint-recipe.d.mts +29 -0
  22. package/src/paint-recipe.mjs +29 -0
  23. package/src/paint-worker.mjs +20 -0
  24. package/src/paint.d.mts +37 -0
  25. package/src/paint.mjs +180 -0
  26. package/src/runtime.ts +35 -0
  27. package/src/scene.ts +289 -0
  28. package/src/stage.ts +192 -0
  29. package/vendor/LICENSE +21 -0
  30. package/vendor/LICENSE-modules +21 -0
  31. package/vendor/NOTICE +24 -0
  32. package/vendor/README.md +13 -0
  33. package/vendor/lit.d.mts +1 -0
  34. package/vendor/lit.mjs +2 -0
  35. package/vendor/lock.json +177 -0
  36. package/vendor/modules/band/events.d.ts +20 -0
  37. package/vendor/modules/band/index.d.ts +29 -0
  38. package/vendor/modules/band/player.d.ts +43 -0
  39. package/vendor/modules/band/roll.d.ts +14 -0
  40. package/vendor/modules/band/score.d.ts +45 -0
  41. package/vendor/modules/band/styles.data.d.ts +37 -0
  42. package/vendor/modules/band/voices.d.ts +33 -0
  43. package/vendor/modules/band.d.mts +1 -0
  44. package/vendor/modules/band.mjs +2 -0
  45. package/vendor/modules/butterflies/butterflies.glsl.d.ts +2 -0
  46. package/vendor/modules/butterflies/flight.d.ts +68 -0
  47. package/vendor/modules/butterflies/index.d.ts +79 -0
  48. package/vendor/modules/butterflies/wing.d.ts +38 -0
  49. package/vendor/modules/butterflies.d.mts +1 -0
  50. package/vendor/modules/butterflies.inputs.json +73 -0
  51. package/vendor/modules/butterflies.mjs +39 -0
  52. package/vendor/modules/camera-rail/index.d.ts +113 -0
  53. package/vendor/modules/camera-rail.d.mts +1 -0
  54. package/vendor/modules/camera-rail.mjs +2 -0
  55. package/vendor/modules/device-profile/index.d.ts +47 -0
  56. package/vendor/modules/device-profile.d.mts +1 -0
  57. package/vendor/modules/device-profile.mjs +2 -0
  58. package/vendor/modules/lit-finish/dress.d.ts +34 -0
  59. package/vendor/modules/lit-finish/finish.glsl.d.ts +15 -0
  60. package/vendor/modules/lit-finish/index.d.ts +33 -0
  61. package/vendor/modules/lit-finish/lit.d.ts +52 -0
  62. package/vendor/modules/lit-finish/pass.d.ts +35 -0
  63. package/vendor/modules/lit-finish/settings.d.ts +88 -0
  64. package/vendor/modules/lit-finish.d.mts +1 -0
  65. package/vendor/modules/lit-finish.inputs.json +200 -0
  66. package/vendor/modules/lit-finish.mjs +267 -0
  67. package/vendor/modules/look/index.d.ts +159 -0
  68. package/vendor/modules/look.d.mts +1 -0
  69. package/vendor/modules/look.inputs.json +23 -0
  70. package/vendor/modules/look.mjs +2 -0
  71. package/vendor/modules/motes/index.d.ts +83 -0
  72. package/vendor/modules/motes/motes.glsl.d.ts +9 -0
  73. package/vendor/modules/motes/place.d.ts +59 -0
  74. package/vendor/modules/motes.d.mts +1 -0
  75. package/vendor/modules/motes.inputs.json +116 -0
  76. package/vendor/modules/motes.mjs +68 -0
  77. package/vendor/modules/plate-painter/dab.d.ts +44 -0
  78. package/vendor/modules/plate-painter/exact.d.ts +19 -0
  79. package/vendor/modules/plate-painter/foliage.d.ts +4 -0
  80. package/vendor/modules/plate-painter/gpu.d.ts +65 -0
  81. package/vendor/modules/plate-painter/index.d.ts +14 -0
  82. package/vendor/modules/plate-painter/paint.glsl.d.ts +14 -0
  83. package/vendor/modules/plate-painter/plan.d.ts +42 -0
  84. package/vendor/modules/plate-painter/recipe.d.ts +136 -0
  85. package/vendor/modules/plate-painter/scene.d.ts +4 -0
  86. package/vendor/modules/plate-painter.d.mts +1 -0
  87. package/vendor/modules/plate-painter.inputs.json +50 -0
  88. package/vendor/modules/plate-painter.mjs +384 -0
  89. package/vendor/modules/portrait/body.d.ts +25 -0
  90. package/vendor/modules/portrait/bust.d.ts +67 -0
  91. package/vendor/modules/portrait/cap.d.ts +12 -0
  92. package/vendor/modules/portrait/compile.d.ts +8 -0
  93. package/vendor/modules/portrait/exact.d.ts +17 -0
  94. package/vendor/modules/portrait/hair.d.ts +26 -0
  95. package/vendor/modules/portrait/hand.d.ts +30 -0
  96. package/vendor/modules/portrait/head.d.ts +18 -0
  97. package/vendor/modules/portrait/index.d.ts +12 -0
  98. package/vendor/modules/portrait/mesh.d.ts +24 -0
  99. package/vendor/modules/portrait/parts.d.ts +33 -0
  100. package/vendor/modules/portrait/portrait.glsl.d.ts +4 -0
  101. package/vendor/modules/portrait/render.d.ts +125 -0
  102. package/vendor/modules/portrait/sdf.d.ts +75 -0
  103. package/vendor/modules/portrait/settings.d.ts +27 -0
  104. package/vendor/modules/portrait.d.mts +1 -0
  105. package/vendor/modules/portrait.inputs.json +111 -0
  106. package/vendor/modules/portrait.mjs +2 -0
  107. package/vendor/modules/quality/index.d.ts +130 -0
  108. package/vendor/modules/quality.d.mts +1 -0
  109. package/vendor/modules/quality.inputs.json +34 -0
  110. package/vendor/modules/quality.mjs +2 -0
  111. package/vendor/modules/scene-blend/blend.d.ts +54 -0
  112. package/vendor/modules/scene-blend/blend.glsl.d.ts +8 -0
  113. package/vendor/modules/scene-blend/index.d.ts +25 -0
  114. package/vendor/modules/scene-blend/lit.d.ts +61 -0
  115. package/vendor/modules/scene-blend/noise.d.ts +13 -0
  116. package/vendor/modules/scene-blend/settings.d.ts +63 -0
  117. package/vendor/modules/scene-blend.d.mts +1 -0
  118. package/vendor/modules/scene-blend.inputs.json +133 -0
  119. package/vendor/modules/scene-blend.mjs +2 -0
  120. package/vendor/modules/section-post/index.d.ts +23 -0
  121. package/vendor/modules/section-post/lit.d.ts +47 -0
  122. package/vendor/modules/section-post/noise.d.ts +14 -0
  123. package/vendor/modules/section-post/post.d.ts +31 -0
  124. package/vendor/modules/section-post/post.glsl.d.ts +8 -0
  125. package/vendor/modules/section-post/settings.d.ts +84 -0
  126. package/vendor/modules/section-post.d.mts +1 -0
  127. package/vendor/modules/section-post.inputs.json +107 -0
  128. package/vendor/modules/section-post.mjs +53 -0
  129. package/vendor/modules/surfaces/exact.d.ts +8 -0
  130. package/vendor/modules/surfaces/field.d.ts +7 -0
  131. package/vendor/modules/surfaces/gpu.d.ts +19 -0
  132. package/vendor/modules/surfaces/index.d.ts +17 -0
  133. package/vendor/modules/surfaces/paint.d.ts +28 -0
  134. package/vendor/modules/surfaces/plan.d.ts +39 -0
  135. package/vendor/modules/surfaces/print.d.ts +55 -0
  136. package/vendor/modules/surfaces/recipe.d.ts +143 -0
  137. package/vendor/modules/surfaces/surface.glsl.d.ts +4 -0
  138. package/vendor/modules/surfaces.d.mts +1 -0
  139. package/vendor/modules/surfaces.inputs.json +54 -0
  140. package/vendor/modules/surfaces.mjs +172 -0
  141. package/vendor/modules/tracks/index.d.ts +66 -0
  142. package/vendor/modules/tracks.d.mts +1 -0
  143. package/vendor/modules/tracks.mjs +2 -0
  144. package/vendor/modules/tree-growth/bend.d.ts +28 -0
  145. package/vendor/modules/tree-growth/frame.d.ts +60 -0
  146. package/vendor/modules/tree-growth/index.d.ts +23 -0
  147. package/vendor/modules/tree-growth/light.d.ts +13 -0
  148. package/vendor/modules/tree-growth/math.d.ts +19 -0
  149. package/vendor/modules/tree-growth/model.d.ts +100 -0
  150. package/vendor/modules/tree-growth/sectors.d.ts +10 -0
  151. package/vendor/modules/tree-growth/simulation.d.ts +58 -0
  152. package/vendor/modules/tree-growth/species.d.ts +117 -0
  153. package/vendor/modules/tree-growth/species.data.d.ts +2 -0
  154. package/vendor/modules/tree-growth/year.d.ts +38 -0
  155. package/vendor/modules/tree-growth.d.mts +1 -0
  156. package/vendor/modules/tree-growth.inputs.json +75 -0
  157. package/vendor/modules/tree-growth.mjs +2 -0
  158. package/vendor/modules/tree-render/features.d.ts +9 -0
  159. package/vendor/modules/tree-render/forest/bake.d.ts +41 -0
  160. package/vendor/modules/tree-render/forest/cards.d.ts +28 -0
  161. package/vendor/modules/tree-render/forest/forest.d.ts +156 -0
  162. package/vendor/modules/tree-render/index.d.ts +52 -0
  163. package/vendor/modules/tree-render/inputs.d.ts +260 -0
  164. package/vendor/modules/tree-render/instances.d.ts +66 -0
  165. package/vendor/modules/tree-render/math.d.ts +8 -0
  166. package/vendor/modules/tree-render/tree/bark.d.ts +20 -0
  167. package/vendor/modules/tree-render/tree/leaves.d.ts +29 -0
  168. package/vendor/modules/tree-render/tree/litter.d.ts +21 -0
  169. package/vendor/modules/tree-render/tree/ornaments.d.ts +36 -0
  170. package/vendor/modules/tree-render/tree/roots.d.ts +75 -0
  171. package/vendor/modules/tree-render/tree/shapes.d.ts +49 -0
  172. package/vendor/modules/tree-render/tree/tree.d.ts +239 -0
  173. package/vendor/modules/tree-render/tree/wood.d.ts +27 -0
  174. package/vendor/modules/tree-render/wind.d.ts +51 -0
  175. package/vendor/modules/tree-render.d.mts +1 -0
  176. package/vendor/modules/tree-render.inputs.json +45 -0
  177. package/vendor/modules/tree-render.mjs +2 -0
  178. package/vendor/modules/voxel-dither/dither.glsl.d.ts +9 -0
  179. package/vendor/modules/voxel-dither/index.d.ts +35 -0
  180. package/vendor/modules/voxel-dither/light.d.ts +33 -0
  181. package/vendor/modules/voxel-dither/lit.d.ts +86 -0
  182. package/vendor/modules/voxel-dither/pass.d.ts +46 -0
  183. package/vendor/modules/voxel-dither/screens.d.ts +21 -0
  184. package/vendor/modules/voxel-dither/settings.d.ts +307 -0
  185. package/vendor/modules/voxel-dither/signals.d.ts +35 -0
  186. package/vendor/modules/voxel-dither.d.mts +1 -0
  187. package/vendor/modules/voxel-dither.inputs.json +295 -0
  188. package/vendor/modules/voxel-dither.mjs +452 -0
  189. package/vendor/modules/world-light/index.d.ts +133 -0
  190. package/vendor/modules/world-light.d.mts +1 -0
  191. package/vendor/modules/world-light.inputs.json +68 -0
  192. package/vendor/modules/world-light.mjs +2 -0
@@ -0,0 +1,60 @@
1
+ import type { SpeciesId } from "./species.js";
2
+ import type { TreeModel } from "./model.js";
3
+ export interface TreeFrame {
4
+ readonly cycle: number;
5
+ /** 0 not grown yet, rising to 1 as the internode elongates. */
6
+ readonly grow: Float32Array;
7
+ readonly radius: Float32Array;
8
+ /** 0 living wood, 1 long dead and grey. */
9
+ readonly dead: Float32Array;
10
+ /** 0 attached; rises to 1 while a shed branch falls; it then lies and rots. */
11
+ readonly fall: Float32Array;
12
+ /** 0 sound, 1 rotted away. */
13
+ readonly rot: Float32Array;
14
+ /** Living tips carried, the pipe-model weight. Small values are leafy twigs. */
15
+ readonly tips: Float32Array;
16
+ readonly x: Float32Array;
17
+ readonly y: Float32Array;
18
+ readonly z: Float32Array;
19
+ /** Where each internode starts (its parent's posed end). */
20
+ readonly baseX: Float32Array;
21
+ readonly baseY: Float32Array;
22
+ readonly baseZ: Float32Array;
23
+ /** How many internodes are visible. */
24
+ readonly visible: number;
25
+ readonly height: number;
26
+ /**
27
+ * How much bigger than life a grand tree has grown by now (the mean of taller and wider); 1 for a natural tree.
28
+ * Renderers grow leaf clumps with it.
29
+ */
30
+ readonly scale: number;
31
+ }
32
+ export interface FrameOptions {
33
+ /** World y of the ground where shed limbs come to rest. */
34
+ readonly ground?: number;
35
+ /**
36
+ * Grow a grand tree, a world tree: it keeps getting bigger all its life,
37
+ * slowing with age, until it stands GRAND times taller and wider than the
38
+ * natural tree, in its own species' way. `true` uses the species' own
39
+ * measure; a number scales how far past life it goes (1 is that measure).
40
+ */
41
+ readonly grand?: boolean | number;
42
+ }
43
+ /**
44
+ * How much bigger a grand tree of each kind grows than the natural one, upward
45
+ * and outward. Conifers and redwoods tower; acacias, oaks and willows spread
46
+ * wide; a palm only climbs; a baobab swells.
47
+ */
48
+ export declare const GRAND: Readonly<Record<SpeciesId, {
49
+ readonly up: number;
50
+ readonly out: number;
51
+ }>>;
52
+ interface Grandeur {
53
+ readonly up: number;
54
+ readonly out: number;
55
+ readonly girth: number;
56
+ }
57
+ export declare function grandAt(model: TreeModel, cycle: number, grand?: boolean | number): Grandeur;
58
+ /** Poses the tree at a cycle: what has grown, how thick it is, what is dead and what lies on the ground. */
59
+ export declare function treeFrame(model: TreeModel, cycle: number, options?: FrameOptions): TreeFrame;
60
+ export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Self-organizing tree growth, yearly phenology and slow decline for voxel
3
+ * trees. Deterministic and renderer-free: a seed and a species become a branch
4
+ * graph that a scene can pose at any moment of the tree's life. MIT.
5
+ *
6
+ * Growth follows Palubicki et al. 2009 ("Self-organizing tree models for image
7
+ * synthesis"): buds compete for light in a shadow grid, light flows down the
8
+ * branches and vigor flows back up with apical control (Borchert–Honda), so
9
+ * the crown fills the space it can reach, shaded limbs die and drop, and the
10
+ * trunk thickens by the pipe model.
11
+ */
12
+ export { SPECIES, SPECIES_IDS, speciesOf } from "./species.js";
13
+ export type { SpeciesId, Hemisphere, PhenologySpec, OrnamentKind, OrnamentSpec, PalmSpec, Species } from "./species.js";
14
+ export { createRandom } from "./math.js";
15
+ export { mixShares, blendSpecies, growTree, kindOrnaments, PACE, cycleAt } from "./model.js";
16
+ export { sectors } from "./sectors.js";
17
+ export type { TreeModel, LeafSlots, GrowInput, KindOrnament, Pace } from "./model.js";
18
+ export { GRAND, grandAt, treeFrame } from "./frame.js";
19
+ export type { TreeFrame, FrameOptions } from "./frame.js";
20
+ export { WOOD_SAG, bendFrame } from "./bend.js";
21
+ export type { Load, BendInto } from "./bend.js";
22
+ export { yearState } from "./year.js";
23
+ export type { Climate, YearInput, YearState } from "./year.js";
@@ -0,0 +1,13 @@
1
+ import type { Vec } from "./math.js";
2
+ export declare const GRID_X = 84;
3
+ export declare const GRID_Y = 96;
4
+ /** The shadow-propagation light field: each internode darkens a pyramid below it. */
5
+ export interface LightGrid {
6
+ readonly shadow: Float32Array;
7
+ }
8
+ export declare function cellOf(p: Vec): number;
9
+ export declare function castShadow(grid: LightGrid, p: Vec, sign: number): void;
10
+ /** Exposure of a bud in [0, 1]: its own internode's shadow does not count. */
11
+ export declare function exposure(grid: LightGrid, p: Vec): number;
12
+ /** The direction of least shadow around `p`, leaning up. */
13
+ export declare function lightDirection(grid: LightGrid, p: Vec): Vec;
@@ -0,0 +1,19 @@
1
+ export declare function createRandom(seed: number): () => number;
2
+ export declare const clamp01: (value: number) => number;
3
+ export declare const ramp: (value: number, start: number, end: number) => number;
4
+ export declare const smooth: (value: number) => number;
5
+ export declare const at: (values: ArrayLike<number>, index: number) => number;
6
+ export interface Vec {
7
+ x: number;
8
+ y: number;
9
+ z: number;
10
+ }
11
+ export declare const vec: (x: number, y: number, z: number) => Vec;
12
+ export declare const add: (a: Vec, b: Vec, scale?: number) => Vec;
13
+ export declare const lengthOf: (a: Vec) => number;
14
+ export declare const cross: (a: Vec, b: Vec) => Vec;
15
+ export declare function normalize(a: Vec, fallback?: Vec): Vec;
16
+ /** Rotates `v` about the unit `axis` by `angle` radians (Rodrigues). */
17
+ export declare function rotate(v: Vec, axis: Vec, angle: number): Vec;
18
+ /** Any unit vector perpendicular to `a`. */
19
+ export declare function perpendicular(a: Vec): Vec;
@@ -0,0 +1,100 @@
1
+ import type { OrnamentSpec, Species, SpeciesId } from "./species.js";
2
+ export interface TreeModel {
3
+ readonly species: Species;
4
+ readonly seed: number;
5
+ /** Cycles of the whole life; the tree is dead at `cycles`. */
6
+ readonly cycles: number;
7
+ /** Last cycle that adds wood; after it the tree declines. */
8
+ readonly matureAt: number;
9
+ readonly count: number;
10
+ readonly parent: Int32Array;
11
+ /** Grown positions, world units, trunk base at the origin. */
12
+ readonly x: Float32Array;
13
+ readonly y: Float32Array;
14
+ readonly z: Float32Array;
15
+ readonly order: Uint8Array;
16
+ /** An internode starts growing at `birth` and is full length `span` later. */
17
+ readonly birth: Float32Array;
18
+ readonly span: Float32Array;
19
+ readonly deadAt: Float32Array;
20
+ readonly shedAt: Float32Array;
21
+ /** Wind phase per internode. */
22
+ readonly phase: Float32Array;
23
+ readonly leaves: LeafSlots;
24
+ /** Flower places (blossoms, catkins, candles, puffs); empty when the species has none. */
25
+ readonly blossoms: LeafSlots;
26
+ /** Fruit places (cherries, acorns, cones, pods). */
27
+ readonly fruit: LeafSlots;
28
+ /** Root flare: angle and reach of each surface root. */
29
+ readonly roots: readonly {
30
+ readonly angle: number;
31
+ readonly reach: number;
32
+ }[];
33
+ }
34
+ /** Leaf or blossom places, each tied to a node with a fixed offset and a rank for the year's timing. */
35
+ export interface LeafSlots {
36
+ readonly count: number;
37
+ readonly node: Int32Array;
38
+ readonly dx: Float32Array;
39
+ readonly dy: Float32Array;
40
+ readonly dz: Float32Array;
41
+ readonly rank: Float32Array;
42
+ readonly size: Float32Array;
43
+ readonly tone: Uint8Array;
44
+ }
45
+ export interface GrowInput {
46
+ /** A species id; anything else grows a cherry. */
47
+ readonly species: string;
48
+ readonly seed: number;
49
+ readonly maxNodes?: number;
50
+ /**
51
+ * A hybrid: each species' share of the tree's makeup (any positive weights;
52
+ * they are normalised). The tree grows a form between them by share; the
53
+ * largest share decides what cannot be halved (a palm's way of growing,
54
+ * whorls, flowers, fruit, evergreen). `species` is ignored when it is set.
55
+ */
56
+ readonly mix?: Readonly<Record<string, number>>;
57
+ }
58
+ /** The species' shares in a mix, largest first, unknown ids and non-positive weights dropped, summing to 1. */
59
+ export declare function mixShares(mix: Readonly<Record<string, number>>): [SpeciesId, number][];
60
+ /**
61
+ * A hybrid species: every measure of form is the shares' weighted mean (an
62
+ * 80/20 cherry-oak is mostly a cherry's crown with an oak's broader reach and
63
+ * flatter limbs); what has no middle comes from the major share.
64
+ */
65
+ export declare function blendSpecies(mix: Readonly<Record<string, number>>): Species;
66
+ /** Grows one tree from its seed. The same species and seed always give the same tree. */
67
+ export declare function growTree(input: GrowInput): TreeModel;
68
+ /** One kind's flowers or fruit: what they are and where they hang. */
69
+ export interface KindOrnament {
70
+ readonly spec: OrnamentSpec;
71
+ readonly slots: LeafSlots;
72
+ }
73
+ /**
74
+ * A hybrid's minor kind bears its own flowers and fruit on the limbs it holds
75
+ * (`kinds` from `sectors`): cherry limbs on an oak blossom though the oak only
76
+ * hangs catkins. Places follow the kind's own spec; a renderer opens them on
77
+ * that kind's calendar. Null where the kind has none.
78
+ */
79
+ export declare function kindOrnaments(model: TreeModel, species: string, kinds: ArrayLike<number>, kind: number): {
80
+ readonly flower: KindOrnament | null;
81
+ readonly fruit: KindOrnament | null;
82
+ };
83
+ /**
84
+ * How a species spends its life, as shares of the lifespan: by `prime` it is
85
+ * most of its way grown, getting there fastest while young (`quick`
86
+ * front-loads it); it then keeps growing, more slowly, until `old`, near the
87
+ * very end, when the decline begins.
88
+ */
89
+ export interface Pace {
90
+ readonly prime: number;
91
+ readonly quick: number;
92
+ readonly old: number;
93
+ }
94
+ export declare const PACE: Readonly<Record<SpeciesId, Pace>>;
95
+ /**
96
+ * The growth cycle at an age: a fresh sprout at birth, quick when young, then
97
+ * less and less each year on one curve until old age, then the decline to death.
98
+ * By `prime` most of the crown is there; it never stops filling out before `old`.
99
+ */
100
+ export declare function cycleAt(model: TreeModel, ageYears: number, lifespanYears: number): number;
@@ -0,0 +1,10 @@
1
+ import type { TreeModel } from "./model.js";
2
+ /**
3
+ * Splits a grown tree into sectors, the way a chimera plant carries whole
4
+ * limbs of different tissue: each main limb (and everything it carries) goes
5
+ * to one strain, so that each strain's share of the crown's leaves is close
6
+ * to its share in `shares`. Strain 0, the first, keeps the trunk. Returns the
7
+ * strain of every internode. A strain with too small a share for any limb
8
+ * still gets the smallest one, so a trace of hidden makeup always shows.
9
+ */
10
+ export declare function sectors(model: TreeModel, shares: readonly number[], seed?: number): Uint8Array;
@@ -0,0 +1,58 @@
1
+ import type { Species } from "./species.js";
2
+ import type { Vec } from "./math.js";
3
+ import type { LightGrid } from "./light.js";
4
+ /** Growing tree state, as parallel arrays so the graph stays flat and ordered. */
5
+ export interface Sim {
6
+ readonly species: Species;
7
+ readonly random: () => number;
8
+ readonly grid: LightGrid;
9
+ readonly maxNodes: number;
10
+ readonly pos: Vec[];
11
+ readonly dir: Vec[];
12
+ readonly parent: number[];
13
+ readonly order: number[];
14
+ readonly birth: number[];
15
+ readonly span: number[];
16
+ readonly main: number[];
17
+ readonly deadAt: number[];
18
+ readonly shedAt: number[];
19
+ readonly weak: number[];
20
+ readonly children: number[][];
21
+ readonly buds: Bud[];
22
+ readonly nodeBuds: number[][];
23
+ height: number;
24
+ }
25
+ interface Bud {
26
+ readonly node: number;
27
+ readonly dir: Vec;
28
+ readonly terminal: boolean;
29
+ alive: boolean;
30
+ light: number;
31
+ vigor: number;
32
+ }
33
+ /** A fresh internode: where it ends, which way it heads, its order, when it grows and whether it carries the axis. */
34
+ export interface NewNode {
35
+ readonly pos: Vec;
36
+ readonly dir: Vec;
37
+ readonly order: number;
38
+ readonly birth: number;
39
+ readonly span: number;
40
+ readonly main: boolean;
41
+ }
42
+ export declare function addNode(sim: Sim, parent: number, node: NewNode): number;
43
+ export declare function addBud(sim: Sim, node: number, dir: Vec, terminal: boolean): void;
44
+ /** What a cycle has to grow with: how vigour is scaled, the shade a branch starves under, and the wood allowed. */
45
+ export interface CycleBudget {
46
+ readonly vigorScale: number;
47
+ readonly shed: number;
48
+ readonly allowed: number;
49
+ }
50
+ /**
51
+ * One cycle of growth. `allowed` is how many internodes the growth curve
52
+ * grants this cycle; when the buds want more, every shoot is trimmed by the
53
+ * same share (rounded at random), so no part of the crown is favoured.
54
+ */
55
+ export declare function growCycle(sim: Sim, cycle: number, budget: CycleBudget): void;
56
+ /** Old age: vigor fades, the top dies back, then limb after limb, until the tree stands dead. */
57
+ export declare function declineCycle(sim: Sim, cycle: number, decline: number): void;
58
+ export {};
@@ -0,0 +1,117 @@
1
+ export type SpeciesId = "cherry" | "oak" | "pine" | "birch" | "willow" | "acacia" | "palm" | "spruce" | "redwood" | "maple" | "jacaranda" | "baobab" | "apple" | "pear" | "peach" | "plum" | "orange" | "lemon" | "fig" | "mango";
2
+ export type Hemisphere = "north" | "south" | "equatorial";
3
+ /**
4
+ * Day windows of one year, counted in a year that starts on day 60 (early
5
+ * March in the north), so every window is a plain [start, end] with no wrap.
6
+ */
7
+ export interface PhenologySpec {
8
+ /** Leaves break bud at [0] and are full size at [1]. */
9
+ readonly leaf: readonly [number, number];
10
+ /** Autumn color starts at [0] and is complete at [1]. */
11
+ readonly color: readonly [number, number];
12
+ /** Leaf fall starts at [0] and ends at [1]. */
13
+ readonly drop: readonly [number, number];
14
+ /** Share of leaves that fall each year; evergreens only shed old needles. */
15
+ readonly dropMax: number;
16
+ /** Fresh spring growth is brightest at [0] and has hardened by [1]. */
17
+ readonly flush: readonly [number, number];
18
+ /** Share of dead leaves that hang on through winter until new leaves push them off (oak). */
19
+ readonly marcescent: number;
20
+ }
21
+ export type OrnamentKind = "blossom" | "catkin" | "candle" | "puff" | "spadix" | "cherry" | "acorn" | "cone" | "pod" | "coconut" | "samara" | "bell" | "gourd" | "apple" | "pear" | "peach" | "plum" | "orange" | "lemon" | "fig" | "mango";
22
+ /** Flowers or fruit: what they are, where they grow and when. */
23
+ export interface OrnamentSpec {
24
+ readonly kind: OrnamentKind;
25
+ /** "spur" on short older wood, "tip" on this year's leafy twigs. */
26
+ readonly on: "spur" | "tip";
27
+ readonly perNode: number;
28
+ /** They appear over days [0, 1] and fall over [2, 3], in the year that starts on day 60. */
29
+ readonly window: readonly [number, number, number, number];
30
+ /** First growth cycle at which the tree is old enough to bear them. */
31
+ readonly from: number;
32
+ /** Only above this share of the grown height (spruce cones hang from the top tiers). */
33
+ readonly above?: number;
34
+ }
35
+ /**
36
+ * Palms never branch. The trunk grows only from its crown, at one girth all
37
+ * its life, and the crown unfolds a few fronds each cycle while the oldest
38
+ * die and drop.
39
+ */
40
+ export interface PalmSpec {
41
+ /** New fronds each cycle. */
42
+ readonly fronds: number;
43
+ /** Frond length, in internode lengths. */
44
+ readonly frond: number;
45
+ /** Cycles a frond lives before it browns and drops. */
46
+ readonly frondLife: number;
47
+ /** Trunk radius, world units. */
48
+ readonly trunk: number;
49
+ /** How far the trunk leans out before it curves back up. */
50
+ readonly lean: number;
51
+ }
52
+ export interface Species {
53
+ readonly id: SpeciesId;
54
+ /** Growth cycles over a whole lifespan, decline included. */
55
+ readonly cycles: number;
56
+ /** World height of the grown tree. */
57
+ readonly height: number;
58
+ /** Apical control λ: the share of vigor the continuing axis keeps. */
59
+ readonly apical: number;
60
+ /** Vigor per unit of light reaching the base (α). */
61
+ readonly vigor: number;
62
+ /** Most internodes one bud can make in one cycle. */
63
+ readonly maxShoot: number;
64
+ /** Most internodes a side bud can make in one cycle (short in conifers). */
65
+ readonly sideShoot: number;
66
+ /** Side shoots leave their axis at this angle, degrees. */
67
+ readonly angle: number;
68
+ /** Phyllotaxis: each lateral bud turns this far round the axis, degrees. */
69
+ readonly divergence: number;
70
+ /** When above 0, side buds sit only at a shoot's end, in whorls of this many. */
71
+ readonly whorl: number;
72
+ /** Weight of the shoot's own heading. */
73
+ readonly straight: number;
74
+ /** Weight toward the open sky (phototropism). */
75
+ readonly light: number;
76
+ /** Gravitropism on the leader. */
77
+ readonly up: number;
78
+ /** Gravitropism on side shoots. */
79
+ readonly lateralUp: number;
80
+ /** Twigs from the second order on hang down by this much: weeping. */
81
+ readonly weep: number;
82
+ /** Pull of side shoots toward horizontal (plagiotropism). */
83
+ readonly flat: number;
84
+ /** Share of the current height kept clear of side shoots on the trunk. */
85
+ readonly crownAt: number;
86
+ /** Self-pruning: limbs on the trunk below this share of the height die and drop as the tree rises (redwood). */
87
+ readonly lift?: number;
88
+ /** Widest crown radius as a share of the tree's height; light fades past it. */
89
+ readonly spread: number;
90
+ /** How far that reach narrows toward the top: 0 keeps it, 1 closes it to a spire (spruce, redwood). */
91
+ readonly cone?: number;
92
+ /** Height, in internodes, where the leader gives up and the crown spreads flat. */
93
+ readonly ceiling: number;
94
+ /** Average bud light under which a branch starves and dies. */
95
+ readonly shed: number;
96
+ /** Leaves around each leafy node. */
97
+ readonly leafSlots: number;
98
+ /** Radius of a node's leaf cluster, world units. */
99
+ readonly leafSpread: number;
100
+ /** Leaves hang in curtains this long below each twig (weeping), world units. */
101
+ readonly hang: number;
102
+ /** Flowers, or null for none worth drawing. */
103
+ readonly flower: OrnamentSpec | null;
104
+ /** Fruit and seed, or null. */
105
+ readonly fruit: OrnamentSpec | null;
106
+ readonly evergreen: boolean;
107
+ /** Grows as a palm instead of a branching tree, or null. */
108
+ readonly palm: PalmSpec | null;
109
+ /** Radius of a one-year twig, world units. */
110
+ readonly radiusTip: number;
111
+ /** Pipe-model exponent: radius^pipe is the sum of the tips it carries. */
112
+ readonly pipe: number;
113
+ readonly phenology: PhenologySpec;
114
+ }
115
+ export { SPECIES } from "./species.data.js";
116
+ export declare const SPECIES_IDS: SpeciesId[];
117
+ export declare function speciesOf(id: string): Species;
@@ -0,0 +1,2 @@
1
+ import type { Species, SpeciesId } from "./species.js";
2
+ export declare const SPECIES: Readonly<Record<SpeciesId, Species>>;
@@ -0,0 +1,38 @@
1
+ import type { Hemisphere } from "./species.js";
2
+ export type Climate = "temperate" | "maritime" | "alpine" | "monsoon" | "highland" | "desert";
3
+ export interface YearInput {
4
+ /** A species id; anything else grows a cherry. */
5
+ readonly species: string;
6
+ /** Day of the year, 1–366, at the tree. */
7
+ readonly day: number;
8
+ readonly year?: number;
9
+ readonly hemisphere?: Hemisphere;
10
+ readonly climate?: string;
11
+ }
12
+ /** What the year is doing to the crown, every value in [0, 1]. */
13
+ export interface YearState {
14
+ /** Share of flowers open. */
15
+ readonly bloom: number;
16
+ /** Share of flowers that have dropped. */
17
+ readonly petals: number;
18
+ /** Share of fruit set and growing. */
19
+ readonly fruit: number;
20
+ /** Share of fruit that has fallen. */
21
+ readonly fruitDrop: number;
22
+ /** Leaves still on the tree are dead and brown (winter-held oak leaves). */
23
+ readonly withered: boolean;
24
+ /** Leaf size: 0 a closed bud, 1 full grown. */
25
+ readonly leaf: number;
26
+ /** Autumn color mix. */
27
+ readonly color: number;
28
+ /** Share of leaves that have fallen. */
29
+ readonly drop: number;
30
+ /** Share of fallen leaves still lying on the ground. */
31
+ readonly litter: number;
32
+ /** Fresh pale green of new growth. */
33
+ readonly flush: number;
34
+ /** The tree is bare and resting. */
35
+ readonly dormant: boolean;
36
+ }
37
+ /** Where the year stands for a species at a place: bud, blossom, leaf, color and fall. */
38
+ export declare function yearState(input: YearInput): YearState;
@@ -0,0 +1 @@
1
+ export * from './tree-growth/index.js'
@@ -0,0 +1,75 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "species",
6
+ "label": "Species",
7
+ "required": false,
8
+ "type": "select",
9
+ "options": [
10
+ {
11
+ "value": "cherry",
12
+ "label": "Cherry"
13
+ },
14
+ {
15
+ "value": "oak",
16
+ "label": "Oak"
17
+ },
18
+ {
19
+ "value": "pine",
20
+ "label": "Pine"
21
+ },
22
+ {
23
+ "value": "birch",
24
+ "label": "Birch"
25
+ },
26
+ {
27
+ "value": "willow",
28
+ "label": "Willow"
29
+ },
30
+ {
31
+ "value": "acacia",
32
+ "label": "Acacia"
33
+ },
34
+ {
35
+ "value": "palm",
36
+ "label": "Coconut palm"
37
+ },
38
+ {
39
+ "value": "spruce",
40
+ "label": "Blue spruce"
41
+ },
42
+ {
43
+ "value": "redwood",
44
+ "label": "Redwood"
45
+ },
46
+ {
47
+ "value": "maple",
48
+ "label": "Maple"
49
+ },
50
+ {
51
+ "value": "jacaranda",
52
+ "label": "Jacaranda"
53
+ },
54
+ {
55
+ "value": "baobab",
56
+ "label": "Baobab"
57
+ }
58
+ ],
59
+ "default": "cherry"
60
+ },
61
+ {
62
+ "key": "maxNodes",
63
+ "label": "Internode budget",
64
+ "required": false,
65
+ "help": "More internodes make a finer crown and cost more to grow and draw.",
66
+ "placement": "advanced",
67
+ "type": "number",
68
+ "min": 64,
69
+ "max": 6000,
70
+ "step": 8,
71
+ "control": "slider",
72
+ "default": 4800
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,2 @@
1
+ // tree-growth@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var e={marcescent:0,leaf:[100,132],color:[258,294],drop:[280,318],dropMax:1,flush:[104,160]},t={leaf:[60,61],color:[300,330],drop:[300,340],dropMax:.08,flush:[110,160],marcescent:0},r={cherry:{id:"cherry",cycles:26,height:8.6,apical:.5,vigor:2.1,maxShoot:3,sideShoot:3,angle:44,divergence:137.5,whorl:0,straight:1,light:.4,up:.45,lateralUp:.12,weep:.03,flat:.12,spread:.52,crownAt:.32,ceiling:1/0,shed:.2,leafSlots:4,leafSpread:.34,hang:0,flower:{kind:"blossom",on:"spur",perNode:3,window:[86,97,101,116],from:4},fruit:{kind:"cherry",on:"spur",perNode:2,window:[130,156,166,188],from:5},evergreen:!1,palm:null,radiusTip:.025,pipe:2.75,phenology:{...e,leaf:[100,130]}},oak:{id:"oak",cycles:30,height:10.2,apical:.46,vigor:2.2,maxShoot:3,sideShoot:3,angle:56,divergence:137.5,whorl:0,straight:.9,light:.45,up:.32,lateralUp:.02,weep:.02,flat:.28,spread:.5,crownAt:.28,ceiling:1/0,shed:.18,leafSlots:4,leafSpread:.36,hang:0,flower:{kind:"catkin",on:"tip",perNode:2,window:[108,120,130,146],from:7},fruit:{kind:"acorn",on:"tip",perNode:1,window:[190,250,268,300],from:9},evergreen:!1,palm:null,radiusTip:.027,pipe:2.65,phenology:{...e,leaf:[112,146],color:[268,304],drop:[290,334],marcescent:.22}},pine:{id:"pine",cycles:28,height:11.2,apical:.7,vigor:2.1,maxShoot:3,sideShoot:2,angle:66,divergence:137.5,whorl:4,straight:1,light:.3,up:1.1,lateralUp:.06,weep:0,flat:.38,spread:.52,crownAt:.3,lift:.28,ceiling:1/0,shed:.18,leafSlots:3,leafSpread:.3,hang:0,flower:{kind:"candle",on:"tip",perNode:1,window:[112,134,158,176],from:2},fruit:{kind:"cone",on:"spur",perNode:1,window:[140,250,330,420],from:6},evergreen:!0,palm:null,radiusTip:.023,pipe:2.85,phenology:{leaf:[60,61],color:[262,300],drop:[270,310],dropMax:.14,flush:[126,176],marcescent:0}},birch:{id:"birch",cycles:26,height:9.6,apical:.62,vigor:2,maxShoot:3,sideShoot:3,angle:40,divergence:137.5,whorl:0,straight:1.1,light:.32,up:.7,lateralUp:.02,weep:.14,flat:.06,spread:.4,crownAt:.36,ceiling:1/0,shed:.21,leafSlots:4,leafSpread:.3,hang:.3,flower:{kind:"catkin",on:"tip",perNode:2,window:[88,100,112,128],from:5},fruit:null,evergreen:!1,palm:null,radiusTip:.022,pipe:2.85,phenology:{...e,leaf:[98,124],color:[246,280],drop:[266,302]}},willow:{id:"willow",cycles:24,height:8.2,apical:.45,vigor:2.1,maxShoot:3,sideShoot:3,angle:50,divergence:137.5,whorl:0,straight:.8,light:.16,up:.5,lateralUp:.3,weep:.3,flat:0,spread:.5,crownAt:.3,ceiling:1/0,shed:.09,leafSlots:9,leafSpread:.28,hang:1.5,flower:{kind:"catkin",on:"tip",perNode:2,window:[66,78,92,106],from:3},fruit:null,evergreen:!1,palm:null,radiusTip:.023,pipe:2.65,phenology:{...e,leaf:[84,110],color:[272,302],drop:[290,326]}},acacia:{id:"acacia",cycles:22,height:7.4,apical:.4,vigor:2.1,maxShoot:3,sideShoot:3,angle:48,divergence:137.5,whorl:0,straight:.9,light:.3,up:.6,lateralUp:.26,weep:0,flat:.5,spread:.66,crownAt:.46,ceiling:15,shed:.18,leafSlots:4,leafSpread:.34,hang:0,flower:{kind:"puff",on:"tip",perNode:2,window:[268,284,298,318],from:3},fruit:{kind:"pod",on:"tip",perNode:1,window:[300,334,380,420],from:4},evergreen:!1,palm:null,radiusTip:.027,pipe:2.55,phenology:{leaf:[60,61],color:[236,280],drop:[250,296],dropMax:.42,flush:[300,340],marcescent:0}},palm:{id:"palm",cycles:30,height:12.5,apical:1,vigor:1,maxShoot:1,sideShoot:0,angle:0,divergence:137.5,whorl:0,straight:1,light:0,up:1,lateralUp:0,weep:0,flat:0,spread:.3,crownAt:0,ceiling:1/0,shed:0,leafSlots:24,leafSpread:.62,hang:.4,flower:{kind:"spadix",on:"spur",perNode:2,window:[100,128,150,176],from:5},fruit:{kind:"coconut",on:"spur",perNode:3,window:[60,61,400,424],from:6},evergreen:!0,palm:{fronds:4,frond:17,frondLife:2.6,trunk:.24,lean:.45},radiusTip:.02,pipe:2.5,phenology:{leaf:[60,61],color:[300,330],drop:[300,340],dropMax:.08,flush:[120,170],marcescent:0}},spruce:{id:"spruce",cycles:30,height:10.4,apical:.86,vigor:2,maxShoot:3,sideShoot:2,angle:78,divergence:137.5,whorl:6,straight:1.1,light:.18,up:1.6,lateralUp:-.08,weep:.12,flat:.62,spread:.34,cone:.97,crownAt:0,ceiling:1/0,shed:.05,leafSlots:3,leafSpread:.32,hang:0,flower:{kind:"candle",on:"tip",perNode:1,window:[118,136,150,166],from:3},fruit:{kind:"cone",on:"spur",perNode:1,window:[150,250,320,400],from:7,above:.7},evergreen:!0,palm:null,radiusTip:.022,pipe:2.8,phenology:{leaf:[60,61],color:[262,300],drop:[270,310],dropMax:.1,flush:[130,178],marcescent:0}},redwood:{id:"redwood",cycles:34,height:15,apical:.9,vigor:2.5,maxShoot:3,sideShoot:2,angle:82,divergence:137.5,whorl:0,straight:1.2,light:.16,up:1.7,lateralUp:-.22,weep:-.16,flat:.3,spread:.28,cone:.7,crownAt:.42,lift:.4,ceiling:1/0,shed:.16,leafSlots:6,leafSpread:.24,hang:0,flower:null,fruit:{kind:"cone",on:"tip",perNode:1,window:[120,230,300,380],from:8},evergreen:!0,palm:null,radiusTip:.03,pipe:1.85,phenology:{leaf:[60,61],color:[262,300],drop:[270,310],dropMax:.12,flush:[128,176],marcescent:0}},maple:{id:"maple",cycles:28,height:9.4,apical:.48,vigor:2.2,maxShoot:3,sideShoot:3,angle:42,divergence:90,whorl:0,straight:1,light:.4,up:.42,lateralUp:.14,weep:.02,flat:.1,spread:.52,crownAt:.26,ceiling:1/0,shed:.2,leafSlots:5,leafSpread:.36,hang:0,flower:{kind:"puff",on:"tip",perNode:1,window:[76,88,98,110],from:5},fruit:{kind:"samara",on:"tip",perNode:2,window:[112,170,256,300],from:6},evergreen:!1,palm:null,radiusTip:.025,pipe:2.7,phenology:{...e,leaf:[104,134],color:[250,282],drop:[272,308]}},jacaranda:{id:"jacaranda",cycles:22,height:8.4,apical:.42,vigor:2.1,maxShoot:3,sideShoot:3,angle:46,divergence:137.5,whorl:0,straight:.9,light:.36,up:.5,lateralUp:.22,weep:.06,flat:.3,spread:.6,crownAt:.36,ceiling:18,shed:.18,leafSlots:5,leafSpread:.34,hang:0,flower:{kind:"blossom",on:"tip",perNode:3,window:[104,118,138,158],from:4},fruit:{kind:"pod",on:"tip",perNode:1,window:[150,210,340,410],from:5},evergreen:!1,palm:null,radiusTip:.024,pipe:2.6,phenology:{leaf:[60,61],color:[326,356],drop:[338,376],dropMax:.6,flush:[124,164],marcescent:0}},baobab:{id:"baobab",cycles:30,height:8.2,apical:.36,vigor:2.2,maxShoot:2,sideShoot:2,angle:54,divergence:137.5,whorl:0,straight:.9,light:.3,up:.6,lateralUp:.34,weep:0,flat:.34,spread:.46,crownAt:.6,ceiling:13,shed:.16,leafSlots:3,leafSpread:.32,hang:0,flower:{kind:"bell",on:"tip",perNode:1,window:[128,142,150,166],from:6},fruit:{kind:"gourd",on:"tip",perNode:1,window:[150,230,340,420],from:8},evergreen:!1,palm:null,radiusTip:.03,pipe:2.05,phenology:{...e,leaf:[122,150],color:[252,282],drop:[262,296]}},apple:{id:"apple",cycles:26,height:7,apical:.44,vigor:2.1,maxShoot:3,sideShoot:3,angle:52,divergence:137.5,whorl:0,straight:.9,light:.4,up:.38,lateralUp:.06,weep:.06,flat:.22,spread:.6,crownAt:.3,ceiling:1/0,shed:.2,leafSlots:4,leafSpread:.34,hang:0,flower:{kind:"blossom",on:"spur",perNode:3,window:[112,122,128,142],from:4},fruit:{kind:"apple",on:"spur",perNode:1,window:[150,240,262,300],from:5},evergreen:!1,palm:null,radiusTip:.026,pipe:2.6,phenology:{...e,leaf:[108,136]}},pear:{id:"pear",cycles:28,height:9,apical:.5,vigor:2.2,maxShoot:3,sideShoot:3,angle:38,divergence:137.5,whorl:0,straight:1,light:.4,up:.5,lateralUp:.18,weep:.02,flat:.06,spread:.46,crownAt:.26,ceiling:1/0,shed:.16,leafSlots:4,leafSpread:.32,hang:0,flower:{kind:"blossom",on:"spur",perNode:3,window:[88,96,104,118],from:5},fruit:{kind:"pear",on:"spur",perNode:1,window:[150,230,252,280],from:6},evergreen:!1,palm:null,radiusTip:.025,pipe:2.7,phenology:{...e,leaf:[104,132],color:[270,300],drop:[288,322]}},peach:{id:"peach",cycles:20,height:5.8,apical:.38,vigor:2.1,maxShoot:3,sideShoot:3,angle:50,divergence:137.5,whorl:0,straight:.9,light:.4,up:.45,lateralUp:.24,weep:.02,flat:.2,spread:.66,crownAt:.26,ceiling:16,shed:.2,leafSlots:5,leafSpread:.3,hang:0,flower:{kind:"blossom",on:"spur",perNode:2,window:[84,94,100,112],from:3},fruit:{kind:"peach",on:"tip",perNode:1,window:[150,196,230,250],from:3},evergreen:!1,palm:null,radiusTip:.024,pipe:2.6,phenology:{...e,leaf:[100,128]}},plum:{id:"plum",cycles:24,height:6.8,apical:.5,vigor:2.1,maxShoot:3,sideShoot:3,angle:42,divergence:137.5,whorl:0,straight:1,light:.4,up:.5,lateralUp:.14,weep:.04,flat:.12,spread:.5,crownAt:.3,ceiling:1/0,shed:.2,leafSlots:4,leafSpread:.32,hang:0,flower:{kind:"blossom",on:"spur",perNode:3,window:[80,90,95,108],from:3},fruit:{kind:"plum",on:"spur",perNode:2,window:[160,208,236,258],from:4},evergreen:!1,palm:null,radiusTip:.024,pipe:2.7,phenology:{...e,leaf:[98,128]}},orange:{id:"orange",cycles:26,height:6.6,apical:.42,vigor:2.1,maxShoot:3,sideShoot:3,angle:46,divergence:137.5,whorl:0,straight:.9,light:.36,up:.4,lateralUp:.1,weep:.05,flat:.1,spread:.56,crownAt:.14,ceiling:1/0,shed:.08,leafSlots:5,leafSpread:.32,hang:0,flower:{kind:"blossom",on:"tip",perNode:2,window:[90,104,116,132],from:4},fruit:{kind:"orange",on:"tip",perNode:1,window:[160,300,400,424],from:5},evergreen:!0,palm:null,radiusTip:.024,pipe:2.6,phenology:t},lemon:{id:"lemon",cycles:24,height:5.6,apical:.4,vigor:2.1,maxShoot:3,sideShoot:3,angle:50,divergence:137.5,whorl:0,straight:.85,light:.38,up:.42,lateralUp:.16,weep:.06,flat:.12,spread:.56,crownAt:.18,ceiling:1/0,shed:.12,leafSlots:5,leafSpread:.3,hang:0,flower:{kind:"blossom",on:"tip",perNode:2,window:[70,84,100,120],from:3},fruit:{kind:"lemon",on:"tip",perNode:1,window:[140,240,380,422],from:4},evergreen:!0,palm:null,radiusTip:.023,pipe:2.6,phenology:t},fig:{id:"fig",cycles:24,height:6.4,apical:.36,vigor:2.1,maxShoot:3,sideShoot:3,angle:54,divergence:137.5,whorl:0,straight:.85,light:.36,up:.4,lateralUp:.2,weep:0,flat:.3,spread:.7,crownAt:.2,ceiling:14,shed:.18,leafSlots:3,leafSpread:.46,hang:0,flower:null,fruit:{kind:"fig",on:"tip",perNode:2,window:[160,206,238,260],from:3},evergreen:!1,palm:null,radiusTip:.03,pipe:2.4,phenology:{...e,leaf:[110,140],color:[268,296],drop:[282,316]}},mango:{id:"mango",cycles:30,height:10,apical:.45,vigor:2.2,maxShoot:3,sideShoot:3,angle:48,divergence:137.5,whorl:0,straight:.9,light:.38,up:.45,lateralUp:.08,weep:.06,flat:.14,spread:.6,crownAt:.26,ceiling:1/0,shed:.1,leafSlots:5,leafSpread:.36,hang:.1,flower:{kind:"puff",on:"tip",perNode:2,window:[64,80,92,108],from:5},fruit:{kind:"mango",on:"tip",perNode:1,window:[130,176,232,254],from:6},evergreen:!0,palm:null,radiusTip:.026,pipe:2.55,phenology:t}},o=Object.keys(r);function a(e){return Object.hasOwn(r,e)?r[e]:r.cherry}function l(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}var n=e=>Math.min(1,Math.max(0,e)),i=(e,t,r)=>n((e-t)/Math.max(r-t,1e-6)),d=e=>e*e*(3-2*e),p=(e,t)=>e[t]??0,h=(e,t,r)=>({x:e,y:t,z:r}),s=(e,t,r=1)=>h(e.x+t.x*r,e.y+t.y*r,e.z+t.z*r),u=e=>Math.hypot(e.x,e.y,e.z),c=(e,t)=>h(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z,e.x*t.y-e.y*t.x);function f(e,t=h(0,1,0)){let r=u(e);return r<1e-9?t:h(e.x/r,e.y/r,e.z/r)}function g(e,t,r){let o=Math.cos(r),a=Math.sin(r),l=c(t,e),n=t.x*e.x+t.y*e.y+t.z*e.z;return h(e.x*o+l.x*a+t.x*n*(1-o),e.y*o+l.y*a+t.y*n*(1-o),e.z*o+l.z*a+t.z*n*(1-o))}function m(e){return f(Math.abs(e.y)<.9?c(e,h(0,1,0)):c(e,h(1,0,0)))}var w=84;function y(e){let t=Math.round(e.x)+42,r=Math.round(e.y)+2,o=Math.round(e.z)+42;return t<0||o<0||r<0||t>=w||o>=w||r>=96?-1:(r*w+o)*w+t}function x(e,t,r){let o=y(t);if(o<0)return;let a=o%w,l=Math.floor(o/w)%w,n=Math.floor(o/(w*w));for(let t=0;t<=7&&n-t>=0;t+=1){let o=r*1.75**-t,i=Math.min(t,3);for(let r=-i;r<=i;r+=1){let d=((n-t)*w+Math.min(83,Math.max(0,l+r)))*w;for(let t=-i;t<=i;t+=1){let r=d+Math.min(83,Math.max(0,a+t));e.shadow[r]=Math.max(0,p(e.shadow,r)+o)}}}}function M(e,t){let r=y(t);return r<0?8.4:p(e.shadow,r)}function v(e,t){return n((4.2-M(e,t)+1)/4.2)}function b(e,t){let r=(r,o,a)=>M(e,h(t.x+2*r,t.y+2*o,t.z+2*a)),o=h(r(1,0,0)-r(-1,0,0),r(0,1,0)-r(0,-1,0),r(0,0,1)-r(0,0,-1));return f(h(-o.x,.35-o.y,-o.z))}function S(e,t,r){let{pos:o,dir:a,order:l,birth:n,span:i,main:d}=r,p=e.pos.length;return e.pos.push(o),e.dir.push(a),e.parent.push(t),e.order.push(l),e.birth.push(n),e.span.push(i),e.main.push(d?1:0),e.deadAt.push(1/0),e.shedAt.push(1/0),e.weak.push(0),e.children.push([]),e.nodeBuds.push([]),e.children[t]?.push(p),e.height=Math.max(e.height,o.y),x(e.grid,o,1),p}function A(e,t,r,o){e.nodeBuds[t]?.push(e.buds.length),e.buds.push({node:t,dir:r,terminal:o,alive:!0,light:0,vigor:0})}function k(e,t,r,o){let{species:a,random:l}=e,{turn:n,end:i}=o,d=a.angle*Math.PI/180,u=m(r);if(a.whorl>0&&p(e.order,t)>0){if(!i)return;let o=f(c(r,h(0,1,0)),u);for(let a of[-1,1])A(e,t,f(s(h(.7*r.x,.7*r.y,.7*r.z),o,.7*a)),!1);return}if(a.whorl>0){if(!i)return;for(let o=0;o<a.whorl;o+=1){let i=n+o/a.whorl*Math.PI*2+.4*(l()-.5);A(e,t,f(g(g(r,u,d),r,i)),!1)}return}let w=n+.3*(l()-.5);A(e,t,f(g(g(r,u,d*(.85+.3*l())),r,w)),!1)}function z(e,t,r,o){let{species:a}=e,l=o>a.ceiling;if(0===r&&!l)return h(0,a.up,0);let n=f(h(t.x,0,t.z),h(1,0,0)),i=a.lateralUp-(r>=2?a.weep*Math.min(r-1,2):0),d=l?Math.max(a.flat,.6):a.flat;return h((n.x-t.x)*d,i+(l?-.1:0)+(n.y-t.y)*d,(n.z-t.z)*d)}function N(e,t,r,o){let{species:a}=e,l=t.node,n=t.dir,i=p(e.order,l)+(t.terminal?0:1),d=e.random()*Math.PI*2;for(let p=0;p<r&&e.pos.length<e.maxNodes;p+=1){let u=e.pos[l]??h(0,0,0),c=i>=2?a.light/(1+4*a.weep):a.light;n=f(s(s(h(n.x*a.straight,n.y*a.straight,n.z*a.straight),b(e.grid,u),c),z(e,n,i,u.y)),n);let g=s(u,n,.88+.24*e.random());if(g.y<.6||y(g)<0)return;l=S(e,l,{pos:g,dir:n,order:i,birth:o+p/r,span:1/r,main:t.terminal||p>0}),d+=a.divergence*Math.PI/180,k(e,l,n,{turn:d,end:p===r-1})}l!==t.node&&A(e,l,n,!0)}function F(e,t){let r=e.species.cone??0;return e.species.spread*Math.max(e.height,6)*(1-r*n(t/Math.max(e.height,1)))+.6*r}function U(e,t){let{light:r,budCount:o}=t;for(let t of e.buds){let r=e.pos[t.node]??h(0,0,0),o=F(e,r.y),a=n(1-(Math.hypot(r.x,r.z)-o)/1.5);t.light=t.alive?v(e.grid,r)*a:0}for(let t=e.pos.length-1;t>=0;t-=1){let a=0,l=0;for(let r of e.nodeBuds[t]??[]){let t=e.buds[r];!0===t?.alive&&(a+=t.light,l+=1)}for(let n of e.children[t]??[])p(e.deadAt,n)===1/0&&(a+=p(r,n),l+=p(o,n));r[t]=a,o[t]=l}}function q(e,t,r,o){let{light:a,incoming:l}=o,n=e.species.apical,i=[],d=[];for(let r of e.children[t]??[])p(e.deadAt,r)===1/0&&(1===p(e.main,r)?i:d).push([r,p(a,r)]);for(let r of e.nodeBuds[t]??[]){let t=e.buds[r];!0===t?.alive&&(t.terminal?i:d).push([-1-r,t.light])}let h=i.reduce((e,[,t])=>e+t,0),s=d.reduce((e,[,t])=>e+t,0),u=n*h+(1-n)*s;if(u<=0)return;let c=(t,r,o)=>{for(let[a,n]of t){let t=o>0?r*n/o:0;if(a>=0)l[a]=t;else{let r=e.buds[-1-a];void 0!==r&&(r.vigor=t)}}};c(i,r*n*h/u,h),c(d,r*(1-n)*s/u,s)}function T(e,t,r){let o=[t],a=0;for(;o.length>0;){let t=o.pop()??0;if(p(e.deadAt,t)===1/0){e.deadAt[t]=r,a+=1,x(e.grid,e.pos[t]??h(0,0,0),-1);for(let r of e.nodeBuds[t]??[]){let t=e.buds[r];void 0!==t&&(t.alive=!1)}o.push(...e.children[t]??[])}}e.shedAt[t]=r+.5+1.1*e.random()+.55*Math.log2(1+a)}function I(e,t,r){let{vigorScale:o,shed:a,allowed:l}=r,n={light:[],budCount:[]};(function(e){let t=e.species.crownAt*e.height;for(let r of e.buds)!r.alive||r.terminal||0===p(e.order,r.node)&&(e.pos[r.node]?.y??0)<t&&(r.alive=!1)})(e),U(e,n),function(e,t,r){let o=new Array(e.pos.length).fill(0);for(let t of e.buds)t.vigor=0;o[0]=e.species.vigor*r*p(t,0);let a={light:t,incoming:o};for(let t=0;t<e.pos.length;t+=1)p(e.deadAt,t)===1/0&&q(e,t,p(o,t),a)}(e,n.light,o);let i=function(e){let t=[];for(let r of e.buds){if(!r.alive)continue;let o=Math.min(r.terminal&&0===p(e.order,r.node)?e.species.maxShoot:e.species.sideShoot,Math.floor(r.vigor));o>=1&&t.push([r,o])}return t}(e),d=i.reduce((e,[,t])=>e+t,0),h=d>l?Math.max(0,l)/d:1;for(let[r,o]of i){let a=h<1?Math.floor(o*h+e.random()):o;a<1||(r.alive=!1,N(e,r,a,t))}(function(e,t,r,o){let{light:a,budCount:l}=t;for(let t=1;t<e.pos.length;t+=1){if(1===p(e.main,t)||p(e.deadAt,t)!==1/0)continue;let n=p(l,t),i=n>0?p(a,t)/n:0;e.weak[t]=i<o?p(e.weak,t)+1:0,p(e.weak,t)>=3&&r-p(e.birth,t)>1.5&&T(e,t,r)}})(e,n,t,a),function(e,t){let r=(e.species.lift??0)*e.height;if(!(r<=0))for(let o=1;o<e.pos.length;o+=1)1!==p(e.order,o)||0!==p(e.order,p(e.parent,o))||p(e.deadAt,o)===1/0&&(e.pos[o]?.y??0)<r&&e.random()<.5&&T(e,o,t)}(e,t)}function P(e,t,r){r>.3&&r<=.3+1/(.28*e.species.cycles)&&function(e,t){let r=function(e){let t=0,r=0;for(let o=0;o<e.pos.length;o+=1){let a=e.pos[o]?.y??0;0===p(e.order,o)&&a>r&&(t=o,r=a)}return t}(e);for(let t=0;t<6&&r>0;t+=1)r=p(e.parent,r);r>0&&(e.pos[r]?.y??0)>.6*e.height&&T(e,r,t)}(e,t),function(e,t,r){let o={light:[],budCount:[]};U(e,o);let{light:a,budCount:l}=o,n=[],i=0;for(let t=1;t<e.pos.length;t+=1){if(p(e.deadAt,t)!==1/0)continue;i+=1;let r=p(l,t);0===p(e.main,t)&&r>0&&r<40&&n.push([t,p(a,t)/r-.15*e.random()])}n.sort((e,t)=>e[1]-t[1]);let d=0;for(let[o]of n){if(d>=i*r)break;if(p(e.deadAt,o)!==1/0)continue;let a=e.deadAt.filter(e=>e!==1/0).length;T(e,o,t),d+=e.deadAt.filter(e=>e!==1/0).length-a}}(e,t,.03+r*r*.3),I(e,t,{vigorScale:Math.max(.3,1-.9*r),shed:e.species.shed+.2*r,allowed:O(e,r)})}function O(e,t){return.13*Math.max(0,e.maxNodes-e.pos.length)*(1-t)**1.1}function X(e){let t=Object.entries(e).filter(([e,t])=>Object.hasOwn(r,e)&&t>0),o=t.reduce((e,[,t])=>e+t,0);return o<=0?[["cherry",1]]:t.map(([e,t])=>[e,t/o]).sort((e,t)=>t[1]-e[1]||(e[0]<t[0]?-1:1))}function Z(e){let t=X(e),o=r[t[0]?.[0]??"cherry"];if(1===t.length||null!==o.palm)return o;let a=e=>((e,t)=>{let o=e.reduce((e,[o,a])=>e+Math.min(t(r[o]),60)*a,0);return e.some(([e])=>t(r[e])===1/0)&&o>=57?1/0:o})(t,e),l=e=>Math.max(1,Math.round(a(e))),n=e=>[a(t=>e(t)[0]),a(t=>e(t)[1])],i=t.every(([e])=>r[e].whorl>0==o.whorl>0),d=e=>i?l(e):e(o);return{...o,cycles:l(e=>e.cycles),height:a(e=>e.height),apical:a(e=>e.apical),vigor:a(e=>e.vigor),maxShoot:d(e=>e.maxShoot),sideShoot:d(e=>e.sideShoot),angle:a(e=>e.angle),straight:a(e=>e.straight),light:a(e=>e.light),up:a(e=>e.up),lateralUp:a(e=>e.lateralUp),weep:a(e=>e.weep),flat:a(e=>e.flat),crownAt:a(e=>e.crownAt),lift:Math.max(...t.map(([e])=>r[e].lift??0)),spread:a(e=>e.spread),cone:a(e=>e.cone??0),ceiling:a(e=>e.ceiling),shed:a(e=>e.shed),leafSlots:l(e=>e.leafSlots),leafSpread:a(e=>e.leafSpread),hang:a(e=>e.hang),radiusTip:a(e=>e.radiusTip),pipe:a(e=>e.pipe),phenology:{...o.phenology,marcescent:a(e=>e.phenology.marcescent),dropMax:a(e=>e.phenology.dropMax),leaf:n(e=>e.phenology.leaf),color:n(e=>e.phenology.color),drop:n(e=>e.phenology.drop),flush:n(e=>e.phenology.flush)}}}function Y(e,t,r){let o=Math.min(1,t/r),a=0;for(let t of e.deadAt)t===1/0&&(a+=1);let l=e.maxNodes*C*(.08+.92*o),n=e.maxNodes*j-e.pos.length;return Math.min(n,Math.max(l-a,.015*a))}var j=.84,C=.5;function B(e,t,r){let{around:o,length:a,cycle:l}=r,n=h(Math.cos(o),0,Math.sin(o)),i=1-.5*e.random(),d=1.6+.4*e.random(),p=t;for(let t=0;t<8;t+=1){let r=f(h(n.x,i-t/7*d,n.z));p=S(e,p,{pos:s(e.pos[p]??h(0,0,0),r,a/8),dir:r,order:1,birth:l+.03*t,span:.2,main:!1})}}function E(e,t,r,o){let a=(.2+.85*i(r,2,6))*o,l=t.top,n=t.heading;for(let t=0;t<2;t+=1)n=f(s(n,h(0,1,0),.05)),l=S(e,l,{pos:s(e.pos[l]??h(0,0,0),n,a),dir:n,order:0,birth:r-1+.5*t,span:.5,main:!0});return{top:l,heading:n}}function D(e,t,r){return{vigorScale:1+1.6/(1+.4*t),shed:e.species.shed,allowed:Y(e,t,r)}}var G=e=>({count:e.pos.length,palm:null!==e.species.palm,heading:t=>e.dir[t]??h(0,1,0)});function L(e,t,r){let{perNode:o,spread:a,hang:n}=t,i=l(t.seed),d=[];for(let t=0;t<e.count;t+=1)if(r(t))for(let e=0;e<o;e+=1)d.push(t);let h=d.length,s={count:h,node:Int32Array.from(d),dx:new Float32Array(h),dy:new Float32Array(h),dz:new Float32Array(h),rank:new Float32Array(h),size:new Float32Array(h),tone:new Uint8Array(h)},u={slots:s,spec:t,random:i};for(let t=0;t<h;t+=1){let r=e.heading(p(s.node,t));if(e.palm&&n>0){W(u,t,r);continue}let l=i()*Math.PI*2,d=2*i()-1,h=Math.sqrt(1-d*d)*Math.cbrt(i()),c=n>0?n*(t%o/o)*(.6+.4*i()):0;s.dx[t]=(Math.cos(l)*h+.45*r.x)*a*(c>0?.5:1),s.dy[t]=(.7*d+.45*r.y+.18)*a-c,s.dz[t]=(Math.sin(l)*h+.45*r.z)*a*(c>0?.5:1),s.rank[t]=i(),s.size[t]=.82+.36*i(),s.tone[t]=Math.floor(3*i())}return s}var R=(e,t)=>p(e.order,t)>0&&0===p(e.order,p(e.parent,t));function W(e,t,r){let{slots:o,random:a}=e,{spread:l,hang:n}=e.spec,i=f(c(r,h(0,1,0)),m(r)),d=t%2==0?1:-1,p=l*(.25+.75*a()),s=(a()-.5)*l*.6;o.dx[t]=i.x*d*p+r.x*s,o.dy[t]=i.y*d*p+r.y*s-n*(p/l)**2,o.dz[t]=i.z*d*p+r.z*s,o.rank[t]=a(),o.size[t]=.7+.3*a(),o.tone[t]=Math.floor(3*a())}function _(e,t,r,o){if(null===t)return L(G(e),{perNode:0,spread:0,hang:0,seed:0},()=>!1);let a=null!==e.species.palm,l=(t.above??0)*e.height;return L(G(e),{perNode:t.perNode,spread:r,hang:0,seed:o},t=>a?R(e,t):p(e.order,t)>0&&(e.pos[t]?.y??0)>=l)}function H(e){let t=e.mix?Z(e.mix):a(e.species),r=e.seed>>>0,o=function(e,t,r){let o=function(e,t,r){return{species:e,random:l(32485^t),grid:{shadow:new Float32Array(677376)},maxNodes:r,pos:[],dir:[],parent:[],order:[],birth:[],span:[],main:[],deadAt:[],shedAt:[],weak:[],children:[],buds:[],nodeBuds:[],height:0}}(e,t,r);if(null!==e.palm)return function(e,t){let{species:r,random:o}=e,a=o()*Math.PI*2,l=t.lean*(.6+.8*o()),n=f(h(Math.cos(a)*l,1,Math.sin(a)*l)),i={top:S(e,-1,{pos:h(0,.2,0),dir:n,order:0,birth:0,span:1,main:!0}),heading:n},d=Math.round(.72*r.cycles),s=o()*Math.PI*2;for(let a=1;a<r.cycles;a+=1){let l=Math.min(1,a/d),n=a>d?(a-d)/(r.cycles-d):0;i=E(e,i,a,1-.75*n);let p=Math.max(1,Math.round(t.fronds*(1-.6*n)));for(let d=0;d<p;d+=1){s+=r.divergence*Math.PI/180;let h=e.pos.length;B(e,i.top,{around:s,length:t.frond*(.15+.85*l**.8)*(1-.35*n),cycle:a-1+d/p});let u=a+t.frondLife*(.8+.4*o());for(let t=h;t<e.pos.length;t+=1)e.deadAt[t]=u;e.shedAt[h]=u+.3+.5*o()}}for(let t=0;t<e.pos.length;t+=1)e.deadAt[t]=Math.min(p(e.deadAt,t),r.cycles-.6),p(e.shedAt,t)!==1/0&&(e.shedAt[t]=Math.min(p(e.shedAt,t),r.cycles-.2))}(o,e.palm),o;let a=f(h(.12*(o.random()-.5),1,.12*(o.random()-.5)));A(o,S(o,-1,{pos:h(a.x,1,a.z),dir:a,order:0,birth:0,span:1,main:!0}),a,!0);let n=Math.round(.72*e.cycles);for(let t=1;t<e.cycles;t+=1)t<=n?I(o,t,D(o,t,n)):P(o,t,(t-n)/(e.cycles-n));for(let t=0;t<o.pos.length;t+=1)p(o.deadAt,t)===1/0&&(o.deadAt[t]=e.cycles-.6);return o}(t,r,Math.max(64,Math.min(e.maxNodes??4800,6e3))),n=o.pos.length,i=t.height/Math.max(o.height,1),d=l(20907^r),s=5+Math.floor(3*d());return{species:t,seed:r,cycles:t.cycles,matureAt:Math.round(.72*t.cycles),count:n,parent:Int32Array.from(o.parent),x:Float32Array.from(o.pos,e=>e.x*i),y:Float32Array.from(o.pos,e=>e.y*i),z:Float32Array.from(o.pos,e=>e.z*i),order:Uint8Array.from(o.order,e=>Math.min(e,255)),birth:Float32Array.from(o.birth),span:Float32Array.from(o.span),deadAt:Float32Array.from(o.deadAt),shedAt:Float32Array.from(o.shedAt,e=>e===1/0?1e9:e),phase:Float32Array.from(o.pos,()=>d()*Math.PI*2),leaves:L(G(o),{perNode:t.leafSlots,spread:t.leafSpread,hang:t.hang,seed:7855^r},e=>function(e,t){return null!==e.species.palm?p(e.order,t)>0&&!R(e,t):p(e.order,t)>0||p(e.birth,t)<4}(o,e)),blossoms:_(o,t.flower,.8*t.leafSpread,45317^r),fruit:_(o,t.fruit,.7*t.leafSpread,991255^r),roots:Array.from({length:s},(e,t)=>({angle:t/s*Math.PI*2+.6*d(),reach:.7+.6*d()}))}}function J(e,t,r,o){let l=a(t),n=e.y.reduce((e,t)=>Math.max(e,t),0),i={count:e.count,palm:!1,heading:t=>{let r=p(e.parent,t);return r<0?h(0,1,0):f(h(p(e.x,t)-p(e.x,r),p(e.y,t)-p(e.y,r),p(e.z,t)-p(e.z,r)))}},d=(t,a,l)=>{if(null===t)return null;let d=(t.above??0)*n,h=L(i,{perNode:t.perNode,spread:a,hang:0,seed:(e.seed^l^40503*o)>>>0},t=>p(r,t)===o&&p(e.order,t)>0&&p(e.y,t)>=d);return h.count>0?{spec:t,slots:h}:null};return{flower:d(l.flower,.8*l.leafSpread,45317),fruit:d(l.fruit,.7*l.leafSpread,991255)}}var K={willow:{prime:.22,quick:4.9,old:.875},birch:{prime:.28,quick:4.4,old:.875},acacia:{prime:.25,quick:4.4,old:.9},jacaranda:{prime:.28,quick:4.4,old:.9},cherry:{prime:.3,quick:4.9,old:.9},maple:{prime:.38,quick:3.6,old:.925},palm:{prime:.4,quick:3.1,old:.925},pine:{prime:.45,quick:3.4,old:.925},spruce:{prime:.5,quick:3.1,old:.93},oak:{prime:.55,quick:2.9,old:.94},baobab:{prime:.65,quick:2.1,old:.96},redwood:{prime:.7,quick:2.3,old:.96},peach:{prime:.22,quick:4.6,old:.875},plum:{prime:.26,quick:4.2,old:.89},fig:{prime:.25,quick:4.4,old:.9},apple:{prime:.3,quick:3.9,old:.9},lemon:{prime:.3,quick:3.9,old:.9},pear:{prime:.35,quick:3.6,old:.92},orange:{prime:.35,quick:3.6,old:.92},mango:{prime:.45,quick:3.2,old:.93}};function Q(e,t,r){let o=n(t/Math.max(r,1e-6)),a=K[e.species.id];return o<a.old?.32+(e.matureAt-.32)*function(e,t){let r=3.2*t;return((1-Math.exp(-r*e))/(1-Math.exp(-r)))**1.25*(1-.42)+.42*e}(o/a.old,a.quick):e.matureAt+(e.cycles-e.matureAt)*((o-a.old)/(1-a.old))**1.5}function V(e,t,r){for(let o=p(e.parent,t);o>=0;o=p(e.parent,o))if(o===r)return!0;return!1}function $(e,t,r){let o=0,a=-1/0;for(let l=0;l<e.length;l+=1){let n=(e[l]??0)*r-p(t,l);(e[l]??0)>0&&n>a&&(a=n,o=l)}return o}var ee=(e,t)=>[.35,.5,.65].filter(r=>p(e.birth,t)<=e.cycles*r&&p(e.deadAt,t)>e.cycles*r).length;function te(e,t){let{model:r,taken:o}=e;for(let e=p(r.parent,t);e>=0;e=p(r.parent,e))if(o.has(e))return!0;return!1}function re(e,t){let{model:r,strain:o,want:a,alive:l,now:n,total:i,taken:d}=e,h=(a[t]??0)*i-p(n,t);if(!(h<=.03*i))for(let s of function(e,t){let{model:r,strain:o,alive:a}=e,l=r.order,n=[];for(let e=0;e<r.count;e+=1){let i=p(r.parent,e);i<0||0===p(l,i)||p(l,e)<=p(l,i)||p(o,e)===t||p(a,e)<=0||n.push(e)}return n.sort((e,t)=>p(a,t)-p(a,e)),n}(e,t)){if(h<=.03*i)break;let u=p(o,s),c=p(l,s),f=p(n,u)-(a[u]??0)*i;u===t||c>1.25*h||c>f||te(e,s)||(d.add(s),n[u]=p(n,u)-c,n[t]=p(n,t)+c,h-=c,oe(r,o,s,t))}}function oe(e,t,r,o){for(let a=r;a<e.count;a+=1)(a===r||V(e,a,r))&&(t[a]=o)}function ae(e,t,r=e.seed){let o=new Uint8Array(e.count);if(t.length<=1)return o;let a=function(e){let t=new Float64Array(e.count);for(let r=0;r<e.leaves.count;r+=1){let o=p(e.leaves.node,r),a=Math.max(0,Math.min(p(e.deadAt,o),e.cycles)-p(e.birth,o))/e.cycles;t[o]=p(t,o)+a}for(let r=e.count-1;r>0;r-=1){let o=p(e.parent,r);o>=0&&(t[o]=p(t,o)+p(t,r))}return t}(e),n=function(e,t,r){let o=e.order,a=[];for(let r=0;r<e.count;r+=1){let l=p(e.parent,r);p(o,r)>0&&(l<0||0===p(o,l))&&p(t,r)>0&&a.push(r)}let l=a.filter(t=>Math.min(p(e.deadAt,t),e.cycles)-p(e.birth,t)>=.25*e.cycles);return l.length>=r?l:a}(e,a,t.length),i=l(24263^r);for(let e=n.length-1;e>0;e-=1){let t=Math.floor(i()*(e+1));[n[e],n[t]]=[p(n,t),p(n,e)]}n.sort((t,r)=>Math.round(2*p(e.birth,t))-Math.round(2*p(e.birth,r)));let d=function(e){let t=e.reduce((e,t)=>e+Math.max(0,t),0)||1;return e.map(e=>Math.max(0,e)/t)}(t),h=function(e,t,r){let o=new Float64Array(r.length),a=new Map,l=0;for(let n of e){l+=p(t,n);let e=$(r,o,l);a.set(n,e),o[e]=p(o,e)+p(t,n)}return function(e,t,r,o){let{owner:a,have:l}=o;for(let o=1;o<r.length;o+=1){if((r[o]??0)<=0||p(l,o)>0)continue;let n=-1;for(let r of e)0===a.get(r)&&(n<0||p(t,r)<p(t,n))&&(n=r);n>=0&&(a.set(n,o),l[o]=p(t,n))}}(e,t,r,{owner:a,have:o}),a}(n,a,d);for(let t=0;t<e.count;t+=1){let r=p(e.parent,t);o[t]=h.get(t)??(r>=0?p(o,r):0)}return function(e,t,r){let o=function(e){let t=new Float64Array(e.count);for(let r=0;r<e.leaves.count;r+=1){let o=p(e.leaves.node,r);t[o]=p(t,o)+ee(e,o)}for(let r=e.count-1;r>0;r-=1){let o=p(e.parent,r);o>=0&&(t[o]=p(t,o)+p(t,r))}return t}(e),a=new Float64Array(r.length);for(let r=0;r<e.leaves.count;r+=1){let o=p(e.leaves.node,r);a[p(t,o)]=p(a,p(t,o))+ee(e,o)}let l=a.reduce((e,t)=>e+t,0),n={model:e,strain:t,want:r,alive:o,now:a,total:l,taken:new Set},i=r.map((e,t)=>t).sort((e,t)=>(r[t]??0)*l-p(a,t)-((r[e]??0)*l-p(a,e)));for(let e of i)re(n,e)}(e,o,d),o}var le={cherry:{up:1.9,out:2.4},oak:{up:2.2,out:3},pine:{up:2.7,out:1.5},birch:{up:2.3,out:1.7},willow:{up:1.8,out:2.8},acacia:{up:1.6,out:3.2},palm:{up:2.5,out:1.1},spruce:{up:2.6,out:1.5},redwood:{up:3.2,out:1.6},maple:{up:2.1,out:2.6},jacaranda:{up:1.8,out:2.8},baobab:{up:1.8,out:2.5},apple:{up:1.8,out:2.6},pear:{up:2.3,out:1.8},peach:{up:1.6,out:2.6},plum:{up:1.9,out:2.3},orange:{up:1.8,out:2.4},lemon:{up:1.7,out:2.2},fig:{up:1.7,out:2.8},mango:{up:2.3,out:2.8}},ne=new WeakMap;function ie(e,t){let r=ne.get(e);if(void 0===r){r=new Float32Array(2*(e.cycles+1));for(let t=0;t<e.count;t+=1){let o=Math.max(0,Math.ceil(p(e.birth,t)+p(e.span,t))),a=p(e.y,t),l=Math.hypot(p(e.x,t),p(e.z,t));for(let t=o;t<=e.cycles;t+=1)r[2*t]=Math.max(p(r,2*t),a),r[2*t+1]=Math.max(p(r,2*t+1),l)}ne.set(e,r)}let o=Math.max(0,Math.min(e.cycles,Math.floor(t))),a=Math.min(e.cycles,o+1),l=n(t-o);return[0,1].map(e=>p(r,2*o+e)+(p(r,2*a+e)-p(r,2*o+e))*l)}function de(e,t,r=!0){let o=function(e){return!1===e?0:!0===e?1:Math.max(0,e)}(r),a=n((function(e,t){let r=0,o=1;for(let a=0;a<32;a+=1){let a=(r+o)/2;Q(e,a,1)<t?r=a:o=a}return(r+o)/2}(e,t)-.04)/.96)**.75,l=le[e.species.id],i=Math.min(t,e.matureAt),[d,p]=ie(e,t),[h,s]=ie(e,i),u=(1+(l.up-1)*o*a)*(o>0&&d>0?h/d:1),c=(1+(l.out-1)*o*a)*(o>0&&p>0?s/p:1);return{up:u,out:c,girth:(u*c)**.6}}function pe(e,t){return e<0?0:t?n(e/.08):i(e,1.4,2.8)}var he=(e,t,r)=>h(p(e.x,t)*r.out,p(e.y,t)*r.up,p(e.z,t)*r.out);function se(e,t,r,o){let a=t.get(r);return void 0===a&&(a=function(e,t,r,o){let{ground:a,size:l}=r,n=p(e.parent,t),i=he(e,n,l),d=he(e,t,l),u=f(s(d,i,-1)),g=f(h(u.x+.3*i.x,0,u.z+.3*i.z),f(h(o()-.5,0,o()-.5),h(1,0,0))),w=f(c(u,g),m(u)),y=Math.acos(Math.max(-1,Math.min(1,u.x*g.x+u.y*g.y+u.z*g.z))),x=h(i.x+.6*g.x,a+.06,i.z+.6*g.z);return{pivot:i,axis:w,angle:y,drop:s(x,i,-1)}}(e,r,o,l(e.seed^r)),t.set(r,a)),a}function ue(e,t,r,o){let a=r*r,l=s(t.pivot,g(s(e,t.pivot,-1),t.axis,t.angle*a)),n=s(l,t.drop,a*a),i=Math.hypot(n.x,n.z),d=1+((i>3.4?(3.4+.25*(i-3.4))/i:1)-1)*a,p=Math.max(0,n.y-o-.04);return h(n.x*d,o+.04+p+(Math.min(.12,.05*p)-p)*a,n.z*d)}var ce=(e,t)=>2*(e-.5)*.3-.22-.05*t;function fe(e,t,r,o){let a=Math.hypot(e.x,e.z),l=Math.atan2(e.y,a);if(l<=o)return e;let n=l+.68*(o-l)*d(t),i=a>1e-6?h(e.x/a,0,e.z/a):f(h(r.x,0,r.z),h(1,0,0)),p=u(e);return h(i.x*Math.cos(n)*p,Math.sin(n)*p,i.z*Math.cos(n)*p)}var ge=(e,t)=>h(p(e,3*t),p(e,3*t+1),p(e,3*t+2));function me(e,t,r={}){let o=e.count,a=Math.min(Math.max(t,0),e.cycles),d=()=>new Float32Array(o),u={cycle:a,grow:d(),radius:d(),dead:d(),fall:d(),rot:d(),tips:d(),x:d(),y:d(),z:d(),baseX:d(),baseY:d(),baseZ:d(),visible:0,height:0,scale:1},c=new Int32Array(o).fill(-1),f=void 0===r.grand||!1===r.grand?{up:1,out:1,girth:1}:de(e,a,r.grand);if(function(e,t,r){for(let o=e.count-1;o>=0;o-=1){let a=n((t-p(e.birth,o))/Math.max(p(e.span,o),.001));r.grow[o]=a;let l=Math.max(a,p(r.tips,o));r.tips[o]=l;let i=p(e.parent,o);i>=0&&a>0&&(r.tips[i]=p(r.tips,i)+l)}let{radiusTip:o,pipe:a,palm:l}=e.species;for(let t=0;t<e.count;t+=1){let e=p(r.grow,t);r.radius[t]=e<=0?0:o*p(r.tips,t)**(1/a)*(.45+.55*e)}null!==l&&function(e,t,r,o){let a=o*(.35+.65*i(t,1,8));for(let t=0;t<e.count;t+=1)0!==p(e.order,t)||p(r.grow,t)<=0||(r.radius[t]=a*(t<3?1.35-.1*t:1))}(e,t,r,l.trunk)}(e,a,u),1!==f.girth)for(let e=0;e<o;e+=1)u.radius[e]=p(u.radius,e)*f.girth;(function(e,t,r,o){for(let a=0;a<e.count;a+=1){let l=p(e.parent,a),i=n((t-p(e.deadAt,a))/1.2);r.dead[a]=l>=0?Math.max(i,p(r.dead,l)):i;let d=l>=0?p(o,l):-1;o[a]=d>=0?d:t>=p(e.shedAt,a)?a:-1;let h=p(o,a),s=h>=0?t-p(e.shedAt,h):-1;r.fall[a]=s<0?0:n(s/.08);let u=h>=0&&p(r.radius,h)<.09;r.rot[a]=pe(s,u)}})(e,a,u,c),function(e,t,r,o){let{ground:a,size:n}=o,i=new Map,d=function(e,t,r){let{ground:o,size:a}=r,n=new Float64Array(3*e.count);for(let r=0;r<e.count;r+=1){let i=p(e.parent,r),d=i>=0?he(e,i,a):h(0,0,0),u=s(d,s(he(e,r,a),d,-1),p(t.grow,r)),c=p(e.order,r)>0?p(t.dead,r):0,f=u;if(c>0){let t=i>=0?ge(n,i):d,a=l(e.seed^31*r+7)(),g=fe(s(u,d,-1),c,d,ce(a,p(e.order,r)));f=s(t,g),f=h(f.x,Math.max(f.y,o+.04),f.z)}n[3*r]=f.x,n[3*r+1]=f.y,n[3*r+2]=f.z}return n}(e,t,o);for(let l=0;l<e.count;l+=1){let u=p(e.parent,l),c=u>=0?he(e,u,n):h(0,0,0),f=s(c,s(he(e,l,n),c,-1),p(t.grow,l)),g=p(r,l),m=u>=0?h(p(t.x,u),p(t.y,u),p(t.z,u)):h(0,0,0),w=p(e.order,l)>0?p(t.dead,l):0,y=ge(d,l),x=y;if(g>=0){let r=se(e,i,g,o),n=p(t.fall,l);x=ue(s(f,s(y,f,-1),1-n),r,n,a);let h=u>=0&&w>0?ge(d,u):c;g===l&&(m=ue(s(c,s(h,c,-1),1-n),r,n,a))}t.x[l]=x.x,t.y[l]=x.y,t.z[l]=x.z,t.baseX[l]=m.x,t.baseY[l]=m.y,t.baseZ[l]=m.z}}(e,u,c,{ground:r.ground??0,size:f});let g=0,m=0;for(let e=0;e<o;e+=1)p(u.grow,e)<=0||p(u.rot,e)>=1||(g+=1,0===p(u.fall,e)&&(m=Math.max(m,p(u.y,e))));return{...u,visible:g,height:m,scale:Math.sqrt(f.up*f.out)}}var we=6e-6,ye=(e,t,r,o)=>Math.hypot(p(e.x,o)-t,p(e.z,o)-r);function xe(e,t){let{model:r,frame:o,drop:a}=e,l=function(e,t){let r=[];for(let o=t;o>0&&p(e.order,o)>0;o=p(e.parent,o))r.push(o);return r.reverse()}(r,t.node);if(0===l.length)return;let n=function(e,t,r,o){let a=p(e.x,r.node),l=p(e.z,r.node),n=t.map(t=>{let n=Math.hypot(a-p(e.baseX,t),l-p(e.baseZ,t)),i=Math.max(p(e.radius,t),.006),d=Math.min(1,(.02/i)**2);return Math.min(o*Math.abs(r.weight)**.5*n*((e,t)=>Math.hypot(p(e.x,t)-p(e.baseX,t),p(e.y,t)-p(e.baseY,t),p(e.z,t)-p(e.baseZ,t)))(e,t)*d/i**4,.3)});return t.map((r,o)=>{let a=0;for(let l=0;l<=o;l+=1){let o=t[l]??r;a+=(n[l]??0)*ye(e,p(e.baseX,o),p(e.baseZ,o),r)}return a})}(o,l,t,e.sag),i=l.reduce((e,t)=>e+ye(o,p(o.baseX,t),p(o.baseZ,t),t),0),d=n[n.length-1]??0,h=Math.min(.25,.25*i+.02),s=(d>h?h/d:1)*Math.sign(t.weight),u=new Float32Array(r.count).fill(Number.NaN);l.forEach((e,t)=>{u[e]=(n[t]??0)*s}),u[0]=0;for(let e=1;e<r.count;e+=1)Number.isNaN(u[e])&&(u[e]=u[p(r.parent,e)]??0),a[e]=(a[e]??0)+(u[e]??0)}function Me(e,t,r,o={}){let{out:a}=o,l=o.sag??we,n=a??{...t,x:new Float32Array(t.x),y:new Float32Array(t.y),z:new Float32Array(t.z),baseX:new Float32Array(t.baseX),baseY:new Float32Array(t.baseY),baseZ:new Float32Array(t.baseZ)};if(n.x.set(t.x),n.z.set(t.z),n.baseX.set(t.baseX),n.baseZ.set(t.baseZ),0===r.length)return n.y.set(t.y),n.baseY.set(t.baseY),n;let i=new Float32Array(e.count),d={model:e,frame:t,drop:i,sag:l};for(let t of r)0!==t.weight&&t.node>0&&t.node<e.count&&xe(d,t);for(let r=0;r<e.count;r+=1){n.y[r]=p(t.y,r)-p(i,r);let o=p(e.parent,r);n.baseY[r]=p(t.baseY,r)-(o>=0?p(i,o):0)}return n}var ve={alpine:14,maritime:-5,monsoon:-6,desert:-10,highland:0,temperate:0},be={alpine:-14,maritime:10,monsoon:6,desert:4,highland:0,temperate:0};function Se(e,t,r){if(null===e)return{open:0,fallen:0};let o=e.window[0]<200?t:r;return{open:d(i(o,e.window[0],e.window[1])),fallen:i(o,e.window[2],e.window[3])}}function Ae(e,t,r){let o=e.phenology,a=d(i(t,o.leaf[0],o.leaf[1])),l=d(i(r,o.color[0],o.color[1])),n=o.dropMax*i(r,o.drop[0],o.drop[1]),p=.35*(1-i(t,60,104))*o.dropMax,h=1-i(t,o.flush[0],o.flush[1]),s=r>=o.drop[1];if(o.dropMax>=1&&(s||t<o.leaf[0])){let e=s?o.dropMax*(1-.65*i(r,o.drop[1],425)):p,t=o.marcescent;return{leaf:t>0?1:0,color:t>0?1:0,drop:t>0?1-t:0,litter:e,flush:0,withered:t>0,dormant:!0}}return{leaf:a,color:l,drop:n,litter:r>=o.drop[0]?n:p,flush:t>=o.flush[0]-6?h:0,withered:!1,dormant:a<=0}}function ke(e){let t=a(e.species),r=t.phenology,o=e.hemisphere??"north",n=(("south"===o?(e.day+182)%365:e.day)-60+365)%365+60,i=e.climate??"temperate",d=function(e,t){return 8*(l(2654435761*e^t)()-.5)}(e.year??2026,r.leaf[0]),p=n-(ve[i]??0)-d,h=n-(be[i]??0)-.5*d,s=Se(t.flower,p,h),u=Se(t.fruit,p,h),c={...Ae(t,p,h),bloom:s.open,petals:s.fallen,fruit:u.open,fruitDrop:u.fallen};return r.dropMax<1&&(c={...c,leaf:1,dormant:!1}),"equatorial"===o&&(c={...c,leaf:Math.max(c.leaf,.85),color:.35*c.color,drop:.3*c.drop,litter:.3*c.litter,withered:!1,dormant:!1}),c}export{le as GRAND,K as PACE,r as SPECIES,o as SPECIES_IDS,we as WOOD_SAG,Me as bendFrame,Z as blendSpecies,l as createRandom,Q as cycleAt,de as grandAt,H as growTree,J as kindOrnaments,X as mixShares,ae as sectors,a as speciesOf,me as treeFrame,ke as yearState};
@@ -0,0 +1,9 @@
1
+ export declare const TREE_FEATURES: readonly ["roots", "leaves", "flowers", "fruit", "deadwood", "litter", "snow", "fallers", "sway", "shadows", "crownShade", "bark", "sprays", "clumps", "rootSink", "rootBreak"];
2
+ export type TreeFeature = (typeof TREE_FEATURES)[number];
3
+ export type TreeFeatures = Readonly<Record<TreeFeature, boolean>>;
4
+ /**
5
+ * Feature switches, all on by default. Pass an object ({ roots: false }) or a
6
+ * plugin string: "-roots,-fruit" turns those off, "roots=off" too, and a bare
7
+ * name or "name=on" turns one back on. Unknown names are ignored.
8
+ */
9
+ export declare function treeFeatures(input?: Partial<Record<TreeFeature, boolean>> | string): TreeFeatures;