@arraypress/effects-astro 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.
- package/AGENTS.md +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +303 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/iso-city/figures
|
|
3
|
+
*
|
|
4
|
+
* What moves in the city, as the shader's instances: each car's place,
|
|
5
|
+
* paint and state (with the little hop and squash of a pickup), the people
|
|
6
|
+
* (a rider waiting by each pin who steps into the taxi, and people walking
|
|
7
|
+
* over a zebra while the cars wait), and each pin's drop, bob and pop.
|
|
8
|
+
*
|
|
9
|
+
* Pure: read off the traffic at a moment.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { lanePoint } from './roads.js';
|
|
13
|
+
import { CAR_SCALE, KERB, PAVEMENT } from './traffic.js';
|
|
14
|
+
|
|
15
|
+
/** Floats an instance: place (x, z, heading, lift), paint (r, g, b, taxi: 1, car: 0, neither: −1), state (brake, squash, scale, fade). */
|
|
16
|
+
export const INSTANCE = 12;
|
|
17
|
+
/** How much larger than its model a pin is drawn. */
|
|
18
|
+
export const PIN_SCALE = 1.9;
|
|
19
|
+
/** How much larger than its model a person is drawn. */
|
|
20
|
+
export const PERSON_SCALE = 1.8;
|
|
21
|
+
/** How long a taxi's pickup hop lasts, seconds. */
|
|
22
|
+
const HOP = 1.6;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {import('./traffic.js').Traffic} Traffic
|
|
26
|
+
* @typedef {import('./traffic.js').Job} Job
|
|
27
|
+
* @typedef {import('./roads.js').Roads} Roads
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An eased drop with one small bounce: 0 at the start, 1 landed.
|
|
32
|
+
*
|
|
33
|
+
* @param {number} t Progress, 0–1 (clamped).
|
|
34
|
+
* @returns {number} The eased value.
|
|
35
|
+
*/
|
|
36
|
+
export function bounce(t) {
|
|
37
|
+
const x = Math.min(1, Math.max(0, t));
|
|
38
|
+
if (x < 0.55) return (x / 0.55) ** 2;
|
|
39
|
+
const k = (x - 0.775) / 0.225;
|
|
40
|
+
return 1 - 0.12 * Math.max(0, 1 - k * k);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Writes the cars' instances.
|
|
45
|
+
*
|
|
46
|
+
* @param {import('./traffic.js').Car[]} cars The cars.
|
|
47
|
+
* @param {{ accent: number[], neutrals: number[][] }} look Their colours: taxis wear the accent.
|
|
48
|
+
* @param {Float32Array} out Where to write them, INSTANCE floats a car.
|
|
49
|
+
*/
|
|
50
|
+
export function carInstances(cars, look, out) {
|
|
51
|
+
cars.forEach((car, i) => {
|
|
52
|
+
const paint = car.taxi ? look.accent : look.neutrals[car.paint % look.neutrals.length];
|
|
53
|
+
const hop = car.hop >= 0 && car.hop < HOP ? car.hop : -1;
|
|
54
|
+
const lift = hop >= 0 ? 0.07 * Math.abs(Math.sin(hop * Math.PI * 2.4)) * Math.exp(-hop * 2.6) : 0;
|
|
55
|
+
const squash = hop >= 0 ? 1 + 0.12 * Math.sin(hop * Math.PI * 4.8) * Math.exp(-hop * 3) : 1;
|
|
56
|
+
out.set([car.x, car.z, car.heading, lift, paint[0], paint[1], paint[2], car.taxi ? 1 : 0, car.brake, squash, CAR_SCALE, 0], i * INSTANCE);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The people's instances: a rider by each pin (stepping to the taxi and in
|
|
62
|
+
* as it picks up), and one or two people walking over a zebra wherever
|
|
63
|
+
* people are crossing.
|
|
64
|
+
*
|
|
65
|
+
* @param {Traffic} traffic The traffic.
|
|
66
|
+
* @param {Roads} roads The roads.
|
|
67
|
+
* @returns {number[]} INSTANCE floats a person.
|
|
68
|
+
*/
|
|
69
|
+
export function peopleInstances(traffic, roads) {
|
|
70
|
+
const clock = traffic.time;
|
|
71
|
+
/** @type {number[]} */
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const job of traffic.jobs) {
|
|
74
|
+
const lane = roads.lanes[job.lane];
|
|
75
|
+
// Beside the pin, on the side nearer the camera (which looks from +x, +z), so the pin never hides them.
|
|
76
|
+
const at = lanePoint(lane, job.s + 0.18 * Math.sign(lane.dx + lane.dz), PAVEMENT - 0.06);
|
|
77
|
+
const since = clock - job.since;
|
|
78
|
+
if (job.state === 'going') {
|
|
79
|
+
const wave = Math.abs(Math.sin(clock * 5)) * 0.012 * bounce(since * 2);
|
|
80
|
+
out.push(at.x, at.z, lane.heading + Math.PI / 2, wave, 0, 0, 0, -1, 0, 1, bounce(since * 2.5) * PERSON_SCALE, 0);
|
|
81
|
+
} else if (job.state === 'pickup' && since < 0.6) {
|
|
82
|
+
// Steps to the car and climbs in.
|
|
83
|
+
const k = since / 0.6;
|
|
84
|
+
const to = lanePoint(lane, job.s, KERB + 0.05);
|
|
85
|
+
out.push(at.x + (to.x - at.x) * k, at.z + (to.z - at.z) * k, lane.heading - Math.PI / 2, 0, 0, 0, 0, -1, 0, 1, (1 - k * k) * PERSON_SCALE, 0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const [node, hold] of traffic.crossings) {
|
|
89
|
+
// One of the junction's zebras, the same one for the whole crossing.
|
|
90
|
+
const leaving = roads.out[node];
|
|
91
|
+
const lane = roads.lanes[leaving[(node * 7 + Math.floor(hold.start * 3)) % leaving.length]];
|
|
92
|
+
const k = (clock - hold.start) / (hold.until - hold.start);
|
|
93
|
+
const count = 1 + ((node + Math.floor(hold.start)) % 2);
|
|
94
|
+
for (let n = 0; n < count; n++) {
|
|
95
|
+
// From kerb to kerb (across from the street's centre), the second person the other way.
|
|
96
|
+
const across = -0.62 + 1.24 * Math.min(1, Math.max(0, k * 1.15 - n * 0.1));
|
|
97
|
+
const way = n % 2 ? -1 : 1;
|
|
98
|
+
const p = lanePoint(lane, 0.12 + n * 0.1, way * across);
|
|
99
|
+
const step = Math.abs(Math.sin(k * 40 + n)) * 0.01;
|
|
100
|
+
out.push(p.x, p.z, lane.heading + way * (Math.PI / 2), step, 0, 0, 0, -1, 0, 1, Math.min(1, Math.min(k, 1 - k) * 12) * PERSON_SCALE, 0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @typedef {object} PinState
|
|
108
|
+
* @property {Job} job Its pickup.
|
|
109
|
+
* @property {number} scale Its size (PIN_SCALE not included).
|
|
110
|
+
* @property {number} lift How high it hangs over the pavement.
|
|
111
|
+
* @property {number} fade Its ring's and route's opacity, 0–1.
|
|
112
|
+
* @property {number} pulse The ring's pulse, 0–1.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The pins to draw: dropping in with a bounce and bobbing while the taxi
|
|
117
|
+
* comes, popping away as it picks up (or is sent elsewhere).
|
|
118
|
+
*
|
|
119
|
+
* @param {Job[]} jobs The pickups.
|
|
120
|
+
* @param {number} clock The traffic's time, seconds.
|
|
121
|
+
* @returns {PinState[]} The pins on show.
|
|
122
|
+
*/
|
|
123
|
+
export function pinStates(jobs, clock) {
|
|
124
|
+
/** @type {PinState[]} */
|
|
125
|
+
const pins = [];
|
|
126
|
+
for (const job of jobs) {
|
|
127
|
+
const since = clock - job.since;
|
|
128
|
+
if (job.state === 'going') {
|
|
129
|
+
pins.push({ job, scale: 0.6 + 0.4 * bounce(since * 2.2), lift: (1 - bounce(since * 2.2)) * 0.9 + Math.sin(clock * 2.2) * 0.015, fade: 1, pulse: (since * 0.7) % 1 });
|
|
130
|
+
} else if (job.state !== 'done' && since < 0.45) {
|
|
131
|
+
const k = since / 0.45;
|
|
132
|
+
pins.push({ job, scale: 1 + 0.25 * Math.sin(k * Math.PI) - k, lift: k * 0.25, fade: 1 - k, pulse: Math.min(1, k * 1.2) });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return pins;
|
|
136
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Rgb } from '../color.js';
|
|
2
|
+
|
|
3
|
+
/** The day defaults: buildings, parks, roads; the taxis; the ground. */
|
|
4
|
+
export const DAY: { colors: string[]; accent: string; background: string };
|
|
5
|
+
/** The night defaults. */
|
|
6
|
+
export const NIGHT: { colors: string[]; accent: string; background: string };
|
|
7
|
+
/** The cars that are not taxis. */
|
|
8
|
+
export const NEUTRALS: string[];
|
|
9
|
+
|
|
10
|
+
/** Every colour the city is drawn in. */
|
|
11
|
+
export interface Look {
|
|
12
|
+
buildings: Rgb;
|
|
13
|
+
roofs: Rgb;
|
|
14
|
+
detail: Rgb;
|
|
15
|
+
parks: Rgb;
|
|
16
|
+
trees: Rgb[];
|
|
17
|
+
trunk: Rgb;
|
|
18
|
+
path: Rgb;
|
|
19
|
+
water: Rgb;
|
|
20
|
+
roads: Rgb;
|
|
21
|
+
pavement: Rgb;
|
|
22
|
+
marking: Rgb;
|
|
23
|
+
lamp: Rgb;
|
|
24
|
+
solar: Rgb;
|
|
25
|
+
tints: Rgb[];
|
|
26
|
+
background: Rgb;
|
|
27
|
+
accent: Rgb;
|
|
28
|
+
neutrals: Rgb[];
|
|
29
|
+
person: Rgb;
|
|
30
|
+
night: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The city's colours from its settings: three given, or a palette softened, or the defaults; the rest mixed from them in Oklab. */
|
|
34
|
+
export function cityLook(config: { colors?: string[]; palette?: string; accent?: string; background?: string; night?: boolean }): Look;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/iso-city/look
|
|
3
|
+
*
|
|
4
|
+
* The city's colours. Three are given (buildings, parks, roads), or taken
|
|
5
|
+
* from a palette and softened so even a loud palette makes a calm city;
|
|
6
|
+
* everything else (pavements, markings, trees, water, roof clutter) is
|
|
7
|
+
* mixed from them in Oklab. Day and night each have their own defaults and
|
|
8
|
+
* light: a warm sun with cool shade by day, a dim blue moon at night, when
|
|
9
|
+
* windows, lamps and headlights do the lighting.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { mixOklab, parseColor, toHex } from '../color.js';
|
|
13
|
+
import { findPalette, pickColors } from '../palettes.js';
|
|
14
|
+
|
|
15
|
+
/** By day: warm off-white buildings, sage parks, graphite roads, amber taxis, a paper ground. */
|
|
16
|
+
export const DAY = { colors: ['#f3eee5', '#a9bf99', '#3b3f46'], accent: '#f2a53a', background: '#e9e3d8' };
|
|
17
|
+
/** By night: slate buildings, deep green parks, near-black roads, a midnight ground. */
|
|
18
|
+
export const NIGHT = { colors: ['#3b434f', '#22372d', '#161a20'], accent: '#ffb547', background: '#0d1219' };
|
|
19
|
+
/** The cars that are not taxis: white, silver, grey, graphite, black. */
|
|
20
|
+
export const NEUTRALS = ['#f5f5f3', '#cfd3d8', '#8f969f', '#4a5059', '#22252a'];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {import('../color.js').Rgb} Rgb
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {object} Look
|
|
28
|
+
* @property {Rgb} buildings Walls.
|
|
29
|
+
* @property {Rgb} roofs Roofs.
|
|
30
|
+
* @property {Rgb} detail Things on roofs.
|
|
31
|
+
* @property {Rgb} parks Grass.
|
|
32
|
+
* @property {Rgb[]} trees Crowns, three greens.
|
|
33
|
+
* @property {Rgb} trunk Trunks.
|
|
34
|
+
* @property {Rgb} path Park paths.
|
|
35
|
+
* @property {Rgb} water Ponds.
|
|
36
|
+
* @property {Rgb} roads Tarmac.
|
|
37
|
+
* @property {Rgb} pavement Pavements and plazas.
|
|
38
|
+
* @property {Rgb} marking Road markings.
|
|
39
|
+
* @property {Rgb} lamp Lamp posts.
|
|
40
|
+
* @property {Rgb} solar Solar panels.
|
|
41
|
+
* @property {Rgb[]} tints A few tints for buildings that differ.
|
|
42
|
+
* @property {Rgb} background The ground the city fades into.
|
|
43
|
+
* @property {Rgb} accent The taxis.
|
|
44
|
+
* @property {Rgb[]} neutrals The other cars.
|
|
45
|
+
* @property {Rgb} person People.
|
|
46
|
+
* @property {boolean} night Whether it is night.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The city's colours from its settings.
|
|
51
|
+
*
|
|
52
|
+
* @param {{ colors?: string[], palette?: string, accent?: string, background?: string, night?: boolean }} config The settings.
|
|
53
|
+
* @returns {Look} The colours.
|
|
54
|
+
*/
|
|
55
|
+
export function cityLook(config) {
|
|
56
|
+
const night = config.night === true;
|
|
57
|
+
const base = night ? NIGHT : DAY;
|
|
58
|
+
const [b, p, r] = baseColors(config).map(parseColor);
|
|
59
|
+
const white = parseColor('#ffffff');
|
|
60
|
+
const black = parseColor('#000000');
|
|
61
|
+
const palette = config.colors?.length ? undefined : findPalette(config.palette);
|
|
62
|
+
return {
|
|
63
|
+
buildings: b,
|
|
64
|
+
roofs: mixOklab(b, night ? black : white, 0.25),
|
|
65
|
+
detail: mixOklab(b, r, night ? 0.25 : 0.2),
|
|
66
|
+
parks: p,
|
|
67
|
+
trees: [mixOklab(p, parseColor('#3e6a47'), 0.5), mixOklab(p, parseColor('#557a4c'), 0.35), mixOklab(p, parseColor('#6f8f58'), 0.3)].map((c) =>
|
|
68
|
+
night ? mixOklab(c, black, 0.35) : c,
|
|
69
|
+
),
|
|
70
|
+
trunk: mixOklab(parseColor('#7b6450'), r, night ? 0.5 : 0.1),
|
|
71
|
+
path: mixOklab(p, b, 0.6),
|
|
72
|
+
water: night ? mixOklab(parseColor('#1f3a52'), r, 0.3) : mixOklab(parseColor('#8dbcd2'), b, 0.15),
|
|
73
|
+
roads: r,
|
|
74
|
+
pavement: mixOklab(b, r, night ? 0.3 : 0.12),
|
|
75
|
+
marking: mixOklab(r, white, night ? 0.32 : 0.72),
|
|
76
|
+
lamp: mixOklab(r, b, 0.25),
|
|
77
|
+
solar: mixOklab(parseColor('#2c3b55'), r, 0.2),
|
|
78
|
+
tints: night
|
|
79
|
+
? [mixOklab(b, parseColor('#4a3f45'), 0.35), mixOklab(b, parseColor('#3b4a4f'), 0.35)]
|
|
80
|
+
: [mixOklab(b, parseColor('#e6c8ae'), 0.4), mixOklab(b, parseColor('#c8d2cf'), 0.45)],
|
|
81
|
+
background: parseColor(config.background ?? base.background),
|
|
82
|
+
accent: parseColor(config.accent ?? (palette ? palette.colors[0] : base.accent)),
|
|
83
|
+
neutrals: NEUTRALS.map((c) => (night ? mixOklab(parseColor(c), black, 0.25) : parseColor(c))),
|
|
84
|
+
person: parseColor(night ? '#8b93a3' : '#4a4f58'),
|
|
85
|
+
night,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The three base colours: `colors` as given, a palette softened into a
|
|
91
|
+
* city (light buildings, muted parks, dark roads), or the defaults.
|
|
92
|
+
*
|
|
93
|
+
* @param {{ colors?: string[], palette?: string, night?: boolean }} config The settings.
|
|
94
|
+
* @returns {string[]} Buildings, parks, roads.
|
|
95
|
+
*/
|
|
96
|
+
function baseColors(config) {
|
|
97
|
+
const base = config.night ? NIGHT : DAY;
|
|
98
|
+
const colors = pickColors(config, base.colors, (palette) => {
|
|
99
|
+
const [a, b, c] = palette.colors.map(parseColor);
|
|
100
|
+
const [db, dp, dr] = base.colors.map(parseColor);
|
|
101
|
+
return [mixOklab(db, a, config.night ? 0.3 : 0.16), mixOklab(dp, b, 0.4), mixOklab(dr, c, 0.3)].map(toHex);
|
|
102
|
+
});
|
|
103
|
+
return [colors[0] ?? base.colors[0], colors[1] ?? base.colors[1], colors[2] ?? base.colors[2]];
|
|
104
|
+
}
|
|
105
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** World units from one street's centre line to the next. */
|
|
2
|
+
export const PITCH: number;
|
|
3
|
+
/** A street's width: two lanes. */
|
|
4
|
+
export const ROAD: number;
|
|
5
|
+
/** The pavement's width round each block. */
|
|
6
|
+
export const CURB: number;
|
|
7
|
+
/** The height of pavements and plazas above the road. */
|
|
8
|
+
export const SLAB: number;
|
|
9
|
+
/** The height of a storey. */
|
|
10
|
+
export const STOREY: number;
|
|
11
|
+
|
|
12
|
+
export interface Rect { x0: number; z0: number; x1: number; z1: number }
|
|
13
|
+
/** A junction: its column and row, and where it is. */
|
|
14
|
+
export interface Node { id: number; i: number; j: number; x: number; z: number }
|
|
15
|
+
/** A street segment between two neighbouring junctions. */
|
|
16
|
+
export interface Edge { id: number; a: number; b: number; axis: 'x' | 'z' }
|
|
17
|
+
/** A box of a building. */
|
|
18
|
+
export interface Part extends Rect { y0: number; y1: number }
|
|
19
|
+
/** Something standing on a roof. */
|
|
20
|
+
export type Roof =
|
|
21
|
+
| { kind: 'box' | 'hut'; x0: number; z0: number; x1: number; z1: number; y0: number; y1: number }
|
|
22
|
+
| { kind: 'tank'; x: number; z: number; r: number; y0: number; y1: number }
|
|
23
|
+
| { kind: 'garden'; x0: number; z0: number; x1: number; z1: number; y0: number }
|
|
24
|
+
| { kind: 'solar'; x0: number; z0: number; x1: number; z1: number; y0: number; rows: number };
|
|
25
|
+
/** A building: its body (and set-back tier), roof clutter, a shade (−1 to 1), a seed and a pick (0–1). */
|
|
26
|
+
export interface Building { parts: Part[]; roof: Roof[]; tone: number; seed: number; glass: number }
|
|
27
|
+
export interface Tree { x: number; z: number; r: number; h: number; tone: number }
|
|
28
|
+
/** A block, or two merged across a plaza. */
|
|
29
|
+
export interface Block extends Rect { kind: 'build' | 'park'; plaza: Rect | null }
|
|
30
|
+
export interface Pond { x: number; z: number; r: number }
|
|
31
|
+
export interface Path extends Rect { axis: 'x' | 'z' }
|
|
32
|
+
|
|
33
|
+
export interface CityPlan {
|
|
34
|
+
/** Blocks across. */
|
|
35
|
+
size: number;
|
|
36
|
+
/** The street grid's span, world units. */
|
|
37
|
+
extent: number;
|
|
38
|
+
/** The junctions, row by row: id = j × (size + 1) + i. */
|
|
39
|
+
nodes: Node[];
|
|
40
|
+
/** The open street segments. */
|
|
41
|
+
edges: Edge[];
|
|
42
|
+
/** The segments closed into plazas. */
|
|
43
|
+
closed: Edge[];
|
|
44
|
+
blocks: Block[];
|
|
45
|
+
buildings: Building[];
|
|
46
|
+
trees: Tree[];
|
|
47
|
+
ponds: Pond[];
|
|
48
|
+
paths: Path[];
|
|
49
|
+
lamps: { x: number; z: number }[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Plans a city from a seed (default 7) and blocks across (default 6, 2–12). The same seed and size always give the same city. */
|
|
53
|
+
export function planCity(options?: { seed?: number; size?: number }): CityPlan;
|
|
54
|
+
|
|
55
|
+
/** Whether every junction can reach every other along some segments. */
|
|
56
|
+
export function connected(count: number, edges: { a: number; b: number }[]): boolean;
|
|
57
|
+
|
|
58
|
+
/** Where a line of sight from `from` to `to` first enters a building, or null when it meets none. */
|
|
59
|
+
export function firstHit(plan: CityPlan, from: [number, number, number], to: [number, number, number]): [number, number, number] | null;
|