@ewanc26/noise 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 (2) hide show
  1. package/README.md +124 -0
  2. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # @ewanc26/noise
2
+
3
+ Generic deterministic value-noise generation from a string seed. Arbitrary dimensions, multi-octave FBM, multiple colour modes. Zero runtime dependencies, works in any environment with a `Uint8ClampedArray` (browsers, Node.js, workers).
4
+
5
+ Part of the [`@ewanc26/pkgs`](https://github.com/ewanc26/pkgs) monorepo.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @ewanc26/noise
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Raw pixels (no DOM required)
16
+
17
+ ```ts
18
+ import { generateNoisePixels } from '@ewanc26/noise';
19
+
20
+ const pixels = generateNoisePixels(256, 256, 'my-seed', {
21
+ octaves: 4,
22
+ colorMode: { type: 'grayscale' },
23
+ });
24
+ // pixels is a Uint8ClampedArray of RGBA values
25
+ ```
26
+
27
+ ### Canvas
28
+
29
+ ```ts
30
+ import { renderNoise } from '@ewanc26/noise';
31
+
32
+ const canvas = document.querySelector('canvas');
33
+ renderNoise(canvas, 'my-seed', { size: 128, octaves: 3 });
34
+ ```
35
+
36
+ ### Svelte action
37
+
38
+ ```svelte
39
+ <script>
40
+ import { noiseAction } from '@ewanc26/noise';
41
+
42
+ let seed = 'my-seed';
43
+ </script>
44
+
45
+ <canvas use:noiseAction={{ seed, size: 128, octaves: 3 }}></canvas>
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### `generateNoisePixels(width, height, seed, options?)`
51
+
52
+ Generates raw RGBA pixel data — no canvas or DOM needed.
53
+
54
+ Returns a `Uint8ClampedArray` of length `width * height * 4`.
55
+
56
+ ### `renderNoise(canvas, seed, options?)`
57
+
58
+ Renders noise onto an existing `HTMLCanvasElement` (resizes it to `width`/`height`/`size`).
59
+
60
+ ### `noiseAction(canvas, params)`
61
+
62
+ Svelte action wrapper around `renderNoise`. Re-renders reactively when `params` changes via `update`.
63
+
64
+ Params object: `{ seed, ...NoiseOptions, width?, height?, size? }`
65
+
66
+ ---
67
+
68
+ ### Noise options
69
+
70
+ | Option | Type | Default | Description |
71
+ |---|---|---|---|
72
+ | `gridSize` | `number` | `5` | Noise grid resolution |
73
+ | `octaves` | `number` | `1` | FBM octave count (1 = plain value noise) |
74
+ | `persistence` | `number` | `0.5` | FBM amplitude falloff per octave |
75
+ | `lacunarity` | `number` | `2` | FBM frequency multiplier per octave |
76
+ | `colorMode` | `ColorMode` | `{ type: 'hsl' }` | How noise values map to colours |
77
+
78
+ ### Render options (canvas/action only)
79
+
80
+ | Option | Type | Default | Description |
81
+ |---|---|---|---|
82
+ | `width` | `number` | `64` | Canvas width in pixels |
83
+ | `height` | `number` | `64` | Canvas height in pixels |
84
+ | `size` | `number` | — | Shorthand to set width and height equally |
85
+
86
+ ### Colour modes
87
+
88
+ **`{ type: 'hsl' }`** — hue derived from seed, noise shifts hue/saturation/lightness.
89
+
90
+ | Option | Type | Default |
91
+ |---|---|---|
92
+ | `hueRange` | `number` | `60` |
93
+ | `saturationRange` | `[number, number]` | `[45, 70]` |
94
+ | `lightnessRange` | `[number, number]` | `[40, 70]` |
95
+
96
+ **`{ type: 'grayscale' }`** — noise value maps to luminance.
97
+
98
+ | Option | Type | Default |
99
+ |---|---|---|
100
+ | `range` | `[number, number]` | `[0, 255]` |
101
+
102
+ **`{ type: 'palette', colors }`** — noise value interpolates through an ordered list of RGB colours.
103
+
104
+ ```ts
105
+ colorMode: {
106
+ type: 'palette',
107
+ colors: [[0, 0, 128], [0, 200, 255], [255, 255, 255]],
108
+ }
109
+ ```
110
+
111
+ ---
112
+
113
+ ### Core primitives
114
+
115
+ | Export | Description |
116
+ |---|---|
117
+ | `hash32(str)` | djb2 hash → unsigned 32-bit integer |
118
+ | `makePrng(seed)` | Seeded LCG PRNG → `() => float in [0, 1)` |
119
+ | `hslToRgb(h, s, l)` | HSL (components in `[0, 1]`) → RGB triple (`[0, 255]`) |
120
+ | `makeValueNoiseSampler(gridSize, rng)` | Returns `(nx, ny) → float in [0, 1]` value-noise sampler |
121
+
122
+ ## Licence
123
+
124
+ AGPL-3.0-only
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ewanc26/noise",
3
+ "version": "0.1.0",
4
+ "description": "Generic deterministic value-noise generation. Arbitrary dimensions, multi-octave FBM, multiple colour modes. Zero runtime dependencies, works in browsers and Node.js.",
5
+ "author": "Ewan Croft",
6
+ "license": "AGPL-3.0-only",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
24
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
25
+ "type-check": "tsc --noEmit"
26
+ },
27
+ "keywords": [
28
+ "noise",
29
+ "procedural",
30
+ "canvas",
31
+ "deterministic",
32
+ "fbm",
33
+ "value-noise"
34
+ ],
35
+ "devDependencies": {
36
+ "tsup": "^8.5.1",
37
+ "typescript": "^5.9.3"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }