-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathq5.d.ts
More file actions
4594 lines (4229 loc) · 124 KB
/
q5.d.ts
File metadata and controls
4594 lines (4229 loc) · 124 KB
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
100
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
declare global {
// ⭐ core
/**
* Welcome to q5's documentation! 🤩
*
* First time coding? Check out the [q5 Beginner's Brief](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Brief).
*
* On these Learn pages, you can experiment with editing the
* interactive mini examples. Have fun! 😎
*
* [](https://notbyai.fyi/)
*/
/** ⭐
* Creates a canvas element, a section of the screen your program
* can draw on.
*
* Run this function to start using q5!
*
* Note that in this example, the circle is located at position [0, 0], the origin of the canvas.
* @param {number} [w] width or side lengths of the canvas
* @param {number} [h] height of the canvas
* @param {object} [opt] [options](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getContextAttributes)
* @returns {Promise<HTMLCanvasElement>} canvas element
* @example
* await Canvas(200, 100);
* background('silver');
* circle(0, 0, 80);
*/
function Canvas(w?: number, h?: number, options?: object): Promise<HTMLCanvasElement>;
/** ⭐
* The q5 draw function is run 60 times per second by default.
* @example
* q5.draw = function () {
* background('silver');
* circle(mouseX, mouseY, 80);
* };
*/
function draw(): void;
/** ⭐
* Logs a message to the JavaScript [console](https://developer.mozilla.org/docs/Web/API/console/log_static).
*
* To view the console, open your browser's web developer tools
* via the keyboard shortcut `Ctrl + Shift + i` or `command + option + i`,
* then click the "Console" tab.
*
* Use `log` when you're curious about what your code is doing!
* @param {*} message
* @example
* q5.draw = function () {
* circle(mouseX, mouseY, 80);
* log('The mouse is at:', mouseX, mouseY);
* };
*/
function log(message: any): void;
// 🧑🎨 shapes
/** 🧑🎨
* Draws a circle.
* @param {number} x x-coordinate
* @param {number} y y-coordinate
* @param {number} diameter diameter of the circle
* @example
* await Canvas(200, 100);
* circle(0, 0, 80);
*/
function circle(x: number, y: number, diameter: number): void;
/** 🧑🎨
* Draws an ellipse.
* @param {number} x x-coordinate
* @param {number} y y-coordinate
* @param {number} width width of the ellipse
* @param {number} height height of the ellipse
* @example
* await Canvas(200, 100);
* ellipse(0, 0, 160, 80);
*/
function ellipse(x: number, y: number, width: number, height: number): void;
/** 🧑🎨
* Draws a rectangle or a rounded rectangle.
*
* Also accepts 8 parameters to specify a
* corner radius for each corner, in the order:
* top-left, top-right, bottom-right, bottom-left.
* @param {number} x x-coordinate
* @param {number} y y-coordinate
* @param {number} w width of the rectangle
* @param {number} h height of the rectangle
* @param {number} [rounded] radius for all corners
* @example
* await Canvas(200);
* background(0.8);
*
* rect(-70, -80, 40, 60);
* rect(-20, -30, 40, 60, 10);
* rect(30, 20, 40, 60, 20, 4, 0, 8);
*/
function rect(x: number, y: number, w: number, h: number, rounded?: number): void;
/** 🧑🎨
* Draws a square or a rounded square.
*
* Also accepts 7 parameters to specify a
* corner radius for each corner, in the order:
* top-left, top-right, bottom-right, bottom-left.
* @param {number} x x-coordinate
* @param {number} y y-coordinate
* @param {number} size size of the sides of the square
* @param {number} [rounded] radius for all corners
* @example
* await Canvas(200);
* background(0.8);
*
* square(-70, -70, 40);
* square(-20, -20, 40, 10);
* square(30, 30, 40, 20, 4, 0, 8);
*/
function square(x: number, y: number, size: number, rounded?: number): void;
/** 🧑🎨
* Draws a point on the canvas.
* @param {number} x x-coordinate
* @param {number} y y-coordinate
* @example
* await Canvas(200, 100);
* stroke('white');
* point(-25, 0);
*
* strokeWeight(10);
* point(25, 0);
*/
function point(x: number, y: number): void;
/** 🧑🎨
* Draws a line on the canvas.
*
* To draw lines with rounded stroke caps, use `capsule` instead.
* @param {number} x1 x-coordinate of the first point
* @param {number} y1 y-coordinate of the first point
* @param {number} x2 x-coordinate of the second point
* @param {number} y2 y-coordinate of the second point
* @example
* await Canvas(200, 100);
* stroke('lime');
* line(-80, -30, 80, 30);
*/
function line(x1: number, y1: number, x2: number, y2: number): void;
/** 🧑🎨
* Draws a capsule.
* @param {number} x1 x-coordinate of the first point
* @param {number} y1 y-coordinate of the first point
* @param {number} x2 x-coordinate of the second point
* @param {number} y2 y-coordinate of the second point
* @param {number} r radius of the capsule semi-circle ends
* @example
* await Canvas(200, 100);
* background(0.8);
* strokeWeight(5);
* capsule(-60, -10, 60, 10, 10);
* @example
* q5.draw = function () {
* background(0.8);
* fill('cyan');
* strokeWeight(10);
* capsule(0, 0, mouseX, mouseY, 20);
* };
*/
function capsule(x1: number, y1: number, x2: number, y2: number, r: number): void;
/** 🧑🎨
* Set to `CORNER` (default), `CENTER`, `RADIUS`, or `CORNERS`.
*
* Changes how the first four inputs to
* `rect` and `square` are interpreted.
* @param {string} mode
* @example
* await Canvas(200, 100);
* background(0.8);
* rectMode(CORNER);
*
* // ( x, y, w, h)
* rect(-50, -25, 100, 50);
* @example
* await Canvas(200, 100);
* background(0.8);
* rectMode(CENTER);
*
* // (cX, cY, w, h)
* rect(0, 0, 100, 50);
* @example
* await Canvas(200, 100);
* background(0.8);
* rectMode(RADIUS);
*
* // (cX, cY, rX, rY)
* rect(0, 0, 50, 25);
* @example
* await Canvas(200, 100);
* background(0.8);
* rectMode(CORNERS);
*
* // ( x1, y1, x2, y2)
* rect(-50, -25, 50, 25);
*/
function rectMode(mode: string): void;
/** 🧑🎨
* Set to `CENTER` (default), `RADIUS`, `CORNER`, or `CORNERS`.
*
* Changes how the first four inputs to
* `ellipse`, `circle`, and `arc` are interpreted.
* @param {string} mode
* @example
* await Canvas(200, 100);
* background(0.8);
* ellipseMode(CENTER);
*
* // (x, y, w, h)
* ellipse(0, 0, 100, 50);
* @example
* await Canvas(200, 100);
* background(0.8);
* ellipseMode(RADIUS);
*
* // (x, y, rX, rY)
* ellipse(0, 0, 50, 25);
* @example
* await Canvas(200, 100);
* background(0.8);
* ellipseMode(CORNER);
*
* // ( lX, tY, w, h)
* ellipse(-50, -25, 100, 50);
* @example
* await Canvas(200, 100);
* background(0.8);
* ellipseMode(CORNERS);
*
* // ( x1, y1, x2, y2)
* ellipse(-50, -25, 50, 25);
*/
function ellipseMode(mode: string): void;
/** 🧑🎨
* Shape alignment mode, for use in `rectMode` and `ellipseMode`.
*/
const CORNER: 'corner';
/** 🧑🎨
* Shape alignment mode, for use in `rectMode` and `ellipseMode`.
*/
const RADIUS: 'radius';
/** 🧑🎨
* Shape alignment mode, for use in `rectMode` and `ellipseMode`.
*/
const CORNERS: 'corners';
// 🌆 image
/** 🌆
* Loads an image from a URL.
*
* By default, assets are loaded in parallel before q5 runs `draw`. Use `await` to wait for an image to load.
* @param {string} url url of the image to load
* @returns {Q5.Image & PromiseLike<Q5.Image>} image
* @example
* await Canvas(200);
*
* let logo = loadImage('/q5js_logo.avif');
*
* q5.draw = function () {
* background(logo);
* };
* @example
* await Canvas(200);
*
* let logo = await loadImage('/q5js_logo.avif');
* background(logo);
*/
function loadImage(url: string): Q5.Image & PromiseLike<Q5.Image>;
/** 🌆
* Draws an image or video frame to the canvas.
* @param {Q5.Image | HTMLVideoElement} img image or video to draw
* @param {number} dx x position to draw the image at
* @param {number} dy y position to draw the image at
* @param {number} [dw] width of the destination image
* @param {number} [dh] height of the destination image
* @param {number} [sx] x position in the source to start clipping a subsection from
* @param {number} [sy] y position in the source to start clipping a subsection from
* @param {number} [sw] width of the subsection of the source image
* @param {number} [sh] height of the subsection of the source image
* @example
* await Canvas(200);
*
* let logo = load('/q5js_logo.avif');
*
* q5.draw = function () {
* image(logo, -100, -100, 200, 200);
* };
* @example
* await Canvas(200);
*
* let logo = load('/q5js_logo.avif');
*
* q5.draw = function () {
* image(logo, -100, -100, 200, 200, 256, 256, 512, 512);
* };
*/
function image(): void;
/** 🌆
* Set to `CORNER` (default), `CORNERS`, or `CENTER`.
*
* Changes how inputs to `image` are interpreted.
* @param {string} mode
* @example
* await Canvas(200);
* let logo = load('/q5js_logo.avif');
*
* q5.draw = function () {
* imageMode(CORNER);
*
* // ( img, x, y, w, h)
* image(logo, -50, -50, 100, 100);
* };
* @example
* await Canvas(200);
* let logo = load('/q5js_logo.avif');
*
* q5.draw = function () {
* imageMode(CENTER);
*
* // (img, cX, cY, w, h)
* image(logo, 0, 0, 100, 100);
* };
* @example
* await Canvas(200);
* let logo = load('/q5js_logo.avif');
*
* q5.draw = function () {
* imageMode(CORNERS);
*
* // ( img, x1, y1, x2, y2)
* image(logo, -50, -50, 50, 50);
* };
*/
function imageMode(mode: string): void;
/** 🌆
* Sets the default image scale, which is applied to images when
* they are drawn without a specified width or height.
*
* By default it is 0.5 so images appear at their actual size
* when pixel density is 2. Images will be drawn at a consistent
* default size relative to the canvas regardless of pixel density.
*
* This function must be called before images are loaded to
* have an effect.
* @param {number} scale
* @returns {number} default image scale
*/
function defaultImageScale(scale: number): number;
/** 🌆
* Resizes the image.
* @param {number} w new width
* @param {number} h new height
* @example
* await Canvas(200);
*
* let logo = await load('/q5js_logo.avif');
*
* logo.resize(128, 128);
* image(logo, -100, -100, 200, 200);
*/
function resize(w: number, h: number): void;
/** 🌆
* Returns a trimmed image, cropping out transparent pixels from the edges.
* @returns {Q5.Image}
*/
function trim(): Q5.Image;
/** 🌆
* Enables smooth rendering of images displayed larger than
* their actual size. This is the default setting, so running this
* function only has an effect if `noSmooth` has been called.
* @example
* await Canvas(200);
* smooth();
*
* let icon = await load('/q5js_icon.png');
* image(icon, -100, -100, 200, 200);
*/
function smooth(): void;
/** 🌆
* Disables smooth image rendering for a pixelated look.
*
* This setting is applied to images when they're loaded.
* @example
* await Canvas(200);
* noSmooth();
*
* let icon = await load('/q5js_icon.png');
* image(icon, -100, -100, 200, 200);
*/
function noSmooth(): void;
/** 🌆
* Applies a tint (color overlay) to the drawing.
*
* The alpha value of the tint color determines the
* strength of the tint. To change an image's opacity,
* use the `opacity` function.
*
* Tinting affects all subsequent images drawn. The tint
* color is applied to images using the "multiply" blend mode.
*
* Since the tinting process is performance intensive, each time
* an image is tinted, q5 caches the result. `image` will draw the
* cached tinted image unless the tint color has changed or the
* image being tinted was edited.
*
* If you need to draw an image multiple times each frame with
* different tints, consider making copies of the image and tinting
* each copy separately.
* @param {string | number} color tint color
* @example
* await Canvas(200);
*
* let logo = await load('/q5js_logo.avif');
*
* tint(1, 0, 0, 0.5);
* image(logo, -100, -100, 200, 200);
*/
function tint(color: string | number): void;
/** 🌆
* Images drawn after this function is run will not be tinted.
*/
function noTint(): void;
/** 🌆
* Masks the image with another image.
* @param {Q5.Image} img image to use as a mask
*/
function mask(img: Q5.Image): void;
/** 🌆
* Returns a copy of the image.
* @returns {Q5.Image}
*/
function copy(): Q5.Image;
/** 🌆
* Displays a region of the image on another region of the image.
* Can be used to create a detail inset, aka a magnifying glass effect.
* @param {number} sx x-coordinate of the source region
* @param {number} sy y-coordinate of the source region
* @param {number} sw width of the source region
* @param {number} sh height of the source region
* @param {number} dx x-coordinate of the destination region
* @param {number} dy y-coordinate of the destination region
* @param {number} dw width of the destination region
* @param {number} dh height of the destination region
* @example
* await Canvas(200);
*
* let logo = await load('/q5js_logo.avif');
*
* logo.inset(256, 256, 512, 512, 0, 0, 256, 256);
* image(logo, -100, -100, 200, 200);
*/
function inset(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
/** 🌆
* Retrieves a subsection of an image or canvas as a new Q5 Image
* or the color of a pixel in the image or canvas.
*
* If only x and y are specified, this function returns the color of the pixel
* at the given coordinate in `[R, G, B, A]` array format. If `loadPixels`
* has never been run, it's run by this function.
*
* If you make changes to the canvas or image, you must call `loadPixels`
* before using this function to get current color data.
*
* Not applicable to WebGPU canvases.
* @param {number} x
* @param {number} y
* @param {number} [w] width of the area, default is 1
* @param {number} [h] height of the area, default is 1
* @returns {Q5.Image | number[]}
* @example
* await Canvas(200);
*
* let logo = await load('/q5js_logo.avif');
*
* let cropped = logo.get(256, 256, 512, 512);
* image(cropped, -100, -100, 200, 200);
*/
function get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
/** 🌆
* Sets a pixel's color in the image or canvas. Color mode must be RGB.
*
* Or if a canvas or image is provided, it's drawn on top of the
* destination image or canvas, ignoring its tint setting.
*
* Run `updatePixels` to apply the changes.
*
* Not applicable to WebGPU canvases.
* @param {number} x
* @param {number} y
* @param {any} val color, canvas, or image
* @example
* await Canvas(200);
* noSmooth();
* let c = color('lime');
* let img = createImage(50, 50);
*
* q5.draw = function () {
* img.set(random(50), random(50), c);
* img.updatePixels();
* background(img);
* };
*/
function set(x: number, y: number, val: any): void;
/** 🌆
* Array of pixel color data from a canvas or image.
*
* Empty by default, get the data by running `loadPixels`.
*
* Each pixel is represented by four consecutive values in the array,
* corresponding to its red, green, blue, and alpha channels.
*
* The top left pixel's data is at the beginning of the array
* and the bottom right pixel's data is at the end, going from
* left to right and top to bottom.
*/
let pixels: number[];
/** 🌆
* Loads pixel data into `pixels` from the canvas or image.
*
* The example below sets some pixels' green channel
* to a random value.
*
* Not applicable to WebGPU canvases.
* @example
* await Canvas(200);
* frameRate(5);
* let icon = load('/q5js_icon.png');
*
* q5.draw = function () {
* icon.loadPixels();
* for (let i = 0; i < icon.pixels.length; i += 16) {
* icon.pixels[i + 1] = random(1);
* }
* icon.updatePixels();
* background(icon);
* };
*/
function loadPixels(): void;
/** 🌆
* Applies changes in the `pixels` array to the canvas or image.
*
* Not applicable to WebGPU canvases.
* @example
* await Canvas(200);
* let c = color('pink');
*
* let img = createImage(50, 50);
* for (let x = 0; x < 50; x += 3) {
* for (let y = 0; y < 50; y += 3) {
* img.set(x, y, c);
* }
* }
* img.updatePixels();
*
* background(img);
*/
function updatePixels(): void;
/** 🌆
* Applies a filter to the image.
*
* See the documentation for q5's filter constants below for more info.
*
* A CSS filter string can also be used.
* https://developer.mozilla.org/docs/Web/CSS/filter
*
* Not applicable to WebGPU canvases.
* @param {string} type filter type or a CSS filter string
* @param {number} [value] optional value, depends on filter type
* @example
* await Canvas(200);
* let logo = await load('/q5js_logo.avif');
* logo.filter(INVERT);
* image(logo, -100, -100, 200, 200);
*/
function filter(type: string, value?: number): void;
/** 🌆
* Converts the image to black and white pixels depending if they are above or below a certain threshold.
*/
const THRESHOLD: 1;
/** 🌆
* Converts the image to grayscale by setting each pixel to its luminance.
*/
const GRAY: 2;
/** 🌆
* Sets the alpha channel to fully opaque.
*/
const OPAQUE: 3;
/** 🌆
* Inverts the color of each pixel.
*/
const INVERT: 4;
/** 🌆
* Limits each channel of the image to the number of colors specified as an argument.
*/
const POSTERIZE: 5;
/** 🌆
* Increases the size of bright areas.
*/
const DILATE: 6;
/** 🌆
* Increases the size of dark areas.
*/
const ERODE: 7;
/** 🌆
* Applies a Gaussian blur to the image.
*/
const BLUR: 8;
/** 🌆
* Creates a new image.
* @param {number} w width
* @param {number} h height
* @param {any} [opt] optional settings for the image
* @returns {Q5.Image}
*/
function createImage(w: number, h: number, opt?: any): Q5.Image;
/** 🌆
* Creates a graphics buffer.
*
* Graphics looping is disabled by default in q5 WebGPU.
* See issue [#104](https://github.com/q5js/q5.js/issues/104) for details.
* @param {number} w width
* @param {number} h height
* @param {object} [opt] options
* @returns {Q5} a new Q5 graphics buffer
* @example
* await Canvas(200);
*
* let g = createGraphics(100);
* g.noLoop();
* g.stroke('pink');
* g.fill('red');
* g.circle(50, 50, 120);
*
* image(g, -50, -50, 100, 100);
*/
function createGraphics(w: number, h: number, opt?: any): Q5;
// 📘 text
/** 📘
* Renders text on the canvas.
* @param {string} str string of text to display
* @param {number} x x-coordinate of the text's position
* @param {number} y y-coordinate of the text's position
* @param {number} [wrapWidth] maximum line width in characters
* @param {number} [lineLimit] maximum number of lines
* @example
* await Canvas(200, 100);
* background('silver');
*
* textSize(32);
* text('Hello, world!', -88, 10);
* @example
* await Canvas(200);
* background(0.8);
* textSize(20);
*
* let info =
* 'q5.js was designed to make creative coding fun and accessible for artists, designers, educators, and beginners.';
*
* text(info, -88, -70, 20);
* //
* //
*/
function text(str: string, x: number, y: number, wrapWidth?: number, lineLimit?: number): void;
/** 📘
* Loads a font from a URL.
*
* The first example below loads [Robotica](https://www.dafont.com/robotica-courtney.font).
*
* The second example loads
* [Pacifico](https://fonts.google.com/specimen/Pacifico) from [Google fonts](https://fonts.google.com/).
*
* By default, assets are loaded in parallel before q5 runs `draw`. Use `await` to wait for a font to load.
*
* Fonts in [MSDF format](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer#text-rendering)
* with the file ending "-msdf.json" can be used for high performance text rendering. Make your own using the [MSDF font converter](https://msdf-bmfont.donmccurdy.com/).
*
* If no fonts are loaded, q5 WebGPU will lazy load the default MSDF font from q5js.org. Until it is loaded, the system's default sans-serif font will be used via `textImage`.
* @param {string} url URL of the font to load
* @returns {FontFace & PromiseLike<FontFace>} font
* @example
* await Canvas(200, 56);
*
* await loadFont('/assets/Robotica.ttf');
*
* fill('skyblue');
* textSize(64);
* text('Hello!', -98, 24);
* @example
* await Canvas(200, 74);
*
* loadFont('fonts.googleapis.com/css2?family=Pacifico');
*
* q5.draw = function () {
* fill('hotpink');
* textSize(68);
* text('Hello!', -98, 31);
* };
* //
* @example
* await Canvas(200, 74);
*
* await loadFont('sans-serif'); // msdf
*
* fill('white');
* textSize(68);
* text('Hello!', -98, 31);
*/
function loadFont(url: string): FontFace & PromiseLike<FontFace>;
/** 📘
* Sets the current font to be used for rendering text.
*
* By default, the font is set to the [CSS font family](https://developer.mozilla.org/docs/Web/CSS/font-family)
* "sans-serif" or the last font loaded.
* @param {string} fontName name of the font family or a FontFace object
* @example
* await Canvas(200, 160);
* background(0.8);
*
* textFont('serif');
*
* text('Hello, world!', -96, 10);
* @example
* await Canvas(200);
* background(0.8);
*
* textFont('monospace');
*
* text('Hello, world!', -96, 10);
*/
function textFont(fontName: string): void;
/** 📘
* Sets or gets the current font size. If no argument is provided, returns the current font size.
* @param {number} [size] size of the font in pixels
* @returns {number | void} current font size when no argument is provided
* @example
* q5.draw = function () {
* background(0.8);
*
* textSize(abs(mouseX));
* text('A', -90, 90);
* };
*/
function textSize(size?: number): number | void;
/** 📘
* Sets or gets the current line height. If no argument is provided, returns the current line height.
* @param {number} [leading] line height in pixels
* @returns {number | void} current line height when no argument is provided
* @example
* q5.draw = function () {
* background(0.8);
*
* textSize(abs(mouseX));
* text('A', -90, 90);
* rect(-90, 90, 5, -textLeading());
* };
*/
function textLeading(leading?: number): number | void;
/** 📘
* Sets the current text style.
*
* Not applicable to MSDF fonts.
* @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
* @example
* await Canvas(200);
* background(0.8);
*
* textStyle(ITALIC);
*
* textSize(32);
* text('Hello, world!', -88, 6);
*/
function textStyle(style: 'normal' | 'italic' | 'bold' | 'bolditalic'): void;
/** 📘
* Sets the horizontal and vertical alignment of text.
*
* Alignment constants like `CENTER` can be used with this function.
* @param {'left' | 'center' | 'right'} horiz horizontal alignment
* @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
* @example
* await Canvas(200);
* background(0.8);
* textSize(32);
*
* textAlign(CENTER, CENTER);
* text('Hello, world!', 0, 0);
*/
function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'middle' | 'bottom' | 'alphabetic'): void;
/** 📘
* Sets the text weight.
*
* - 100: thin
* - 200: extra-light
* - 300: light
* - 400: normal/regular
* - 500: medium
* - 600: semi-bold
* - 700: bold
* - 800: bolder/extra-bold
* - 900: black/heavy
* @param {number | string} weight font weight
* @example
* await Canvas(200);
* background(0.8);
* textSize(32);
* textAlign(CENTER, CENTER);
*
* textWeight(100);
* text('Hello, world!', 0, 0);
*/
function textWeight(weight: number | string): void;
/** 📘
* Calculates and returns the width of a given string of text.
* @param {string} str string to measure
* @returns {number} width of the text in pixels
* @example
* q5.draw = function () {
* background(0.8);
*
* textSize(abs(mouseX));
* rect(-90, 90, textWidth('A'), -textLeading());
* text('A', -90, 90);
* };
*/
function textWidth(str: string): number;
/** 📘
* Calculates and returns the ascent (the distance from the baseline to the top of the highest character) of the current font.
* @param {string} str string to measure
* @returns {number} ascent of the text in pixels
* @example
* q5.draw = function () {
* background(0.8);
*
* textSize(abs(mouseX));
* rect(-90, 90, textWidth('A'), -textAscent());
* text('A', -90, 90);
* };
*/
function textAscent(str: string): number;
/** 📘
* Calculates and returns the descent (the distance from the baseline to the bottom of the lowest character) of the current font.
* @param {string} str string to measure
* @returns {number} descent of the text in pixels
* @example
* await Canvas(200);
* background(0.8);
* textSize(64);
*
* rect(-100, 0, 200, textDescent('q5'));
* text('q5', -90, 0);
*/
function textDescent(str: string): number;
/** 📘
* Creates an image from a string of text.
* @param {string} str string of text
* @param {number} [wrapWidth] maximum line width in characters
* @param {number} [lineLimit] maximum number of lines
* @returns {Q5.Image} an image object representing the rendered text
* @example
* await Canvas(200);
* textSize(96);
*
* let img = createTextImage('🐶');
* img.filter(INVERT);
*
* q5.draw = function () {
* image(img, -45, -90);
* };
*/
function createTextImage(str: string, wrapWidth: number, lineLimit: number): Q5.Image;
/** 📘
* Renders an image generated from text onto the canvas.
*
* If the first parameter is a string, an image of the text will be
* created and cached automatically.
*
* The positioning of the image is affected by the current text
* alignment and baseline settings.
*
* This function can be used to draw emojis, which can
* not be drawn with MSDF text rendering.
*
* Using this function to draw text that changes every frame has a
* very high performance cost.
* @param {Q5.Image | string} img image or text
* @param {number} x x-coordinate where the image should be placed
* @param {number} y y-coordinate where the image should be placed
* @example
* await Canvas(200);
* background(0.8);
* textSize(96);
* textAlign(CENTER, CENTER);
*
* textImage('🐶', 0, 0);
*/
function textImage(img: Q5.Image | String, x: number, y: number): void;
/** 📘
* Converts a string of text to an array of points.
*
* Samples opaque pixels in a text image made with `createTextImage`.
*
* It's influenced by text settings, such as font, size, and alignment.
*
* Uses a [Z-order curve](https://wikipedia.org/wiki/Z-order_curve) to improve spatial distribution, which preserves the shape of text better than purely random sampling.
* @param {string} str string of text
* @param {number} [x=0] x coordinate of the text position
* @param {number} [y=0] y coordinate of the text position
* @param {number} [sampleRate=0.1] lower values increase dithering (1 = all points, 0.1 = ~10% of points)
* @param {number} [density=1] pixel density of the text
* @example
* await Canvas(200);
* textSize(220);
* textAlign(CENTER, CENTER);
*
* let points = textToPoints('5');
*
* for (let pt of points) {
* rect(pt.x, pt.y, 5, 20);
* }
* @example
* await Canvas(200, 296);
* textSize(340);
* noFill();
* stroke(1);
* strokeWeight(8);
*
* let pts = textToPoints('q', -100, 56);
*
* strokeWeight(1);
* for (let pt of pts) {
* ellipse(pt.x, pt.y, 10, 0.1);
* }
*/
function textToPoints(str: string, x?: number, y?: number, sampleRate?: number, density?: number): [];
/** 📘
* Number formatter, can be used to display a number as a string with