textmode.js 0.2.0-beta.4 → 0.2.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.
package/README.md CHANGED
@@ -10,32 +10,36 @@
10
10
 
11
11
  </div>
12
12
 
13
- `textmode.js` is a free, lightweight and framework-agnostic creative coding library for real-time ASCII art and textmode experiences in web browsers.
13
+ textmode.js is a lightweight creative-coding library for realtime ASCII and textmode graphics in the browser. It combines a grid‑based API with a modern `WebGL2` pipeline, multiple render targets, and aggressive instanced rendering to deliver smooth, high‑performance rendering.
14
14
 
15
- Transform any `<canvas>` or `<video>` element into dynamic ASCII representations with blazing-fast WebGL rendering. Whether you're using p5.js, three.js, or vanilla JavaScript, textmode.js seamlessly integrates with your existing projects to create interactive textmode games, live visual performances, and artistic installations.
15
+ The library is designed to be easy to use and accessible to developers of all skill levels. Whether you're a seasoned developer or just starting out, `textmode.js` provides a simple and intuitive API that makes it easy to create stunning textmode art and animations.
16
16
 
17
- For standalone projects, textmode.js provides its own p5.js-inspired drawing API, letting you create compelling ASCII experiences without additional dependencies.
18
-
19
- The library powers live coding performances, interactive installations, and digital art projects worldwide, bringing the nostalgic aesthetic of textmode art into modern web development.
17
+ Key ideas in one sentence: you draw with simple shape calls; under the hood we batch instances and write to a special framebuffer with five render targets; a conversion pass maps those buffers to a crisp grid of characters on the canvas.
20
18
 
21
19
  ## Features
