textmode.synth.js 1.0.0-beta.1 → 1.0.0-beta.3

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 (85) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +104 -121
  3. package/dist/textmode.synth.esm.js +491 -410
  4. package/dist/textmode.synth.umd.js +31 -52
  5. package/dist/types/api/index.d.ts +7 -0
  6. package/dist/types/api/index.d.ts.map +1 -0
  7. package/dist/types/api/sources.d.ts +327 -0
  8. package/dist/types/api/sources.d.ts.map +1 -0
  9. package/dist/types/augmentations/index.d.ts +7 -0
  10. package/dist/types/augmentations/index.d.ts.map +1 -0
  11. package/dist/types/augmentations/textmode.d.ts +65 -0
  12. package/dist/types/augmentations/textmode.d.ts.map +1 -0
  13. package/dist/types/bootstrap.d.ts +11 -0
  14. package/dist/types/bootstrap.d.ts.map +1 -0
  15. package/dist/types/compiler/ExternalLayerManager.d.ts +60 -0
  16. package/dist/types/compiler/ExternalLayerManager.d.ts.map +1 -0
  17. package/dist/types/compiler/FeedbackTracker.d.ts +53 -0
  18. package/dist/types/compiler/FeedbackTracker.d.ts.map +1 -0
  19. package/dist/types/compiler/GLSLGenerator.d.ts +2 -2
  20. package/dist/types/compiler/GLSLGenerator.d.ts.map +1 -1
  21. package/dist/types/compiler/SynthCompiler.d.ts +7 -1
  22. package/dist/types/compiler/SynthCompiler.d.ts.map +1 -1
  23. package/dist/types/compiler/TransformCodeGenerator.d.ts +77 -0
  24. package/dist/types/compiler/TransformCodeGenerator.d.ts.map +1 -0
  25. package/dist/types/compiler/UniformManager.d.ts.map +1 -1
  26. package/dist/types/compiler/index.d.ts +14 -3
  27. package/dist/types/compiler/index.d.ts.map +1 -1
  28. package/dist/types/compiler/types.d.ts +7 -7
  29. package/dist/types/compiler/types.d.ts.map +1 -1
  30. package/dist/types/core/GlobalState.d.ts +30 -0
  31. package/dist/types/core/GlobalState.d.ts.map +1 -0
  32. package/dist/types/core/ISynthSource.d.ts +173 -202
  33. package/dist/types/core/ISynthSource.d.ts.map +1 -1
  34. package/dist/types/core/SynthChain.d.ts +0 -2
  35. package/dist/types/core/SynthChain.d.ts.map +1 -1
  36. package/dist/types/core/SynthSource.d.ts +4 -3
  37. package/dist/types/core/SynthSource.d.ts.map +1 -1
  38. package/dist/types/core/index.d.ts +9 -3
  39. package/dist/types/core/index.d.ts.map +1 -1
  40. package/dist/types/core/types.d.ts +57 -4
  41. package/dist/types/core/types.d.ts.map +1 -1
  42. package/dist/types/extensions/index.d.ts +10 -0
  43. package/dist/types/extensions/index.d.ts.map +1 -0
  44. package/dist/types/extensions/textmodelayer.d.ts +22 -0
  45. package/dist/types/extensions/textmodelayer.d.ts.map +1 -0
  46. package/dist/types/extensions/textmodifier.d.ts +11 -0
  47. package/dist/types/extensions/textmodifier.d.ts.map +1 -0
  48. package/dist/types/index.d.ts +11 -364
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/dist/types/lifecycle/index.d.ts +10 -0
  51. package/dist/types/lifecycle/index.d.ts.map +1 -0
  52. package/dist/types/lifecycle/synthDispose.d.ts +11 -0
  53. package/dist/types/lifecycle/synthDispose.d.ts.map +1 -0
  54. package/dist/types/lifecycle/synthRender.d.ts +11 -0
  55. package/dist/types/lifecycle/synthRender.d.ts.map +1 -0
  56. package/dist/types/{SynthPlugin.d.ts → plugin/SynthPlugin.d.ts} +1 -1
  57. package/dist/types/plugin/SynthPlugin.d.ts.map +1 -0
  58. package/dist/types/plugin/constants.d.ts +5 -0
  59. package/dist/types/plugin/constants.d.ts.map +1 -0
  60. package/dist/types/plugin/index.d.ts +10 -0
  61. package/dist/types/plugin/index.d.ts.map +1 -0
  62. package/dist/types/transforms/TransformDefinition.d.ts +0 -12
  63. package/dist/types/transforms/TransformDefinition.d.ts.map +1 -1
  64. package/dist/types/transforms/TransformFactory.d.ts +4 -7
  65. package/dist/types/transforms/TransformFactory.d.ts.map +1 -1
  66. package/dist/types/transforms/TransformRegistry.d.ts +3 -6
  67. package/dist/types/transforms/TransformRegistry.d.ts.map +1 -1
  68. package/dist/types/transforms/categories/colors.d.ts +1 -1
  69. package/dist/types/transforms/categories/colors.d.ts.map +1 -1
  70. package/dist/types/transforms/categories/combine.d.ts.map +1 -1
  71. package/dist/types/transforms/categories/index.d.ts +3 -4
  72. package/dist/types/transforms/categories/index.d.ts.map +1 -1
  73. package/dist/types/transforms/categories/sources.d.ts.map +1 -1
  74. package/dist/types/{lib → utils}/ArrayUtils.d.ts +20 -5
  75. package/dist/types/utils/ArrayUtils.d.ts.map +1 -0
  76. package/dist/types/utils/CharacterResolver.d.ts.map +1 -1
  77. package/dist/types/utils/collectExternalLayerRefs.d.ts +7 -0
  78. package/dist/types/utils/collectExternalLayerRefs.d.ts.map +1 -0
  79. package/dist/types/utils/index.d.ts +12 -0
  80. package/dist/types/utils/index.d.ts.map +1 -0
  81. package/package.json +16 -9
  82. package/dist/types/SynthPlugin.d.ts.map +0 -1
  83. package/dist/types/lib/ArrayUtils.d.ts.map +0 -1
  84. package/dist/types/transforms/categories/charModifiers.d.ts +0 -16
  85. package/dist/types/transforms/categories/charModifiers.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,15 +1,33 @@
