textmode.filters.js 1.0.1 → 1.1.1

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.
@@ -0,0 +1,1017 @@
1
+ /**
2
+ * Type definitions for all filter options in textmode.filters.js.
3
+ *
4
+ * Each filter can be applied using either:
5
+ * - A single value (shorthand for the primary parameter)
6
+ * - An options object with named parameters
7
+ * @example
8
+ * ```javascript
9
+ * const t = textmode.create({
10
+ * width: window.innerWidth,
11
+ * height: window.innerHeight,
12
+ * plugins: [FiltersPlugin],
13
+ * });
14
+ *
15
+ * let video;
16
+ *
17
+ * t.setup(async () => {
18
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
19
+ * video.play();
20
+ * video.loop();
21
+ * video.characters(' .:-=+*#%@');
22
+ * });
23
+ *
24
+ * t.draw(() => {
25
+ * t.background(0);
26
+ * if (video) {
27
+ * t.image(video, t.grid.cols, t.grid.rows);
28
+ * }
29
+ *
30
+ * const wobble = Math.sin(t.secs * 2);
31
+ * t.layers.base.filter('bloom', {
32
+ * threshold: 0.5,
33
+ * intensity: 1 + wobble * 0.35,
34
+ * radius: 6 + wobble * 2,
35
+ * });
36
+ * });
37
+ *
38
+ * t.windowResized(() => {
39
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
40
+ * });
41
+ * ```
42
+ *
43
+ * @module
44
+ */
45
+ /**
46
+ * Configuration options for the `'brightness'` filter.
47
+ *
48
+ * Adjusts image brightness by multiplying pixel values.
49
+ * @example
50
+ * ```javascript
51
+ * const t = textmode.create({
52
+ * width: window.innerWidth,
53
+ * height: window.innerHeight,
54
+ * plugins: [FiltersPlugin],
55
+ * });
56
+ *
57
+ * let video;
58
+ *
59
+ * t.setup(async () => {
60
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
61
+ * video.play();
62
+ * video.loop();
63
+ * video.characters(' .:-=+*#%@');
64
+ * });
65
+ *
66
+ * t.draw(() => {
67
+ * t.background(0);
68
+ * if (video) {
69
+ * t.image(video, t.grid.cols, t.grid.rows);
70
+ * }
71
+ *
72
+ * const wobble = Math.sin(t.secs * 2);
73
+ * t.layers.base.filter('brightness', {
74
+ * amount: 1 + wobble * 0.25,
75
+ * });
76
+ * });
77
+ *
78
+ * t.windowResized(() => {
79
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
80
+ * });
81
+ * ```
82
+ *
83
+ * @category Color adjustment filters
84
+ */
85
+ export interface BrightnessOptions {
86
+ /**
87
+ * Brightness multiplier.
88
+ *
89
+ * - `1.0` = normal brightness (no change)
90
+ * - `> 1.0` = brighter
91
+ * - `< 1.0` = darker
92
+ * - `0.0` = completely black
93
+ *
94
+ * @default 1.0
95
+ */
96
+ amount: number;
97
+ }
98
+ /**
99
+ * Configuration options for the `'contrast'` filter.
100
+ *
101
+ * Adjusts image contrast by scaling pixel values around mid-gray.
102
+ * @example
103
+ * ```javascript
104
+ * const t = textmode.create({
105
+ * width: window.innerWidth,
106
+ * height: window.innerHeight,
107
+ * plugins: [FiltersPlugin],
108
+ * });
109
+ *
110
+ * let video;
111
+ *
112
+ * t.setup(async () => {
113
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
114
+ * video.play();
115
+ * video.loop();
116
+ * video.characters(' .:-=+*#%@');
117
+ * });
118
+ *
119
+ * t.draw(() => {
120
+ * t.background(0);
121
+ * if (video) {
122
+ * t.image(video, t.grid.cols, t.grid.rows);
123
+ * }
124
+ *
125
+ * const wobble = Math.sin(t.secs * 2);
126
+ * t.layers.base.filter('contrast', {
127
+ * amount: 1 + wobble * 0.35,
128
+ * });
129
+ * });
130
+ *
131
+ * t.windowResized(() => {
132
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
133
+ * });
134
+ * ```
135
+ *
136
+ * @category Color adjustment filters
137
+ */
138
+ export interface ContrastOptions {
139
+ /**
140
+ * Contrast multiplier.
141
+ *
142
+ * - `1.0` = normal contrast (no change)
143
+ * - `> 1.0` = more contrast (darker darks, brighter brights)
144
+ * - `< 1.0` = less contrast (more gray/washed out)
145
+ * - `0.0` = solid gray
146
+ *
147
+ * @default 1.0
148
+ */
149
+ amount: number;
150
+ }
151
+ /**
152
+ * Configuration options for the `'saturation'` filter.
153
+ *
154
+ * Adjusts color intensity without affecting luminance.
155
+ * Perfect for creating vivid, oversaturated looks or desaturating to grayscale.
156
+ * @example
157
+ * ```javascript
158
+ * const t = textmode.create({
159
+ * width: window.innerWidth,
160
+ * height: window.innerHeight,
161
+ * plugins: [FiltersPlugin],
162
+ * });
163
+ *
164
+ * let video;
165
+ *
166
+ * t.setup(async () => {
167
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
168
+ * video.play();
169
+ * video.loop();
170
+ * video.characters(' .:-=+*#%@');
171
+ * });
172
+ *
173
+ * t.draw(() => {
174
+ * t.background(0);
175
+ * if (video) {
176
+ * t.image(video, t.grid.cols, t.grid.rows);
177
+ * }
178
+ *
179
+ * const wobble = Math.sin(t.secs * 2);
180
+ * t.layers.base.filter('saturation', {
181
+ * amount: 1 + wobble * 0.45,
182
+ * });
183
+ * });
184
+ *
185
+ * t.windowResized(() => {
186
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
187
+ * });
188
+ * ```
189
+ *
190
+ * @category Color adjustment filters
191
+ */
192
+ export interface SaturationOptions {
193
+ /**
194
+ * Saturation multiplier.
195
+ *
196
+ * - `0.0` = grayscale (no color)
197
+ * - `1.0` = normal saturation (no change)
198
+ * - `> 1.0` = vivid/oversaturated colors
199
+ *
200
+ * @default 1.0
201
+ */
202
+ amount: number;
203
+ }
204
+ /**
205
+ * Configuration options for the `'hueRotate'` filter.
206
+ *
207
+ * Shifts all colors around the color wheel by a specified angle.
208
+ * Useful for color grading or creating surreal color effects.
209
+ * @example
210
+ * ```javascript
211
+ * const t = textmode.create({
212
+ * width: window.innerWidth,
213
+ * height: window.innerHeight,
214
+ * plugins: [FiltersPlugin],
215
+ * });
216
+ *
217
+ * let video;
218
+ *
219
+ * t.setup(async () => {
220
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
221
+ * video.play();
222
+ * video.loop();
223
+ * video.characters(' .:-=+*#%@');
224
+ * });
225
+ *
226
+ * t.draw(() => {
227
+ * t.background(0);
228
+ * if (video) {
229
+ * t.image(video, t.grid.cols, t.grid.rows);
230
+ * }
231
+ *
232
+ * const wobble = Math.sin(t.secs * 2);
233
+ * const hue = (t.frameCount * 2 + wobble * 45) % 360;
234
+ * t.layers.base.filter('hueRotate', {
235
+ * angle: hue,
236
+ * });
237
+ * });
238
+ *
239
+ * t.windowResized(() => {
240
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
241
+ * });
242
+ * ```
243
+ *
244
+ * @category Color adjustment filters
245
+ */
246
+ export interface HueRotateOptions {
247
+ /**
248
+ * Rotation angle in degrees.
249
+ *
250
+ * - `0` = no change
251
+ * - `180` = complementary colors
252
+ * - `360` = full rotation (same as 0)
253
+ *
254
+ * Values wrap around, so `370` is equivalent to `10`.
255
+ *
256
+ * @default 0.0
257
+ */
258
+ angle: number;
259
+ }
260
+ /**
261
+ * Configuration options for the `'posterize'` filter.
262
+ *
263
+ * Reduces the color palette to a limited number of bands per channel,
264
+ * creating a retro quantized/poster-like look.
265
+ * @example
266
+ * ```javascript
267
+ * const t = textmode.create({
268
+ * width: window.innerWidth,
269
+ * height: window.innerHeight,
270
+ * plugins: [FiltersPlugin],
271
+ * });
272
+ *
273
+ * let video;
274
+ *
275
+ * t.setup(async () => {
276
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
277
+ * video.play();
278
+ * video.loop();
279
+ * video.characters(' .:-=+*#%@');
280
+ * });
281
+ *
282
+ * t.draw(() => {
283
+ * t.background(0);
284
+ * if (video) {
285
+ * t.image(video, t.grid.cols, t.grid.rows);
286
+ * }
287
+ *
288
+ * const wobble = Math.sin(t.secs * 2);
289
+ * t.layers.base.filter('posterize', {
290
+ * levels: Math.max(2, Math.round(5 + wobble * 3)),
291
+ * });
292
+ * });
293
+ *
294
+ * t.windowResized(() => {
295
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
296
+ * });
297
+ * ```
298
+ *
299
+ * @category Color adjustment filters
300
+ */
301
+ export interface PosterizeOptions {
302
+ /**
303
+ * Number of color levels per channel.
304
+ *
305
+ * Lower values create more dramatic banding effects.
306
+ * Higher values approach the original image quality.
307
+ *
308
+ * - `2` = extreme posterization (very few colors)
309
+ * - `4` = strong posterization (default)
310
+ * - `8+` = subtle posterization
311
+ *
312
+ * @default 4.0
313
+ */
314
+ levels: number;
315
+ }
316
+ /**
317
+ * Configuration options for the `'chromaticAberration'` filter.
318
+ *
319
+ * RGB color channel separation effect that simulates lens distortion
320
+ * found in cheap cameras or creates stylized glitch aesthetics.
321
+ * @example
322
+ * ```javascript
323
+ * const t = textmode.create({
324
+ * width: window.innerWidth,
325
+ * height: window.innerHeight,
326
+ * plugins: [FiltersPlugin],
327
+ * });
328
+ *
329
+ * let video;
330
+ *
331
+ * t.setup(async () => {
332
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
333
+ * video.play();
334
+ * video.loop();
335
+ * video.characters(' .:-=+*#%@');
336
+ * });
337
+ *
338
+ * t.draw(() => {
339
+ * t.background(0);
340
+ * if (video) {
341
+ * t.image(video, t.grid.cols, t.grid.rows);
342
+ * }
343
+ *
344
+ * const wobble = Math.sin(t.secs * 2);
345
+ * t.layers.base.filter('chromaticAberration', {
346
+ * amount: 6 + wobble * 4,
347
+ * direction: [Math.sin(t.secs), Math.cos(t.secs)],
348
+ * });
349
+ * });
350
+ *
351
+ * t.windowResized(() => {
352
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
353
+ * });
354
+ * ```
355
+ *
356
+ * @category Distortion filters
357
+ */
358
+ export interface ChromaticAberrationOptions {
359
+ /**
360
+ * Offset amount in pixels.
361
+ *
362
+ * Controls how far the red and blue channels are separated from green.
363
+ *
364
+ * @default 5.0
365
+ */
366
+ amount: number;
367
+ /**
368
+ * Direction of the color separation as `[x, y]`.
369
+ *
370
+ * - `[1, 0]` = horizontal separation
371
+ * - `[0, 1]` = vertical separation
372
+ * - `[1, 1]` = diagonal separation
373
+ *
374
+ * The vector is normalized internally, so `[2, 0]` is the same as `[1, 0]`.
375
+ *
376
+ * @default [1.0, 0.0]
377
+ */
378
+ direction: [number, number];
379
+ }
380
+ /**
381
+ * Configuration options for the `'pixelate'` filter.
382
+ *
383
+ * Reduces image resolution to create a mosaic/pixelated effect
384
+ * reminiscent of retro video games or censored content.
385
+ * @example
386
+ * ```javascript
387
+ * const t = textmode.create({
388
+ * width: window.innerWidth,
389
+ * height: window.innerHeight,
390
+ * plugins: [FiltersPlugin],
391
+ * });
392
+ *
393
+ * let video;
394
+ *
395
+ * t.setup(async () => {
396
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
397
+ * video.play();
398
+ * video.loop();
399
+ * video.characters(' .:-=+*#%@');
400
+ * });
401
+ *
402
+ * t.draw(() => {
403
+ * t.background(0);
404
+ * if (video) {
405
+ * t.image(video, t.grid.cols, t.grid.rows);
406
+ * }
407
+ *
408
+ * const wobble = Math.sin(t.secs * 2);
409
+ * t.layers.base.filter('pixelate', {
410
+ * pixelSize: 6 + wobble * 3,
411
+ * });
412
+ * });
413
+ *
414
+ * t.windowResized(() => {
415
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
416
+ * });
417
+ * ```
418
+ *
419
+ * @category Distortion filters
420
+ */
421
+ export interface PixelateOptions {
422
+ /**
423
+ * Size of each pixel block in pixels.
424
+ *
425
+ * Larger values create bigger, more visible pixels.
426
+ *
427
+ * Minimum value: `1.0`
428
+ *
429
+ * @default 4.0
430
+ */
431
+ pixelSize: number;
432
+ }
433
+ /**
434
+ * Configuration options for the `'gridDistortion'` filter.
435
+ *
436
+ * Distorts a monospaced character grid by varying the width and height
437
+ * of individual cells. Create wave effects, perspective distortions,
438
+ * or other grid warping effects by providing custom factor arrays.
439
+ *
440
+ * This filter is designed specifically for textmode.js grids, allowing
441
+ * you to create dynamic text distortion effects.
442
+ * @example
443
+ * ```javascript
444
+ * const t = textmode.create({
445
+ * width: window.innerWidth,
446
+ * height: window.innerHeight,
447
+ * plugins: [FiltersPlugin],
448
+ * });
449
+ *
450
+ * let video;
451
+ *
452
+ * t.setup(async () => {
453
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
454
+ * video.play();
455
+ * video.loop();
456
+ * video.characters(' .:-=+*#%@');
457
+ * });
458
+ *
459
+ * t.draw(() => {
460
+ * t.background(0);
461
+ * if (video) {
462
+ * t.image(video, t.grid.cols, t.grid.rows);
463
+ * }
464
+ *
465
+ * const wobble = Math.sin(t.secs * 2);
466
+ * const widthFactors = Array.from({ length: t.grid.cols }, (_, i) => (Math.sin(i * 0.18 + t.frameCount * 0.04) + 1) * 0.5);
467
+ * const heightFactors = Array.from({ length: t.grid.rows }, (_, i) => (Math.sin(i * 0.24 + t.secs * 1.5) + 1) * 0.5);
468
+ * t.layers.base.filter('gridDistortion', {
469
+ * gridCellDimensions: [t.grid.cols, t.grid.rows],
470
+ * gridPixelDimensions: [t.grid.width, t.grid.height],
471
+ * gridOffsetDimensions: [t.grid.offsetX, t.grid.offsetY],
472
+ * widthFactors,
473
+ * heightFactors,
474
+ * widthVariationScale: 0.35 + wobble * 0.15,
475
+ * heightVariationScale: 0.35 + wobble * 0.15,
476
+ * });
477
+ * });
478
+ *
479
+ * t.windowResized(() => {
480
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
481
+ * });
482
+ * ```
483
+ *
484
+ * @category Distortion filters
485
+ */
486
+ export interface GridDistortionOptions {
487
+ /**
488
+ * Grid dimensions as `[columns, rows]`.
489
+ *
490
+ * Should match your textmode grid dimensions.
491
+ *
492
+ * Maximum value: `[128, 128]`
493
+ *
494
+ * @default [80.0, 40.0]
495
+ */
496
+ gridCellDimensions: [number, number];
497
+ /**
498
+ * Grid size in pixels as `[width, height]`.
499
+ *
500
+ * Typically calculated as:
501
+ * `[t.grid.cols * t.grid.cellWidth, t.grid.rows * t.grid.cellHeight]`
502
+ *
503
+ * @default [640.0, 320.0]
504
+ */
505
+ gridPixelDimensions: [number, number];
506
+ /**
507
+ * Grid offset in pixels as `[offsetX, offsetY]`.
508
+ *
509
+ * Use `[t.grid.offsetX, t.grid.offsetY]` to match your grid position.
510
+ *
511
+ * @default [0.0, 0.0]
512
+ */
513
+ gridOffsetDimensions: [number, number];
514
+ /**
515
+ * Array of distortion values (0-1) for each column.
516
+ *
517
+ * Must contain at least as many elements as columns (max 128).
518
+ * Values control the relative width of each column:
519
+ * - `0.0` = minimum width
520
+ * - `0.5` = normal width
521
+ * - `1.0` = maximum width
522
+ *
523
+ * @default Array(128).fill(0.5)
524
+ */
525
+ widthFactors: number[];
526
+ /**
527
+ * Array of distortion values (0-1) for each row.
528
+ *
529
+ * Must contain at least as many elements as rows (max 128).
530
+ * Values control the relative height of each row:
531
+ * - `0.0` = minimum height
532
+ * - `0.5` = normal height
533
+ * - `1.0` = maximum height
534
+ *
535
+ * @default Array(128).fill(0.5)
536
+ */
537
+ heightFactors: number[];
538
+ /**
539
+ * Intensity multiplier for width distortion.
540
+ *
541
+ * Higher values create more dramatic width variations.
542
+ *
543
+ * @default 0.5
544
+ */
545
+ widthVariationScale: number;
546
+ /**
547
+ * Intensity multiplier for height distortion.
548
+ *
549
+ * Higher values create more dramatic height variations.
550
+ *
551
+ * @default 0.5
552
+ */
553
+ heightVariationScale: number;
554
+ }
555
+ /**
556
+ * Configuration options for the `'glitch'` filter.
557
+ *
558
+ * Digital glitch effect with RGB channel separation, scanlines, and noise.
559
+ * Creates a corrupted/broken digital signal aesthetic.
560
+ * @example
561
+ * ```javascript
562
+ * const t = textmode.create({
563
+ * width: window.innerWidth,
564
+ * height: window.innerHeight,
565
+ * plugins: [FiltersPlugin],
566
+ * });
567
+ *
568
+ * let video;
569
+ *
570
+ * t.setup(async () => {
571
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
572
+ * video.play();
573
+ * video.loop();
574
+ * video.characters(' .:-=+*#%@');
575
+ * });
576
+ *
577
+ * t.draw(() => {
578
+ * t.background(0);
579
+ * if (video) {
580
+ * t.image(video, t.grid.cols, t.grid.rows);
581
+ * }
582
+ *
583
+ * const wobble = Math.sin(t.secs * 2);
584
+ * t.layers.base.filter('glitch', {
585
+ * amount: Math.max(0, 0.2 + wobble * 0.8),
586
+ * });
587
+ * });
588
+ *
589
+ * t.windowResized(() => {
590
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
591
+ * });
592
+ * ```
593
+ *
594
+ * @category Stylization filters
595
+ */
596
+ export interface GlitchOptions {
597
+ /**
598
+ * Glitch intensity.
599
+ *
600
+ * - `0.0` = no glitch effect
601
+ * - `0.5` = subtle glitching
602
+ * - `1.0+` = intense, chaotic glitching
603
+ *
604
+ * @default 0.0
605
+ */
606
+ amount: number;
607
+ }
608
+ /**
609
+ * Configuration options for the `'crtMattias'` filter.
610
+ *
611
+ * CRT monitor emulation effect with screen curvature, animated scanlines,
612
+ * blur, vignette, and film grain noise. Based on Mattias Gustavsson's
613
+ * classic CRT shader.
614
+ * @example
615
+ * ```javascript
616
+ * const t = textmode.create({
617
+ * width: window.innerWidth,
618
+ * height: window.innerHeight,
619
+ * plugins: [FiltersPlugin],
620
+ * });
621
+ *
622
+ * let video;
623
+ *
624
+ * t.setup(async () => {
625
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
626
+ * video.play();
627
+ * video.loop();
628
+ * video.characters(' .:-=+*#%@');
629
+ * });
630
+ *
631
+ * t.draw(() => {
632
+ * t.background(0);
633
+ * if (video) {
634
+ * t.image(video, t.grid.cols, t.grid.rows);
635
+ * }
636
+ *
637
+ * const wobble = Math.sin(t.secs * 2);
638
+ * t.layers.base.filter('crtMattias', {
639
+ * curvature: 0.45 + wobble * 0.1,
640
+ * scanSpeed: 1 + wobble * 0.25,
641
+ * time: t.secs,
642
+ * });
643
+ * });
644
+ *
645
+ * t.windowResized(() => {
646
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
647
+ * });
648
+ * ```
649
+ *
650
+ * @see {@link https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-mattias.glsl | Original shader by Mattias Gustavsson}
651
+ *
652
+ * @category Stylization filters
653
+ */
654
+ export interface CrtMattiasOptions {
655
+ /**
656
+ * Amount of screen curvature/barrel distortion.
657
+ *
658
+ * - `0.0` = flat screen
659
+ * - `0.5` = moderate curvature (default)
660
+ * - `1.0` = maximum curvature
661
+ *
662
+ * @default 0.5
663
+ */
664
+ curvature: number;
665
+ /**
666
+ * Speed of the scrolling scanline effect.
667
+ *
668
+ * Higher values make the scanline crawl faster.
669
+ *
670
+ * @default 1.0
671
+ */
672
+ scanSpeed: number;
673
+ /**
674
+ * Animation time parameter.
675
+ *
676
+ * Increment this value each frame to animate the effect.
677
+ * Typically use elapsed time in seconds or frame count.
678
+ *
679
+ * @default 0.0
680
+ */
681
+ time: number;
682
+ }
683
+ /**
684
+ * Configuration options for the `'scanlines'` filter.
685
+ *
686
+ * A standalone scanline effect that adds horizontal lines to the image
687
+ * to simulate a CRT display or old monitor. More customizable than
688
+ * the scanlines in crtMattias.
689
+ * @example
690
+ * ```javascript
691
+ * const t = textmode.create({
692
+ * width: window.innerWidth,
693
+ * height: window.innerHeight,
694
+ * plugins: [FiltersPlugin],
695
+ * });
696
+ *
697
+ * let video;
698
+ *
699
+ * t.setup(async () => {
700
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
701
+ * video.play();
702
+ * video.loop();
703
+ * video.characters(' .:-=+*#%@');
704
+ * });
705
+ *
706
+ * t.draw(() => {
707
+ * t.background(0);
708
+ * if (video) {
709
+ * t.image(video, t.grid.cols, t.grid.rows);
710
+ * }
711
+ *
712
+ * const wobble = Math.sin(t.secs * 2);
713
+ * t.layers.base.filter('scanlines', {
714
+ * count: 256,
715
+ * lineWidth: 0.5,
716
+ * intensity: 0.7 + wobble * 0.1,
717
+ * speed: 1 + wobble * 0.15,
718
+ * time: t.secs,
719
+ * });
720
+ * });
721
+ *
722
+ * t.windowResized(() => {
723
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
724
+ * });
725
+ * ```
726
+ *
727
+ * @category Stylization filters
728
+ */
729
+ export interface ScanlinesOptions {
730
+ /**
731
+ * Number of scanlines across the image height.
732
+ *
733
+ * Higher values create finer, more dense lines.
734
+ *
735
+ * Minimum value: `10.0`
736
+ *
737
+ * @default 300.0
738
+ */
739
+ count: number;
740
+ /**
741
+ * Width of the lines relative to the spacing.
742
+ *
743
+ * - `0.0` = very thin lines (mostly transparent)
744
+ * - `0.5` = equal line and gap width
745
+ * - `1.0` = solid (no gaps)
746
+ *
747
+ * @default 0.5
748
+ */
749
+ lineWidth: number;
750
+ /**
751
+ * Opacity/darkness of the scanlines.
752
+ *
753
+ * - `0.0` = invisible lines
754
+ * - `0.75` = clearly visible (default)
755
+ * - `1.0` = maximum darkness (solid black lines)
756
+ *
757
+ * @default 0.75
758
+ */
759
+ intensity: number;
760
+ /**
761
+ * Scrolling speed of the lines.
762
+ *
763
+ * - `0.0` = static lines
764
+ * - `1.0` = normal scrolling speed
765
+ * - Higher values = faster scrolling
766
+ *
767
+ * @default 1.0
768
+ */
769
+ speed: number;
770
+ /**
771
+ * Animation time parameter.
772
+ *
773
+ * Increment this value each frame to animate the scrolling effect.
774
+ *
775
+ * @default 0.0
776
+ */
777
+ time: number;
778
+ }
779
+ /**
780
+ * Configuration options for the `'vignette'` filter.
781
+ *
782
+ * Darkens the edges and corners of the image, drawing focus to the center.
783
+ * Useful for creating a cinematic look or highlighting central content.
784
+ * @example
785
+ * ```javascript
786
+ * const t = textmode.create({
787
+ * width: window.innerWidth,
788
+ * height: window.innerHeight,
789
+ * plugins: [FiltersPlugin],
790
+ * });
791
+ *
792
+ * let video;
793
+ *
794
+ * t.setup(async () => {
795
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
796
+ * video.play();
797
+ * video.loop();
798
+ * video.characters(' .:-=+*#%@');
799
+ * });
800
+ *
801
+ * t.draw(() => {
802
+ * t.background(0);
803
+ * if (video) {
804
+ * t.image(video, t.grid.cols, t.grid.rows);
805
+ * }
806
+ *
807
+ * const wobble = Math.sin(t.secs * 2);
808
+ * t.layers.base.filter('vignette', {
809
+ * amount: 0.5 + wobble * 0.2,
810
+ * softness: 0.5,
811
+ * roundness: 0.5 + wobble * 0.15,
812
+ * });
813
+ * });
814
+ *
815
+ * t.windowResized(() => {
816
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
817
+ * });
818
+ * ```
819
+ *
820
+ * @category Stylization filters
821
+ */
822
+ export interface VignetteOptions {
823
+ /**
824
+ * Intensity of the darkening effect.
825
+ *
826
+ * - `0.0` = no vignette
827
+ * - `0.5` = moderate vignette (default)
828
+ * - `1.0` = very dark edges
829
+ *
830
+ * @default 0.5
831
+ */
832
+ amount: number;
833
+ /**
834
+ * Falloff gradient softness.
835
+ *
836
+ * - `0.0` = hard edge (sharp transition)
837
+ * - `0.5` = moderate gradient (default)
838
+ * - `1.0` = very soft, gradual falloff
839
+ *
840
+ * @default 0.5
841
+ */
842
+ softness: number;
843
+ /**
844
+ * Shape of the vignette.
845
+ *
846
+ * - `0.0` = rectangular (follows screen edges)
847
+ * - `0.5` = rounded rectangle (default)
848
+ * - `1.0` = circular/elliptical
849
+ *
850
+ * @default 0.5
851
+ */
852
+ roundness: number;
853
+ }
854
+ /**
855
+ * Configuration options for the `'bloom'` filter.
856
+ *
857
+ * Creates a glow effect around bright areas of the image. Pixels above
858
+ * the brightness threshold emit a soft glow that spreads outward.
859
+ * Perfect for creating neon, glowing text, or dreamy effects.
860
+ * @example
861
+ * ```javascript
862
+ * const t = textmode.create({
863
+ * width: window.innerWidth,
864
+ * height: window.innerHeight,
865
+ * plugins: [FiltersPlugin],
866
+ * });
867
+ *
868
+ * let video;
869
+ *
870
+ * t.setup(async () => {
871
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
872
+ * video.play();
873
+ * video.loop();
874
+ * video.characters(' .:-=+*#%@');
875
+ * });
876
+ *
877
+ * t.draw(() => {
878
+ * t.background(0);
879
+ * if (video) {
880
+ * t.image(video, t.grid.cols, t.grid.rows);
881
+ * }
882
+ *
883
+ * const wobble = Math.sin(t.secs * 2);
884
+ * t.layers.base.filter('bloom', {
885
+ * threshold: 0.5,
886
+ * intensity: 1.2 + wobble * 0.5,
887
+ * radius: 6 + wobble * 2,
888
+ * });
889
+ * });
890
+ *
891
+ * t.windowResized(() => {
892
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
893
+ * });
894
+ * ```
895
+ *
896
+ * @category Stylization filters
897
+ */
898
+ export interface BloomOptions {
899
+ /**
900
+ * Brightness level above which pixels will glow.
901
+ *
902
+ * - `0.0` = everything glows
903
+ * - `0.5` = mid-brightness and above glows (default)
904
+ * - `1.0` = only the brightest pixels glow
905
+ *
906
+ * @default 0.5
907
+ */
908
+ threshold: number;
909
+ /**
910
+ * Strength of the glow effect.
911
+ *
912
+ * - `0.0` = no visible glow
913
+ * - `1.0` = normal glow intensity (default)
914
+ * - `2.0+` = very bright, intense glow
915
+ *
916
+ * @default 1.0
917
+ */
918
+ intensity: number;
919
+ /**
920
+ * Size of the glow spread in pixels.
921
+ *
922
+ * Larger values create a wider, softer glow.
923
+ *
924
+ * - `1.0` = tight glow
925
+ * - `4.0` = moderate spread (default)
926
+ * - `10.0+` = wide, diffuse glow
927
+ *
928
+ * @default 4.0
929
+ */
930
+ radius: number;
931
+ }
932
+ /**
933
+ * Configuration options for the `'filmGrain'` filter.
934
+ *
935
+ * Adds an animated film grain/noise texture overlay to simulate vintage
936
+ * film stock or analog video. The multi-layered noise creates an organic,
937
+ * moving grain pattern that's less visible in darker areas, mimicking
938
+ * real film characteristics.
939
+ * @example
940
+ * ```javascript
941
+ * const t = textmode.create({
942
+ * width: window.innerWidth,
943
+ * height: window.innerHeight,
944
+ * plugins: [FiltersPlugin],
945
+ * });
946
+ *
947
+ * let video;
948
+ *
949
+ * t.setup(async () => {
950
+ * video = await t.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
951
+ * video.play();
952
+ * video.loop();
953
+ * video.characters(' .:-=+*#%@');
954
+ * });
955
+ *
956
+ * t.draw(() => {
957
+ * t.background(0);
958
+ * if (video) {
959
+ * t.image(video, t.grid.cols, t.grid.rows);
960
+ * }
961
+ *
962
+ * const wobble = Math.sin(t.secs * 2);
963
+ * t.layers.base.filter('filmGrain', {
964
+ * intensity: 0.2 + wobble * 0.1,
965
+ * size: 2 + wobble * 0.5,
966
+ * speed: 1 + wobble * 0.2,
967
+ * time: t.secs,
968
+ * });
969
+ * });
970
+ *
971
+ * t.windowResized(() => {
972
+ * t.resizeCanvas(window.innerWidth, window.innerHeight);
973
+ * });
974
+ * ```
975
+ *
976
+ * @category Stylization filters
977
+ */
978
+ export interface FilmGrainOptions {
979
+ /**
980
+ * Strength of the grain effect.
981
+ *
982
+ * - `0.0` = no grain
983
+ * - `0.2` = subtle grain (default)
984
+ * - `0.5+` = heavy, noticeable grain
985
+ *
986
+ * @default 0.2
987
+ */
988
+ intensity: number;
989
+ /**
990
+ * Size of grain particles.
991
+ *
992
+ * - `1.0` = fine grain
993
+ * - `2.0` = medium grain (default)
994
+ * - `5.0+` = coarse, chunky grain
995
+ *
996
+ * @default 2.0
997
+ */
998
+ size: number;
999
+ /**
1000
+ * Animation speed of the grain.
1001
+ *
1002
+ * - `0.0` = static grain (not recommended)
1003
+ * - `1.0` = normal animation speed (default)
1004
+ * - `2.0+` = fast, flickering grain
1005
+ *
1006
+ * @default 1.0
1007
+ */
1008
+ speed: number;
1009
+ /**
1010
+ * Animation time parameter.
1011
+ *
1012
+ * Increment this value each frame to animate the grain effect.
1013
+ *
1014
+ * @default 0.0
1015
+ */
1016
+ time: number;
1017
+ }