22
- - **Dependency-free**: No external libraries required, making it lightweight and easy to integrate into any project.
23
- - **TTF/OTF font support**: Load and use TrueType and OpenType fonts for rendering textmode art, allowing for a wide range of styles and characters.
24
- - **Framework-agnostic**: Use `textmode.js` with any JavaScript framework or library, such as `p5.js`, `three.js`, or even vanilla JavaScript.
25
- - **Standalone drawing API**: Use the built-in `p5.js`-like drawing API for creating textmode art without any other dependencies.
26
- - **Injectable**: Easily inject `textmode.js` into websites like YouTube to convert `<video>` or `<canvas>` elements into textmode representations for a unique viewing experience.
27
- - **WebGL1/WebGL2 support**: All shader code provided by `textmode.js` is written in `GLSL ES 1.0`, making it compatible with both `WebGL1` and `WebGL2` contexts, allowing for a wide range of devices to run your ASCII projects.
28
- - **Exporting**: Export your creations to various image formats, and as `.txt`, `.svg` and image files for easy sharing, printing and plotting.
29
- - **Typescript support**: Fully typed library with TypeScript definitions, making it easy to integrate into TypeScript projects and ensuring type safety.
20
+ - Real‑time* ASCII/textmode rendering with a simple drawing API
21
+ - `WebGL2` pipeline with [Multiple Render Targets (MRT)](https://en.wikipedia.org/wiki/Multiple_Render_Targets) for rich per‑cell data
22
+ - Instanced rendering and batching for low draw call counts
23
+ - Font system with runtime font loading and dynamic sizing
24
+ - Author custom filter shaders in [`GLSL ES 3.00`](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf) for advanced effects
25
+ - Flexible exporting: TXT, SVG, and raster images *(PNG/JPG/WebP)*
26
+ - Animation loop control: `frameRate`, `loop`/`noLoop`, `redraw`, `frameCount`, etc.
27
+ - Zero dependencies, written in TypeScript, with comprehensive type definitions
28
+
29
+ > [!NOTE]
30
+ > *Performance depends on the complexity of your scene and device capabilities. Consider authoring filter shaders for complex effects at low cost.
30
31
 
31
32
  ## Installation
32
33
 
33
34
  ### Prerequisites
34
35
 
35
36
  To get started with `textmode.js`, you'll need:
36
- - A **modern web browser** with `WebGL` support
37
- - A `<canvas>` or `<video>` element in your project *(optional, for capturing content from a different source)*
38
- - **Node.js 16+** and `npm` *(optional, for ESM installation)*
37
+ - A **modern web browser** with `WebGL2` support *(Chrome, Firefox, Safari, Edge, etc.)*
38
+ - A [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) in your project *(optional, otherwise the library will create one for you)*
39
+ - [Node.js 16+](https://nodejs.org/) and `npm` *(optional, for ESM installation)*
40
+
41
+ > [!IMPORTANT]
42
+ > `textmode.js` is currently fully dependent on `WebGL2`. Ensure your target browsers support it. You can check compatibility on [caniuse.com](https://caniuse.com/webgl2).
39
43
 
40
44
  ### Importing `textmode.js`
41
45
 
@@ -43,28 +47,31 @@ To get started with `textmode.js`, you'll need:
43
47
 
44
48
  | Bundle type | File size | Font included? | Best for |
45
49
  |-------------|-----------|---------------|----------|
46
- | **Standard UMD**<br/>(`textmode.umd.js`) | ~111kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
47
- | **Standard ESM**<br/>(`textmode.esm.js`) | ~128kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
48
- | **Minified UMD**<br/>(`textmode.umd.min.js`) | ~64kB | ❌ Requires external font | Production apps, custom fonts |
49
- | **Minified ESM**<br/>(`textmode.esm.min.js`) | ~82kB | ❌ Requires external font | Production apps, custom fonts |
50
+ | **Standard UMD** (`textmode.umd.js`) | ~112kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
51
+ | **Standard ESM** (`textmode.esm.js`) | ~130kB | ✅ [UrsaFont](https://ursafrank.itch.io/ursafont) embedded | Quick setup, prototyping |
52
+ | **Minified UMD** (`textmode.umd.min.js`) | ~65kB | ❌ Requires external font | Custom fonts |
53
+ | **Minified ESM** (`textmode.esm.min.js`) | ~84kB | ❌ Requires external font | Custom fonts |
50
54
 
51
55
  **Choose standard bundles for:**
52
56
  - Quick setup with no additional configuration
53
- - Everything embedded and ready to use
54
- - Getting started without worrying about fonts
57
+ - Production applications that use the embedded font
55
58
 
56
59
  **Choose minified bundles for:**
57
60
  - Production applications that don't use the embedded font
58
61
 
59
- #### UMD
62
+ > [!NOTE]
63
+ > Apart from the font inclusion, both bundle types are functionally identical and equally minified.
64
+
65
+ ### UMD
60
66
 
61
67
  To use `textmode.js` in a UMD environment, download the latest `umd` build from the [**GitHub releases page**](https://github.com/humanbydefinition/textmode.js/releases/) or import it directly from a CDN like [**jsDelivr**](https://www.jsdelivr.com/package/npm/textmode.js). The library is distributed as a single JavaScript file, which you can include in your project by adding the following script tag to your HTML file:
62
68
 
63
69
  ```html
70
+ <!-- index.html -->
64
71
  <!DOCTYPE html>
65
72
  <html>
66
73
  <head>
67
- <title>textmode.js example</title>
74
+ <title>textmode.js sketch</title>
68
75
 
69
76
  <!-- Standard bundle (with embedded UrsaFont) -->
70
77
  <script src="https://cdn.jsdelivr.net/npm/textmode.js@latest/dist/textmode.umd.js"></script>
@@ -73,26 +80,40 @@ To use `textmode.js` in a UMD environment, download the latest `umd` build from
73
80
  <!-- <script src="https://cdn.jsdelivr.net/npm/textmode.js@latest/dist/textmode.umd.min.js"></script> -->
74
81
  </head>
75
82
  <body>
76
- <canvas id="myCanvas" width="800" height="600"></canvas>
77
- <script>
78
- (async () => {
79
- // Reference your existing canvas element
80
- const canvas = document.querySelector('canvas#myCanvas');
81
-
82
- // Standard bundle - no font configuration needed
83
- const textmodifier = await textmode.create(canvas);
84
-
85
- // Minified bundle - font required
86
- // const textmodifier = await textmode.create(canvas, {
87
- // fontSource: './path/to/your/font.ttf'
88
- // });
89
- })();
90
- </script>
83
+ <script src="sketch.js"></script>
91
84
  </body>
92
85
  </html>
93
86
  ```
94
87
 
95
- #### ESM
88
+ ```javascript
89
+ // sketch.js
90
+ const t = textmode.create({
91
+ width: window.innerWidth,
92
+ height: window.innerHeight,
93
+ fontSize: 16,
94
+ frameRate: 60
95
+ });
96
+
97
+ t.setup(() => {
98
+ // Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
99
+ });
100
+
101
+ t.draw(() => {
102
+ t.background(32); // Dark gray background
103
+
104
+ t.char('A');
105
+ t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
106
+ t.rect(0, 0, t.grid.cols / 2, t.grid.rows / 2);
107
+
108
+ // ...add your drawing code here!
109
+ });
110
+
111
+ t.windowResized(() => {
112
+ t.resizeCanvas(window.innerWidth, window.innerHeight);
113
+ });
114
+ ```
115
+
116
+ ### ESM
96
117
 
97
118
  To use `textmode.js` in an ESM environment, you can install it via `npm`:
98
119
 
@@ -102,43 +123,73 @@ npm install textmode.js
102
123
 
103
124
  Then, you can import it in your JavaScript or TypeScript files:
104
125
 
126
+ ```html
127
+ <!-- index.html -->
128
+ <!DOCTYPE html>
129
+ <html lang="en">
130
+ <head>
131
+ <meta charset="utf-8">
132
+ <title>textmode.js sketch</title>
133
+ </head>
134
+ <body>
135
+ <script type="module" src="./sketch.js"></script>
136
+ </body>
137
+ </html>
138
+ ```
139
+
105
140
  ```javascript
141
+ // sketch.js
106
142
  // Standard bundle (with embedded UrsaFont)
107
143
  import { textmode } from 'textmode.js';
108
144
 
109
145
  // OR Minified bundle (requires external font)
110
146
  // import { textmode } from 'textmode.js/min';
111
147
 
112
- (async () => {
113
- // Canvas example
114
- const canvas = document.querySelector('canvas#myCanvas');
115
-
116
- // Standard bundle - no font configuration needed
117
- const textmodifier = await textmode.create(canvas);
118
-
119
- // Minified bundle - font required
120
- // const textmodifier = await textmode.create(canvas, {
121
- // fontSource: './path/to/your/font.ttf'
122
- // });
123
- })();
148
+ const t = textmode.create({
149
+ width: window.innerWidth,
150
+ height: window.innerHeight,
151
+ fontSize: 16,
152
+ frameRate: 60
153
+ });
154
+
155
+ t.setup(() => {
156
+ // Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
157
+ });
158
+
159
+ t.draw(() => {
160
+ t.background(32); // Dark gray background
161
+
162
+ t.char('A');
163
+ t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
164
+ t.rect(0, 0, t.grid.cols / 2, t.grid.rows / 2);
165
+
166
+ // ...add your drawing code here!
167
+ });
168
+
169
+ t.windowResized(() => {
170
+ t.resizeCanvas(window.innerWidth, window.innerHeight);
171
+ });
124
172
  ```
125
173
 
126
- ### Next steps
174
+ ## Verification
175
+
176
+ To verify your installation is working correctly, try this simple test:
177
+
178
+ ```javascript
179
+ // Test if textmode.js is available
180
+ console.log('textmode.js version:', textmode.version);
181
+ ```
127
182
 
128
- Now that you have `textmode.js` set up, you can start creating your ASCII art projects! Check out the [**API documentation**](/api/) for detailed information on how to use the library, including examples and advanced features.
183
+ > [!NOTE]
184
+ > If you see the version number printed in the console, your installation was successful!
129
185
 
130
- ## Learn more
186
+ ## Next steps
131
187
 
132
- ### 📚 [Visit the Official Documentation](https://code.textmode.art/)
188
+ Now that you have `textmode.js` set up, you can start creating your textmode art projects! Going forward, here are some resources to help you get the most out of the library:
133
189
 
134
- Explore the comprehensive documentation at [code.textmode.art](https://code.textmode.art/) for:
135
- - Detailed guides
136
- - Interactive examples
137
- - Complete API reference
138
- - Tips and tricks
139
- - ... and much more!
190
+ 📚 **[Visit the Official Documentation](https://code.textmode.art/)** for detailed guides, interactive examples, complete API reference, tips and tricks, and much more to unlock the full potential of `textmode.js` in your creative coding projects.
140
191
 
141
- The documentation will help you unlock the full potential of `textmode.js` in your creative coding projects.
192
+ 🎨 **[Try the Web Editor](https://editor.textmode.art)** to experiment with `textmode.js` without setting up a local environment.
142
193
 
143
194
  ## Acknowledgements
144
195