1
1
  # textmode.synth.js
2
2
 
3
- A `hydra`-inspired chainable visual synthesis system for `textmode.js`. Create procedural ASCII/text animations with simple, expressive code.
3
+ **A derivative work of [hydra-synth](https://github.com/hydra-synth/hydra-synth) by [Olivia Jack](https://github.com/ojack), adapted for the [textmode.js](https://github.com/humanbydefinition/textmode.js) ecosystem.**
4
+
5
+ Create procedural ASCII/text animations with a `hydra`-inspired, chainable visual synthesis system.
6
+
7
+ > [!NOTE]
8
+ > This project is work-in-progress and not yet ready for production use.
9
+ >
10
+ > `textmode.synth.js` becomes usable once `textmode.js` v0.9.0 is released.
4
11
 
5
12
  ## Features
6
13
 
7
- - 🎨 **Procedural Generation**: Generate characters, colors, and patterns using oscillators, noise, voronoi, and more
8
- - 🔗 **Method Chaining**: Hydra-style fluent API for building complex visual effects
9
- - 🎯 **Three-Texture System**: Independent control over characters, character colors, and cell backgrounds
10
- - ⚡ **WebGL Powered**: Compiled to optimized GLSL shaders for real-time performance
11
- - 🔄 **Feedback Loops**: Create trails, motion blur, and recursive patterns
12
- - 📦 **Compositional API**: Start with any aspect (char, color, background) and build from there
14
+ - 🎨 **Procedural generation** - Oscillators, noise, voronoi, and more
15
+ - 🔗 **Method chaining** - Hydra-style fluent API for complex visuals
16
+ - 🎯 **Three-texture system** - Independent control over characters, foreground, and background
17
+ - ⚡ **WebGL powered** - Compiled to optimized GLSL shaders
18
+ - 🔄 **Feedback loops** - Trails, motion blur, and recursive patterns
19
+ - 📦 **Compositional API** - Start from any aspect and build organically
20
+ - 📚 **Extensible** - Add your own sources, transforms, and more
21
+
22
+ ## Try it online first
23
+
24
+ > [!NOTE]
25
+ > The live coding environment is not yet live. It will be available in the next few days.
26
+
27
+ To go along with the release of this library, we've created a **live coding environment** where you can explore everything in the browser: [synth.textmode.art](https://synth.textmode.art)
28
+
29
+ It features IntelliSense & auto-completion, documentation on hover, curated examples to explore, and a lot more. The whole `textmode.js` ecosystem is available at your fingertips.
30
+
13
31
 
14
32
  ## Installation
15
33
 
@@ -17,164 +35,129 @@ A `hydra`-inspired chainable visual synthesis system for `textmode.js`. Create p
17
35
  npm install textmode.synth.js
18
36
  ```
19
37
 
20
- ## Quick Start
38
+ ## Quick start
21
39
 
22
40
  ```javascript
23
41
  import { textmode } from 'textmode.js';
24
- import { SynthPlugin, char, osc, noise, solid } from 'textmode.synth.js';
42
+ import { SynthPlugin, char, osc } from 'textmode.synth.js';
25
43
 
26
44
  const t = textmode.create({
27
- width: 800,
28
- height: 600,
29
- fontSize: 12,
45
+ width: window.innerWidth,
46
+ height: window.innerHeight,
47
+ fontSize: 16,
30
48
  plugins: [SynthPlugin]
31
49
  });
32
50
 
33
- // Create a simple animated pattern
34
- const pattern = osc(10, 0.1, 1.5);
51
+ const charChain = osc(1, -0.1, 0.5).kaleid(50);
52
+ const colorChain = osc(25, -0.1, 0.5).kaleid(50);
53
+
35
54
  t.layers.base.synth(
36
- char(pattern)
55
+ char(charChain)
37
56
  .charMap('@#%*+=-:. ')
38
- .charColor(pattern.clone())
39
- .cellColor(pattern.clone().invert())
57
+ .charColor(colorChain)
58
+ .cellColor(colorChain.clone().invert())
40
59
  );
60
+
61
+ t.windowResized(() => {
62
+ t.resizeCanvas(window.innerWidth, window.innerHeight);
63
+ });
41
64
  ```
42
65
 
43
- ## Core Concepts
66
+ ## Core concepts
44
67
 
45
- ### The New Compositional API
68
+ ### Compositional API
46
69
 
47
- textmode.synth.js provides three standalone functions for defining different aspects of your visual:
70
+ `textmode.js` renders to three textures: characters, foreground colors, and background colors. `textmode.synth.js` provides functions to drive each independently:
48
71
 
49
- - **`char(source, charCount?)`** - Define which pattern drives character generation
50
- - **`charColor(source)`** - Define character foreground colors
51
- - **`cellColor(source)`** - Define cell background colors
72
+ | Function | Purpose |
73
+ |----------|---------|
74
+ | `char(source, charCount?)` | Character generation |
75
+ | `charColor(source)` | Foreground color |
76
+ | `cellColor(source)` | Background color |
77
+ | `paint(source)` | Both foreground & background |
52
78
 
53
- You can start with any of these and chain the others:
79
+ Start from any entry point and chain the others:
54
80
 
55
81
  ```javascript
56
- // Start with character generation
57
- char(noise(10), 16)
58
- .charMap('@#%*+=-:. ')
59
- .charColor(osc(5))
60
- .cellColor(solid(0, 0, 0, 0.5));
61
-
62
- // Start with colors
63
- charColor(voronoi(5).mult(osc(20)))
64
- .char(noise(10), 16)
65
- .cellColor(gradient(0.5));
66
-
67
- // Start with background
68
- cellColor(solid(0, 0, 0, 0.8))
69
- .char(noise(10))
70
- .charColor(osc(5).kaleid(4));
71
- ```
82
+ // From characters
83
+ char(noise(10)).charColor(osc(5)).cellColor(solid(0,0,0,0.5));
72
84
 
73
- ### Source Generators
85
+ // From colors
86
+ charColor(voronoi(5)).char(noise(10)).cellColor(gradient(0.5));
74
87
 
75
- Create patterns using these generators:
88
+ // Shorthand for pixel art style
89
+ paint(noise(10));
90
+ ```
76
91
 
77
- - `osc(frequency, sync, offset)` - Oscillating sine wave patterns
78
- - `noise(scale, offset)` - Perlin noise
79
- - `voronoi(scale, speed, blending)` - Cellular/voronoi patterns
80
- - `gradient(speed)` - Rotating radial gradient
81
- - `shape(sides, radius, smoothing)` - Geometric shapes
82
- - `solid(r, g, b, a)` - Solid colors
92
+ ### Pixel art mode
83
93
 
84
- ### Transforms
94
+ Use `paint()` to color both foreground and background identically, effectively hiding the characters:
85
95
 
86
- Chain transforms to modify patterns:
96
+ ```javascript
97
+ t.fontSize(16);
98
+ t.layers.base.synth(paint(noise(10)));
99
+ ```
87
100
 
88
- **Geometry:** `rotate()`, `scale()`, `scroll()`, `pixelate()`, `repeat()`, `kaleid()`
89
- **Color:** `brightness()`, `contrast()`, `invert()`, `hue()`, `saturate()`, `colorama()`
90
- **Blend:** `add()`, `sub()`, `mult()`, `blend()`, `diff()`, `layer()`, `mask()`
91
- **Modulate:** `modulate()`, `modulateScale()`, `modulateRotate()`, `modulateScrollX()`, etc.
101
+ > **Tip:** With `t.fontSize(1)`, you can recreate most hydra visuals 1:1.
92
102
 
93
- ### Character Mapping
103
+ ### Direct source usage
94
104
 
95
- Use `.charMap()` to define which characters to display:
105
+ You can also pass a source directly to `.synth()` without any wrapper function:
96
106
 
97
107
  ```javascript
98
- char(noise(10))
99
- .charMap('@#%*+=-:. ') // ASCII gradient
100
- .charColor(osc(5));
101
-
102
- char(voronoi(5))
103
- .charMap('█▓▒░ ') // Block characters
104
- .charColor(gradient(0.5));
108
+ t.layers.base.synth(noise(10));
105
109
  ```
106
110
 
107
- ## Examples
111
+ This drives both characters *and* foreground colors from the same source *(background defaults to black)*. In practice, using separate sources for characters often looks better - character cycling is more rapid than color changes.
108
112
 
109
- ### Same Pattern for Everything
110
- ```javascript
111
- const pattern = osc([10, 30, 60].fast(2), 0.1);
112
- layer.synth(
113
- char(pattern)
114
- .charMap('@#%*+=-:. ')
115
- .charColor(pattern.clone())
116
- .cellColor(pattern.clone().invert())
117
- );
118
- ```
113
+ ### Source generators
119
114
 
120
- ### Different Patterns for Each Aspect
121
- ```javascript
122
- const charPattern = noise(5);
123
- const colorPattern = voronoi(10, 0.5).mult(osc(20));
124
- const bgPattern = gradient(0.2);
125
-
126
- layer.synth(
127
- char(charPattern, 16)
128
- .charMap(' .:-=+*#%@')
129
- .charColor(colorPattern)
130
- .cellColor(bgPattern.invert())
131
- );
132
- ```
133
-
134
- ### Feedback Loop
135
- ```javascript
136
- // Classic hydra-style feedback
137
- layer.synth(
138
- src()
139
- .modulate(noise(3), 0.005)
140
- .blend(shape(4), 0.01)
141
- );
142
- ```
115
+ | Generator | Description |
116
+ |-----------|-------------|
117
+ | `osc(freq, sync, offset)` | Sine wave patterns |
118
+ | `noise(scale, offset)` | Perlin noise |
119
+ | `voronoi(scale, speed, blend)` | Cellular patterns |
120
+ | `gradient(speed)` | Radial gradient |
121
+ | `shape(sides, radius, smooth)` | Geometric polygons |
122
+ | `solid(r, g, b, a)` | Solid colors |
123
+ | `src(layer?)` | Feedback / cross-layer sampling |
124
+ | `...` | ...and many more..? |
143
125
 
144
- ### Array Modulation
145
- ```javascript
146
- // Animate between multiple values
147
- layer.synth(
148
- char(osc([1, 10, 50, 100].fast(2), 0.1), 16)
149
- .charMap('@#%*+=-:. ')
150
- .charColor(osc([1, 10, 50, 100].fast(2), 0.1))
151
- );
152
- ```
126
+ ### Transforms
153
127
 
154
- ## Documentation
128
+ Chain transforms to modify patterns:
155
129
 
156
- - [Full API Documentation](./api/index.md)
157
- - [Compositional API Guide](./docs/COMPOSITIONAL-API.md)
158
- - [Examples](./examples/)
130
+ | Category | Methods |
131
+ |----------|---------|
132
+ | **Geometry** | `rotate`, `scale`, `scroll`, `pixelate`, `repeat`, `kaleid`, ... |
133
+ | **Color** | `brightness`, `contrast`, `invert`, `hue`, `saturate`, `colorama`, ... |
134
+ | **Blend** | `add`, `sub`, `mult`, `blend`, `diff`, `layer`, `mask`, ... |
135
+ | **Modulate** | `modulate`, `modulateScale`, `modulateRotate`, `modulateKaleid`, ... |
159
136
 
160
- ## Backward Compatibility
137
+ ### Character mapping
161
138
 
162
- The old `charOsc()`, `charNoise()`, etc. functions still work:
139
+ Use `.charMap()` to define the character set. By default, all characters available in the layer's font are used.
163
140
 
164
141
  ```javascript
165
- // Old style (still works)
166
- charOsc(10, 0.1, 0, 16)
167
- .charColor(osc(10, 0.1));
168
-
169
- // New style (recommended)
170
- char(osc(10, 0.1), 16)
171
- .charColor(osc(10, 0.1));
142
+ char(noise(10)).charMap('@#%*+=-:. '); // ASCII gradient
143
+ char(voronoi(5)).charMap('█▓▒░ '); // Block characters
172
144
  ```
173
145
 
146
+ ## Documentation
147
+
148
+ There's a lot more to explore beyond this overview:
149
+
150
+ - **[Online documentation](https://code.textmode.art/docs/synth)** - Full guides and tutorials
151
+ - **[API reference](./api/index.md)** - Complete API documentation
152
+ - **[synth.textmode.art](https://synth.textmode.art)** - Live coding environment
153
+
174
154
  ## License
175
155
 
176
- MIT
156
+ Distributed under the **AGPL-3.0** License. See [LICENSE](./LICENSE) for more information.
177
157
 
178
158
  ## Credits
179
159
 
180
- Inspired by [hydra-synth](https://github.com/hydra-synth/hydra-synth) by Olivia Jack.
160
+ This project is a derivative work of [hydra-synth](https://github.com/hydra-synth/hydra-synth) by [Olivia Jack](https://github.com/ojack), adapted for the [textmode.js](https://github.com/humanbydefinition/textmode.js) ecosystem.
161
+
162
+ - **hydra-synth**: Core synthesis logic, GLSL shader generation, and functional API design.
163
+ - **Modifications**: Adapted for `textmode.js`'s three-texture rendering pipeline *(characters, foreground colors, background colors)* and plugin system.