@ewanc26/noise 0.1.1 → 0.1.2
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/README.md +3 -114
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,124 +1,13 @@
|
|
|
1
1
|
# @ewanc26/noise
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Part of the [`@ewanc26/pkgs`](https://github.com/ewanc26/pkgs) monorepo.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
3
|
+
Deterministic value-noise generation from a string seed — arbitrary dimensions, multi-octave FBM, multiple colour modes. Zero dependencies.
|
|
8
4
|
|
|
9
5
|
```bash
|
|
10
6
|
pnpm add @ewanc26/noise
|
|
11
7
|
```
|
|
12
8
|
|
|
13
|
-
|
|
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 |
|
|
9
|
+
Full documentation at **[docs.ewancroft.uk](https://docs.ewancroft.uk/projects/noise)**.
|
|
121
10
|
|
|
122
11
|
## Licence
|
|
123
12
|
|
|
124
|
-
AGPL-3.0-only
|
|
13
|
+
AGPL-3.0-only.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ewanc26/noise",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
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
5
|
"author": "Ewan Croft",
|
|
6
6
|
"license": "AGPL-3.0-only",
|