textmode.js 0.9.0-beta.2 → 0.9.0-beta.4
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/LICENSE +21 -0
- package/README.md +180 -179
- package/dist/textmode.esm.js +2562 -2779
- package/dist/textmode.umd.js +16 -18
- package/package.json +151 -107
- package/dist/types/Textmode.d.ts +0 -62
- package/dist/types/errors/Error.d.ts +0 -11
- package/dist/types/errors/ErrorHandler.d.ts +0 -77
- package/dist/types/errors/index.d.ts +0 -2
- package/dist/types/exports/conversion.d.ts +0 -1
- package/dist/types/exports/filters.d.ts +0 -1
- package/dist/types/exports/input.d.ts +0 -1
- package/dist/types/exports/layering.d.ts +0 -1
- package/dist/types/exports/loadables.d.ts +0 -1
- package/dist/types/exports/loading.d.ts +0 -1
- package/dist/types/exports/plugins.d.ts +0 -1
- package/dist/types/index.d.ts +0 -83
- package/dist/types/rendering/index.d.ts +0 -3
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +0 -89
- package/dist/types/rendering/webgl/batching/GeometryAttributeCache.d.ts +0 -15
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +0 -87
- package/dist/types/rendering/webgl/batching/InstanceBatch.d.ts +0 -82
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +0 -78
- package/dist/types/rendering/webgl/batching/InstanceData.d.ts +0 -60
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +0 -70
- package/dist/types/rendering/webgl/core/Framebuffer.d.ts +0 -93
- package/dist/types/rendering/webgl/core/Renderer.d.ts +0 -75
- package/dist/types/rendering/webgl/core/Shader.d.ts +0 -65
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +0 -96
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +0 -210
- package/dist/types/rendering/webgl/geometries/2d/Arc.d.ts +0 -17
- package/dist/types/rendering/webgl/geometries/2d/BezierCurve.d.ts +0 -23
- package/dist/types/rendering/webgl/geometries/2d/Ellipse.d.ts +0 -21
- package/dist/types/rendering/webgl/geometries/2d/Line.d.ts +0 -21
- package/dist/types/rendering/webgl/geometries/2d/Rectangle.d.ts +0 -21
- package/dist/types/rendering/webgl/geometries/2d/Triangle.d.ts +0 -21
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +0 -53
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +0 -33
- package/dist/types/rendering/webgl/geometries/index.d.ts +0 -6
- package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +0 -31
- package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +0 -16
- package/dist/types/rendering/webgl/index.d.ts +0 -19
- package/dist/types/rendering/webgl/materials/Material.d.ts +0 -26
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +0 -62
- package/dist/types/rendering/webgl/materials/index.d.ts +0 -2
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +0 -63
- package/dist/types/rendering/webgl/pipeline/index.d.ts +0 -7
- package/dist/types/rendering/webgl/state/RenderState.d.ts +0 -143
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +0 -20
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +0 -144
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +0 -14
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +0 -45
- package/dist/types/rendering/webgl/utils/ViewportCache.d.ts +0 -4
- package/dist/types/rendering/webgl/utils/hash.d.ts +0 -102
- package/dist/types/textmode/AnimationController.d.ts +0 -100
- package/dist/types/textmode/Canvas.d.ts +0 -53
- package/dist/types/textmode/Grid.d.ts +0 -92
- package/dist/types/textmode/TextmodeColor.d.ts +0 -61
- package/dist/types/textmode/Textmodifier.d.ts +0 -103
- package/dist/types/textmode/conversion/ConversionManager.d.ts +0 -73
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +0 -92
- package/dist/types/textmode/conversion/index.d.ts +0 -3
- package/dist/types/textmode/conversion/strategies/brightness.d.ts +0 -2
- package/dist/types/textmode/filters/FilterManager.d.ts +0 -128
- package/dist/types/textmode/filters/FilterRegistry.d.ts +0 -75
- package/dist/types/textmode/filters/index.d.ts +0 -3
- package/dist/types/textmode/filters/types.d.ts +0 -77
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +0 -441
- package/dist/types/textmode/interfaces/index.d.ts +0 -1
- package/dist/types/textmode/layers/Camera3D.d.ts +0 -205
- package/dist/types/textmode/layers/Layer2DCompositor.d.ts +0 -79
- package/dist/types/textmode/layers/Layer3DCompositor.d.ts +0 -152
- package/dist/types/textmode/layers/LayerManager.d.ts +0 -151
- package/dist/types/textmode/layers/TextmodeLayer.d.ts +0 -106
- package/dist/types/textmode/layers/index.d.ts +0 -8
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +0 -102
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +0 -427
- package/dist/types/textmode/layers/types.d.ts +0 -78
- package/dist/types/textmode/loadables/ITextmodeSource.d.ts +0 -123
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +0 -46
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +0 -67
- package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +0 -34
- package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +0 -25
- package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +0 -23
- package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +0 -106
- package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +0 -56
- package/dist/types/textmode/loadables/font/index.d.ts +0 -8
- package/dist/types/textmode/loadables/font/types.d.ts +0 -44
- package/dist/types/textmode/loadables/font/typr/Typr.d.ts +0 -20
- package/dist/types/textmode/loadables/font/typr/types.d.ts +0 -238
- package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +0 -40
- package/dist/types/textmode/loadables/font/utils/index.d.ts +0 -7
- package/dist/types/textmode/loadables/index.d.ts +0 -4
- package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +0 -75
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +0 -93
- package/dist/types/textmode/loading/LoadingPhase.d.ts +0 -28
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +0 -20
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +0 -209
- package/dist/types/textmode/loading/LoadingScreenState.d.ts +0 -22
- package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +0 -26
- package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +0 -17
- package/dist/types/textmode/loading/index.d.ts +0 -7
- package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +0 -2
- package/dist/types/textmode/loading/templates/index.d.ts +0 -1
- package/dist/types/textmode/loading/types.d.ts +0 -255
- package/dist/types/textmode/managers/KeyboardManager.d.ts +0 -124
- package/dist/types/textmode/managers/MouseManager.d.ts +0 -163
- package/dist/types/textmode/managers/PluginManager.d.ts +0 -226
- package/dist/types/textmode/managers/TouchManager.d.ts +0 -240
- package/dist/types/textmode/managers/index.d.ts +0 -12
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +0 -8
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +0 -13
- package/dist/types/textmode/mixins/MouseMixin.d.ts +0 -10
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +0 -8
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +0 -19
- package/dist/types/textmode/mixins/TouchMixin.d.ts +0 -6
- package/dist/types/textmode/mixins/index.d.ts +0 -9
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +0 -300
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +0 -234
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +0 -448
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +0 -1151
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +0 -186
- package/dist/types/textmode/types.d.ts +0 -46
- package/dist/types/textmode/utils/cssColor.d.ts +0 -8
- package/dist/types/utils/TextmodeCollection.d.ts +0 -262
- package/dist/types/utils/array.d.ts +0 -34
- package/dist/types/utils/color.d.ts +0 -1
- package/dist/types/utils/mat3.d.ts +0 -149
- package/dist/types/utils/math.d.ts +0 -95
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 humanbydefinition
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,179 +1,180 @@
|
|
|
1
|
-
# textmode.js (✿◠‿◠)
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
|
|
5
|
-
<img alt="textmodejs_banner" src="https://github.com/user-attachments/assets/f03c2d74-7dc3-45cf-a0a5-043f9438231e" />
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- ✨ **Zero setup required** - Start coding immediately
|
|
41
|
-
- 🚀 **Live preview** - See your creations in real-time
|
|
42
|
-
- 💾 **Save & share** - Export your sketches and share with others
|
|
43
|
-
- 📚 **Built-in examples** - Learn from interactive examples
|
|
44
|
-
- 🔧 **Full API access** - All `textmode.js` features available
|
|
45
|
-
|
|
46
|
-
The web editor is perfect for learning, prototyping, or creating quick experiments without any local setup!
|
|
47
|
-
|
|
48
|
-
## Installation
|
|
49
|
-
|
|
50
|
-
### Prerequisites
|
|
51
|
-
|
|
52
|
-
To get started with `textmode.js`, you'll need:
|
|
53
|
-
|
|
54
|
-
- A
|
|
55
|
-
- [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
</
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
t.
|
|
100
|
-
t.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
t.
|
|
154
|
-
|
|
155
|
-
t.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
`textmode.js`
|
|
179
|
-
|
|
1
|
+
# textmode.js (✿◠‿◠)
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
<img alt="textmodejs_banner" src="https://github.com/user-attachments/assets/f03c2d74-7dc3-45cf-a0a5-043f9438231e" />
|
|
6
|
+
|
|
7
|
+
| [](https://www.typescriptlang.org/) [](https://www.khronos.org/webgl/) [](https://vitejs.dev/) | [](https://code.textmode.art/) [](https://discord.gg/sjrw8QXNks) | [](https://ko-fi.com/V7V8JG2FY) [](https://github.com/sponsors/humanbydefinition) |
|
|
8
|
+
|:-------------|:-------------|:-------------|
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
textmode.js is a free, lightweight, and framework-agnostic creative-coding library for real‑time ASCII and textmode graphics in the browser. It combines a grid‑based API with a modern [`WebGL2`](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext) pipeline, multiple render targets, and aggressive instanced rendering to deliver smooth, high‑performance rendering.
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Real‑time* ASCII/textmode rendering with a simple drawing API
|
|
19
|
+
- Font system with runtime font loading and dynamic sizing *(supports TTF/OTF/WOFF)*
|
|
20
|
+
- Dynamic layering system with blend modes and opacity for multi‑layered textmode scenes
|
|
21
|
+
- Filter system with built-in filters and support for custom filter shaders
|
|
22
|
+
- Load images and videos as sources and render them in customizable textmode styles
|
|
23
|
+
- 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
|
|
24
|
+
- Flexible exporting: TXT, SVG, raster images *(PNG/JPG/WebP)*, animated GIFs, and video *(WebM)*
|
|
25
|
+
- Animation loop control: `frameRate`, `loop`/`noLoop`, `redraw`, `frameCount`, etc.
|
|
26
|
+
- Framework-agnostic: Use `textmode.js` with any canvas-based framework or library
|
|
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.
|
|
31
|
+
|
|
32
|
+
## Try it online first
|
|
33
|
+
|
|
34
|
+
Before installing anything locally, you can try `textmode.js` directly in your browser using our dedicated web editor:
|
|
35
|
+
|
|
36
|
+
🌐 **[editor.textmode.art](https://editor.textmode.art)**
|
|
37
|
+
|
|
38
|
+
The web editor is specifically designed for `textmode.js` and provides:
|
|
39
|
+
|
|
40
|
+
- ✨ **Zero setup required** - Start coding immediately
|
|
41
|
+
- 🚀 **Live preview** - See your creations in real-time
|
|
42
|
+
- 💾 **Save & share** - Export your sketches and share with others
|
|
43
|
+
- 📚 **Built-in examples** - Learn from interactive examples
|
|
44
|
+
- 🔧 **Full API access** - All `textmode.js` features available
|
|
45
|
+
|
|
46
|
+
The web editor is perfect for learning, prototyping, or creating quick experiments without any local setup!
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
### Prerequisites
|
|
51
|
+
|
|
52
|
+
To get started with `textmode.js`, you'll need:
|
|
53
|
+
|
|
54
|
+
- A **modern web browser** with `WebGL2` support *(Chrome, Firefox, Safari, Edge, etc.)*
|
|
55
|
+
- 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)*
|
|
56
|
+
- [Node.js 16+](https://nodejs.org/) and `npm` *(optional, for ESM installation)*
|
|
57
|
+
|
|
58
|
+
> [!IMPORTANT]
|
|
59
|
+
> `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).
|
|
60
|
+
|
|
61
|
+
### Importing `textmode.js`
|
|
62
|
+
|
|
63
|
+
#### UMD
|
|
64
|
+
|
|
65
|
+
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:
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<!-- index.html -->
|
|
69
|
+
<!DOCTYPE html>
|
|
70
|
+
<html>
|
|
71
|
+
<head>
|
|
72
|
+
<title>textmode.js sketch</title>
|
|
73
|
+
|
|
74
|
+
<!-- Standard bundle (with embedded UrsaFont) -->
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/textmode.js@latest/dist/textmode.umd.js"></script>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
<script src="sketch.js"></script>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
// sketch.js
|
|
85
|
+
const t = textmode.create({
|
|
86
|
+
width: window.innerWidth,
|
|
87
|
+
height: window.innerHeight,
|
|
88
|
+
fontSize: 16,
|
|
89
|
+
frameRate: 60
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
t.setup(() => {
|
|
93
|
+
// Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
t.draw(() => {
|
|
97
|
+
t.background(32); // Dark gray background
|
|
98
|
+
|
|
99
|
+
t.char('A');
|
|
100
|
+
t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
|
|
101
|
+
t.translate(-t.grid.cols / 4, -t.grid.rows / 4);
|
|
102
|
+
t.rect(t.grid.cols / 2, t.grid.rows / 2);
|
|
103
|
+
|
|
104
|
+
// ...add your drawing code here!
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
t.windowResized(() => {
|
|
108
|
+
t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### ESM
|
|
113
|
+
|
|
114
|
+
To use `textmode.js` in an ESM environment, you can install it via `npm`:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npm install textmode.js
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Then, you can import it in your JavaScript or TypeScript files:
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<!-- index.html -->
|
|
124
|
+
<!DOCTYPE html>
|
|
125
|
+
<html lang="en">
|
|
126
|
+
<head>
|
|
127
|
+
<meta charset="utf-8">
|
|
128
|
+
<title>textmode.js sketch</title>
|
|
129
|
+
</head>
|
|
130
|
+
<body>
|
|
131
|
+
<script type="module" src="./sketch.js"></script>
|
|
132
|
+
</body>
|
|
133
|
+
</html>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// sketch.js
|
|
138
|
+
// Standard bundle (with embedded UrsaFont)
|
|
139
|
+
import { textmode } from 'textmode.js';
|
|
140
|
+
|
|
141
|
+
const t = textmode.create({
|
|
142
|
+
width: window.innerWidth,
|
|
143
|
+
height: window.innerHeight,
|
|
144
|
+
fontSize: 16,
|
|
145
|
+
frameRate: 60
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
t.setup(() => {
|
|
149
|
+
// Optional setup code here (e.g., load fonts/shaders, initialize variables that access 't')
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
t.draw(() => {
|
|
153
|
+
t.background(32); // Dark gray background
|
|
154
|
+
|
|
155
|
+
t.char('A');
|
|
156
|
+
t.charColor(255, 0, 0); // Cover the top-left quarter of the grid with a rectangle of red 'A's
|
|
157
|
+
t.translate(-t.grid.cols / 4, -t.grid.rows / 4);
|
|
158
|
+
t.rect(t.grid.cols / 2, t.grid.rows / 2);
|
|
159
|
+
|
|
160
|
+
// ...add your drawing code here!
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
t.windowResized(() => {
|
|
164
|
+
t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Next steps
|
|
169
|
+
|
|
170
|
+
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:
|
|
171
|
+
|
|
172
|
+
📚 **[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.
|
|
173
|
+
|
|
174
|
+
🎨 **[Try the Web Editor](https://editor.textmode.art)** to experiment with `textmode.js` without setting up a local environment.
|
|
175
|
+
|
|
176
|
+
## Acknowledgements
|
|
177
|
+
|
|
178
|
+
`textmode.js` uses a custom-made TypeScript rewrite and minified version of [`Typr.js`](https://github.com/photopea/Typr.js) by [**Photopea**](https://github.com/photopea) for font loading and parsing, containing only the necessary components for our use case. `Typr.js` is licensed under the [**MIT License**](https://github.com/photopea/Typr.js/blob/main/LICENSE).
|
|
179
|
+
|
|
180
|
+
`textmode.js` ships with [`UrsaFont`](https://ursafrank.itch.io/ursafont) as the default font, created by [**UrsaFrank**](https://ursafrank.itch.io/). This font is available under the [**CC0 (Creative Commons Zero) license**](https://creativecommons.org/publicdomain/zero/1.0/).
|