q5 3.5.1 → 3.6.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.
@@ -0,0 +1,3950 @@
1
+ declare global {
2
+
3
+ // ⭐ core
4
+
5
+ /**
6
+ * Welcome to q5's documentation! 🤩
7
+ *
8
+ * First time coding? Check out the [q5 Beginner's Brief](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Brief).
9
+ *
10
+ * On these Learn pages, you can experiment with editing the
11
+ * interactive mini examples. Have fun! 😎
12
+ */
13
+
14
+ /** ⭐
15
+ * Creates a canvas element, a section of the screen your program
16
+ * can draw on.
17
+ *
18
+ * Run this function to start using q5!
19
+ *
20
+ * Note that in this example, the circle is located at position [0, 0], the origin of the canvas.
21
+ * @param {number} [w] width or side lengths of the canvas
22
+ * @param {number} [h] height of the canvas
23
+ * @param {object} [opt] [options](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getContextAttributes)
24
+ * @returns {HTMLCanvasElement} created canvas element
25
+ * @example
26
+ * // Canvas2D
27
+ * createCanvas(200, 100);
28
+ * background('silver');
29
+ * circle(0, 0, 80);
30
+ */
31
+ function createCanvas(w?: number, h?: number, options?: CanvasRenderingContext2DSettings): HTMLCanvasElement;
32
+
33
+ /** ⭐
34
+ * The q5 draw function is run 60 times per second by default.
35
+ * @example
36
+ * function draw() {
37
+ * background('silver');
38
+ * circle(mouseX, mouseY, 80);
39
+ * }
40
+ */
41
+ function draw(): void;
42
+
43
+ /** ⭐
44
+ * Logs a message to the JavaScript console.
45
+ *
46
+ * To view the console, open your browser's web developer tools
47
+ * via the keyboard shortcut `Ctrl + Shift + i` or `command + option + i`,
48
+ * then click the "Console" tab.
49
+ *
50
+ * This is an alias for the standard
51
+ * [`console.log`](https://developer.mozilla.org/docs/Web/API/console/log_static) function.
52
+ *
53
+ * When you're curious about what your code is doing, use `log()`!
54
+ * @param {*} message
55
+ * @example
56
+ * function draw() {
57
+ * circle(mouseX, mouseY, 80);
58
+ * log('The mouse is at:', mouseX, mouseY);
59
+ * }
60
+ */
61
+ function log(message: any): void;
62
+
63
+ // 🧑‍🎨 shapes
64
+
65
+ /** 🧑‍🎨
66
+ * Draws a circle.
67
+ * @param {number} x x-coordinate
68
+ * @param {number} y y-coordinate
69
+ * @param {number} diameter diameter of the circle
70
+ * @example
71
+ * createCanvas(200, 100);
72
+ * circle(100, 50, 80);
73
+ */
74
+ function circle(x: number, y: number, diameter: number): void;
75
+
76
+ /** 🧑‍🎨
77
+ * Draws an ellipse.
78
+ * @param {number} x x-coordinate
79
+ * @param {number} y y-coordinate
80
+ * @param {number} width width of the ellipse
81
+ * @param {number} [height] height of the ellipse
82
+ * @example
83
+ * createCanvas(200, 100);
84
+ * ellipse(100, 50, 160, 80);
85
+ */
86
+ function ellipse(x: number, y: number, width: number, height?: number): void;
87
+
88
+ /** 🧑‍🎨
89
+ * Draws a rectangle or a rounded rectangle.
90
+ * @param {number} x x-coordinate
91
+ * @param {number} y y-coordinate
92
+ * @param {number} w width of the rectangle
93
+ * @param {number} [h] height of the rectangle
94
+ * @param {number} [rounded] radius for all corners
95
+ * @example
96
+ * createCanvas(200);
97
+ * background(200);
98
+ *
99
+ * rect(30, 20, 40, 60);
100
+ * rect(80, 70, 40, 60, 10);
101
+ * rect(130, 120, 40, 60, 30, 2, 8, 20);
102
+ */
103
+ function rect(x: number, y: number, w: number, h?: number, rounded?: number): void;
104
+
105
+ /** 🧑‍🎨
106
+ * Draws a square or a rounded square.
107
+ * @param {number} x x-coordinate
108
+ * @param {number} y y-coordinate
109
+ * @param {number} size size of the sides of the square
110
+ * @param {number} [rounded] radius for all corners
111
+ * @example
112
+ * createCanvas(200);
113
+ * background(200);
114
+ *
115
+ * square(30, 30, 40);
116
+ * square(80, 80, 40, 10);
117
+ * square(130, 130, 40, 30, 2, 8, 20);
118
+ */
119
+ function square(x: number, y: number, size: number, rounded?: number): void;
120
+
121
+ /** 🧑‍🎨
122
+ * Draws a point on the canvas.
123
+ * @param {number} x x-coordinate
124
+ * @param {number} y y-coordinate
125
+ * @example
126
+ * createCanvas(200, 100);
127
+ * stroke('white');
128
+ * point(75, 50);
129
+ *
130
+ * strokeWeight(10);
131
+ * point(125, 50);
132
+ */
133
+ function point(x: number, y: number): void;
134
+
135
+ /** 🧑‍🎨
136
+ * Draws a line on the canvas.
137
+ * @param {number} x1 x-coordinate of the first point
138
+ * @param {number} y1 y-coordinate of the first point
139
+ * @param {number} x2 x-coordinate of the second point
140
+ * @param {number} y2 y-coordinate of the second point
141
+ * @example
142
+ * createCanvas(200, 100);
143
+ * stroke('lime');
144
+ * line(20, 20, 180, 80);
145
+ */
146
+ function line(x1: number, y1: number, x2: number, y2: number): void;
147
+
148
+ /** 🧑‍🎨
149
+ * Draws a capsule.
150
+ * @param {number} x1 x-coordinate of the first point
151
+ * @param {number} y1 y-coordinate of the first point
152
+ * @param {number} x2 x-coordinate of the second point
153
+ * @param {number} y2 y-coordinate of the second point
154
+ * @param {number} r radius of the capsule semi-circle ends
155
+ * @example
156
+ * createCanvas(200, 100);
157
+ * background(200);
158
+ * strokeWeight(5);
159
+ * capsule(40, 40, 160, 60, 10);
160
+ * @example
161
+ * function draw() {
162
+ * background(200);
163
+ * fill('cyan');
164
+ * strokeWeight(10);
165
+ * capsule(100, 100, mouseX, mouseY, 20);
166
+ * }
167
+ */
168
+ function capsule(x1: number, y1: number, x2: number, y2: number, r: number): void;
169
+
170
+ /** 🧑‍🎨
171
+ * Set to `CORNER` (default), `CENTER`, `RADIUS`, or `CORNERS`.
172
+ *
173
+ * Changes how the first four inputs to
174
+ * `rect` and `square` are interpreted.
175
+ * @param {string} mode
176
+ * @example
177
+ * createCanvas(200, 100);
178
+ * background(200);
179
+ * rectMode(CORNER);
180
+ *
181
+ * // ( x, y, w, h)
182
+ * rect(50, 25, 100, 50);
183
+ * @example
184
+ * createCanvas(200, 100);
185
+ * background(200);
186
+ * rectMode(CENTER);
187
+ *
188
+ * // ( cX, cY, w, h)
189
+ * rect(100, 50, 100, 50);
190
+ * @example
191
+ * createCanvas(200, 100);
192
+ * background(200);
193
+ * rectMode(RADIUS);
194
+ *
195
+ * // ( cX, cY, rX, rY)
196
+ * rect(100, 50, 50, 25);
197
+ * @example
198
+ * createCanvas(200, 100);
199
+ * background(200);
200
+ * rectMode(CORNERS);
201
+ *
202
+ * // ( x1, y1, x2, y2)
203
+ * rect(50, 25, 150, 75);
204
+ */
205
+ function rectMode(mode: string): void;
206
+
207
+ /** 🧑‍🎨
208
+ * Set to `CENTER` (default), `RADIUS`, `CORNER`, or `CORNERS`.
209
+ *
210
+ * Changes how the first four inputs to
211
+ * `ellipse`, `circle`, and `arc` are interpreted.
212
+ * @param {string} mode
213
+ * @example
214
+ * createCanvas(200, 100);
215
+ * background(200);
216
+ * ellipseMode(CENTER);
217
+ *
218
+ * // ( x, y, w, h)
219
+ * ellipse(100, 50, 100, 50);
220
+ * @example
221
+ * createCanvas(200, 100);
222
+ * background(200);
223
+ * ellipseMode(RADIUS);
224
+ *
225
+ * // ( x, y, rX, rY)
226
+ * ellipse(100, 50, 50, 25);
227
+ * @example
228
+ * createCanvas(200, 100);
229
+ * background(200);
230
+ * ellipseMode(CORNER);
231
+ *
232
+ * // (lX, tY, w, h)
233
+ * ellipse(50, 25, 100, 50);
234
+ * @example
235
+ * createCanvas(200, 100);
236
+ * background(200);
237
+ * ellipseMode(CORNERS);
238
+ *
239
+ * // ( x1, y1, x2, y2)
240
+ * ellipse(50, 25, 150, 75);
241
+ */
242
+ function ellipseMode(mode: string): void;
243
+
244
+ /** 🧑‍🎨
245
+ * Shape alignment mode, for use in `rectMode` and `ellipseMode`.
246
+ */
247
+ const CORNER: 'corner';
248
+
249
+ /** 🧑‍🎨
250
+ * Shape alignment mode, for use in `rectMode` and `ellipseMode`.
251
+ */
252
+ const RADIUS: 'radius';
253
+
254
+ /** 🧑‍🎨
255
+ * Shape alignment mode, for use in `rectMode` and `ellipseMode`.
256
+ */
257
+ const CORNERS: 'corners';
258
+
259
+ // 🌆 image
260
+
261
+ /** 🌆
262
+ * Loads an image from a URL and optionally runs a callback function.
263
+ * @param {string} url url of the image to load
264
+ * @returns {Q5.Image & PromiseLike<Q5.Image>} image
265
+ * @example
266
+ * createCanvas(200);
267
+ *
268
+ * let logo = loadImage('/q5js_logo.avif');
269
+ *
270
+ * function draw() {
271
+ * background(logo);
272
+ * }
273
+ */
274
+ function loadImage(url: string): Q5.Image & PromiseLike<Q5.Image>;
275
+
276
+ /** 🌆
277
+ * Draws an image or video frame to the canvas.
278
+ * @param {Q5.Image | HTMLVideoElement} img image or video to draw
279
+ * @param {number} dx x position to draw the image at
280
+ * @param {number} dy y position to draw the image at
281
+ * @param {number} [dw] width of the destination image
282
+ * @param {number} [dh] height of the destination image
283
+ * @param {number} [sx] x position in the source to start clipping a subsection from
284
+ * @param {number} [sy] y position in the source to start clipping a subsection from
285
+ * @param {number} [sw] width of the subsection of the source image
286
+ * @param {number} [sh] height of the subsection of the source image
287
+ * @example
288
+ * createCanvas(200);
289
+ *
290
+ * let logo = loadImage('/q5js_logo.avif');
291
+ *
292
+ * function draw() {
293
+ * image(logo, 0, 0, 200, 200);
294
+ * }
295
+ * @example
296
+ * createCanvas(200);
297
+ *
298
+ * let logo = loadImage('/q5js_logo.avif');
299
+ *
300
+ * function draw() {
301
+ * image(logo, 0, 0, 200, 200, 256, 256, 512, 512);
302
+ * }
303
+ */
304
+ function image(): void;
305
+
306
+ /** 🌆
307
+ * Set to `CORNER` (default), `CORNERS`, or `CENTER`.
308
+ *
309
+ * Changes how inputs to `image` are interpreted.
310
+ * @param {string} mode
311
+ * @example
312
+ * createCanvas(200);
313
+ * let logo = loadImage('/q5js_logo.avif');
314
+ *
315
+ * function draw() {
316
+ * imageMode(CORNER);
317
+ *
318
+ * // ( img, x, y, w, h)
319
+ * image(logo, 50, 50, 100, 100);
320
+ * }
321
+ * @example
322
+ * createCanvas(200);
323
+ * let logo = loadImage('/q5js_logo.avif');
324
+ *
325
+ * function draw() {
326
+ * imageMode(CENTER);
327
+ *
328
+ * // ( img, cX, cY, w, h)
329
+ * image(logo, 100, 100, 100, 100);
330
+ * }
331
+ * @example
332
+ * createCanvas(200);
333
+ * let logo = loadImage('/q5js_logo.avif');
334
+ *
335
+ * function draw() {
336
+ * imageMode(CORNERS);
337
+ *
338
+ * // ( img, x1, y1, x2, y2)
339
+ * image(logo, 50, 50, 100, 100);
340
+ * }
341
+ */
342
+ function imageMode(mode: string): void;
343
+
344
+ /** 🌆
345
+ * Sets the default image scale, which is applied to images when
346
+ * they are drawn without a specified width or height.
347
+ *
348
+ * By default it is 0.5 so images appear at their actual size
349
+ * when pixel density is 2. Images will be drawn at a consistent
350
+ * default size relative to the canvas regardless of pixel density.
351
+ *
352
+ * This function must be called before images are loaded to
353
+ * have an effect.
354
+ * @param {number} scale
355
+ * @returns {number} default image scale
356
+ */
357
+ function defaultImageScale(scale: number): number;
358
+
359
+ /** 🌆
360
+ * Resizes the image.
361
+ * @param {number} w new width
362
+ * @param {number} h new height
363
+ * @example
364
+ * createCanvas(200);
365
+ *
366
+ * let logo = loadImage('/q5js_logo.avif');
367
+ *
368
+ * function setup() {
369
+ * logo.resize(128, 128);
370
+ * image(logo, 0, 0, 200, 200);
371
+ * }
372
+ */
373
+ function resize(w: number, h: number): void;
374
+
375
+ /** 🌆
376
+ * Returns a trimmed image, cropping out transparent pixels from the edges.
377
+ * @returns {Q5.Image}
378
+ */
379
+ function trim(): Q5.Image;
380
+
381
+ /** 🌆
382
+ * Enables smooth rendering of images displayed larger than
383
+ * their actual size. This is the default setting, so running this
384
+ * function only has an effect if `noSmooth` has been called.
385
+ * @example
386
+ * createCanvas(200);
387
+ *
388
+ * let icon = loadImage('/q5js_icon.png');
389
+ *
390
+ * function setup() {
391
+ * image(icon, 0, 0, 200, 200);
392
+ * }
393
+ */
394
+ function smooth(): void;
395
+
396
+ /** 🌆
397
+ * Disables smooth image rendering for a pixelated look.
398
+ * @example
399
+ * createCanvas(200);
400
+ *
401
+ * let icon = loadImage('/q5js_icon.png');
402
+ *
403
+ * function setup() {
404
+ * noSmooth();
405
+ * image(icon, 0, 0, 200, 200);
406
+ * }
407
+ */
408
+ function noSmooth(): void;
409
+
410
+ /** 🌆
411
+ * Applies a tint (color overlay) to the drawing.
412
+ *
413
+ * The alpha value of the tint color determines the
414
+ * strength of the tint. To change an image's opacity,
415
+ * use the `opacity` function.
416
+ *
417
+ * Tinting affects all subsequent images drawn. The tint
418
+ * color is applied to images using the "multiply" blend mode.
419
+ *
420
+ * Since the tinting process is performance intensive, each time
421
+ * an image is tinted, q5 caches the result. `image` will draw the
422
+ * cached tinted image unless the tint color has changed or the
423
+ * image being tinted was edited.
424
+ *
425
+ * If you need to draw an image multiple times each frame with
426
+ * different tints, consider making copies of the image and tinting
427
+ * each copy separately.
428
+ * @param {string | number} color tint color
429
+ * @example
430
+ * createCanvas(200);
431
+ *
432
+ * let logo = loadImage('/q5js_logo.avif');
433
+ *
434
+ * function setup() {
435
+ * tint(255, 0, 0, 128);
436
+ * image(logo, 0, 0, 200, 200);
437
+ * }
438
+ */
439
+ function tint(color: string | number): void;
440
+
441
+ /** 🌆
442
+ * Images drawn after this function is run will not be tinted.
443
+ */
444
+ function noTint(): void;
445
+
446
+ /** 🌆
447
+ * Masks the image with another image.
448
+ * @param {Q5.Image} img image to use as a mask
449
+ */
450
+ function mask(img: Q5.Image): void;
451
+
452
+ /** 🌆
453
+ * Returns a copy of the image.
454
+ * @returns {Q5.Image}
455
+ */
456
+ function copy(): Q5.Image;
457
+
458
+ /** 🌆
459
+ * Displays a region of the image on another region of the image.
460
+ * Can be used to create a detail inset, aka a magnifying glass effect.
461
+ * @param {number} sx x-coordinate of the source region
462
+ * @param {number} sy y-coordinate of the source region
463
+ * @param {number} sw width of the source region
464
+ * @param {number} sh height of the source region
465
+ * @param {number} dx x-coordinate of the destination region
466
+ * @param {number} dy y-coordinate of the destination region
467
+ * @param {number} dw width of the destination region
468
+ * @param {number} dh height of the destination region
469
+ * @example
470
+ * createCanvas(200);
471
+ *
472
+ * let logo = loadImage('/q5js_logo.avif');
473
+ *
474
+ * function setup() {
475
+ * logo.inset(256, 256, 512, 512, 0, 0, 256, 256);
476
+ * image(logo, 0, 0, 200, 200);
477
+ * }
478
+ */
479
+ function inset(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
480
+
481
+ /** 🌆
482
+ * Retrieves a subsection of an image or canvas as a new Q5 Image
483
+ * or the color of a pixel in the image or canvas.
484
+ *
485
+ * If only x and y are specified, this function returns the color of the pixel
486
+ * at the given coordinate in `[R, G, B, A]` array format. If `loadPixels`
487
+ * has never been run, it's run by this function.
488
+ *
489
+ * If you make changes to the canvas or image, you must call `loadPixels`
490
+ * before using this function to get current color data.
491
+ * @param {number} x
492
+ * @param {number} y
493
+ * @param {number} [w] width of the area, default is 1
494
+ * @param {number} [h] height of the area, default is 1
495
+ * @returns {Q5.Image | number[]}
496
+ * @example
497
+ * function draw() {
498
+ * background(200);
499
+ * noStroke();
500
+ * circle(100, 100, frameCount % 200);
501
+ *
502
+ * loadPixels();
503
+ * let col = get(mouseX, mouseY);
504
+ * text(col, mouseX, mouseY);
505
+ * }
506
+ * @example
507
+ * createCanvas(200);
508
+ *
509
+ * let logo = loadImage('/q5js_logo.avif');
510
+ *
511
+ * function setup() {
512
+ * let cropped = logo.get(256, 256, 512, 512);
513
+ * image(cropped, 0, 0, 200, 200);
514
+ * }
515
+ */
516
+ function get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
517
+
518
+ /** 🌆
519
+ * Sets a pixel's color in the image or canvas.
520
+ *
521
+ * Or if a canvas or image is provided, it's drawn on top of the
522
+ * destination image or canvas, ignoring its tint setting.
523
+ *
524
+ * Run `updatePixels` to apply the changes.
525
+ * @param {number} x
526
+ * @param {number} y
527
+ * @param {any} val color, canvas, or image
528
+ * @example
529
+ * createCanvas(200);
530
+ * let c = color('lime');
531
+ *
532
+ * function draw() {
533
+ * set(random(200), random(200), c);
534
+ * updatePixels();
535
+ * }
536
+ */
537
+ function set(x: number, y: number, val: any): void;
538
+
539
+ /** 🌆
540
+ * Array of pixel color data from a canvas or image.
541
+ *
542
+ * Each pixel is represented by four consecutive values in the array,
543
+ * corresponding to its red, green, blue, and alpha channels.
544
+ *
545
+ * The top left pixel's data is at the beginning of the array
546
+ * and the bottom right pixel's data is at the end, going from
547
+ * left to right and top to bottom.
548
+ *
549
+ * Use `loadPixels` to load current pixel data from a canvas or image.
550
+ */
551
+ var pixels: number[];
552
+
553
+ /** 🌆
554
+ * Loads pixel data into `pixels` from the canvas or image.
555
+ *
556
+ * The example below sets some pixels' green channel
557
+ * to a random 0-255 value.
558
+ * @example
559
+ * frameRate(5);
560
+ * let icon = loadImage('/q5js_icon.png');
561
+ *
562
+ * function draw() {
563
+ * icon.loadPixels();
564
+ * for (let i = 0; i < icon.pixels.length; i += 16) {
565
+ * icon.pixels[i + 1] = random(255);
566
+ * }
567
+ * icon.updatePixels();
568
+ * background(icon);
569
+ * }
570
+ */
571
+ function loadPixels(): void;
572
+
573
+ /** 🌆
574
+ * Applies changes in the `pixels` array to the canvas or image.
575
+ * @example
576
+ * createCanvas(200);
577
+ *
578
+ * for (let x = 0; x < 200; x += 5) {
579
+ * for (let y = 0; y < 200; y += 5) {
580
+ * set(x, y, color('pink'));
581
+ * }
582
+ * }
583
+ * updatePixels();
584
+ */
585
+ function updatePixels(): void;
586
+
587
+ /** 🌆
588
+ * Applies a filter to the image.
589
+ *
590
+ * See the documentation for q5's filter constants below for more info.
591
+ *
592
+ * A CSS filter string can also be used.
593
+ * https://developer.mozilla.org/docs/Web/CSS/filter
594
+ * @param {string} type filter type or a CSS filter string
595
+ * @param {number} [value] optional value, depends on filter type
596
+ * @example
597
+ * createCanvas(200);
598
+ * let logo = loadImage('/q5js_logo.avif');
599
+ *
600
+ * function setup() {
601
+ * logo.filter(INVERT);
602
+ * image(logo, 0, 0, 200, 200);
603
+ * }
604
+ */
605
+ function filter(type: string, value?: number): void;
606
+
607
+ /** 🌆
608
+ * Converts the image to black and white pixels depending if they are above or below a certain threshold.
609
+ */
610
+ const THRESHOLD: 1;
611
+
612
+ /** 🌆
613
+ * Converts the image to grayscale by setting each pixel to its luminance.
614
+ */
615
+ const GRAY: 2;
616
+
617
+ /** 🌆
618
+ * Sets the alpha channel to fully opaque.
619
+ */
620
+ const OPAQUE: 3;
621
+
622
+ /** 🌆
623
+ * Inverts the color of each pixel.
624
+ */
625
+ const INVERT: 4;
626
+
627
+ /** 🌆
628
+ * Limits each channel of the image to the number of colors specified as an argument.
629
+ */
630
+ const POSTERIZE: 5;
631
+
632
+ /** 🌆
633
+ * Increases the size of bright areas.
634
+ */
635
+ const DILATE: 6;
636
+
637
+ /** 🌆
638
+ * Increases the size of dark areas.
639
+ */
640
+ const ERODE: 7;
641
+
642
+ /** 🌆
643
+ * Applies a Gaussian blur to the image.
644
+ */
645
+ const BLUR: 8;
646
+
647
+ /** 🌆
648
+ * Creates a new image.
649
+ * @param {number} w width
650
+ * @param {number} h height
651
+ * @param {any} [opt] optional settings for the image
652
+ * @returns {Q5.Image}
653
+ */
654
+ function createImage(w: number, h: number, opt?: any): Q5.Image;
655
+
656
+ /** 🌆
657
+ * Creates a graphics buffer.
658
+ *
659
+ * Disabled by default in q5 WebGPU.
660
+ * See issue [#104](https://github.com/q5js/q5.js/issues/104) for details.
661
+ * @param {number} w width
662
+ * @param {number} h height
663
+ * @param {object} [opt] options
664
+ * @returns {Q5} a new Q5 graphics buffer
665
+ */
666
+ function createGraphics(w: number, h: number, opt?: any): Q5;
667
+
668
+ namespace Q5 {
669
+ interface Image {
670
+ width: number;
671
+ height: number;
672
+ }
673
+ }
674
+
675
+ // 📘 text
676
+
677
+ /** 📘
678
+ * Renders text to the screen. Text can be positioned with the x and y
679
+ * parameters and can optionally be constrained.
680
+ * @param {string} str string of text to display
681
+ * @param {number} x x-coordinate of the text's position
682
+ * @param {number} y y-coordinate of the text's position
683
+ * @param {number} [wrapWidth] maximum line width in characters
684
+ * @param {number} [lineLimit] maximum number of lines
685
+ * @example
686
+ * createCanvas(200, 100);
687
+ * background('silver');
688
+ *
689
+ * textSize(32);
690
+ * text('Hello, world!', 12, 60);
691
+ * @example
692
+ * createCanvas(200);
693
+ * background(200);
694
+ * textSize(20);
695
+ *
696
+ * let info =
697
+ * 'q5.js was designed to make creative coding fun and accessible for a new generation of artists, designers, educators, and beginners.';
698
+ *
699
+ * text(info, 12, 30, 20, 6);
700
+ * //
701
+ * //
702
+ */
703
+ function text(str: string, x: number, y: number, wrapWidth?: number, lineLimit?: number): void;
704
+
705
+ /** 📘
706
+ * Loads a font from a URL.
707
+ *
708
+ * The font file can be in any format accepted in CSS, such as
709
+ * .ttf and .otf files. The first example below loads
710
+ * [Robotica](https://www.dafont.com/robotica-courtney.font).
711
+ *
712
+ * Also supports loading [Google fonts](https://fonts.google.com/).
713
+ * The second example loads
714
+ * [Pacifico](https://fonts.google.com/specimen/Pacifico).
715
+ *
716
+ * If no fonts are loaded, the default sans-serif font is used.
717
+ *
718
+ * In q5 WebGPU, only fonts in [MSDF format](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer#text-rendering)
719
+ * with the file ending "-msdf.json" can be used to render text with
720
+ * the `text` function. Fonts in other formats can be used with the
721
+ * [`textImage`](https://q5js.org/learn/#textImage) function.
722
+ * @param {string} url URL of the font to load
723
+ * @returns {FontFace & PromiseLike<FontFace>} font
724
+ * @example
725
+ * createCanvas(200, 56);
726
+ *
727
+ * loadFont('/assets/Robotica.ttf');
728
+ *
729
+ * function setup() {
730
+ * fill('skyblue');
731
+ * textSize(64);
732
+ * text('Hello!', 2, 54);
733
+ * }
734
+ * @example
735
+ * createCanvas(200, 74);
736
+ *
737
+ * loadFont('fonts.googleapis.com/css2?family=Pacifico');
738
+ *
739
+ * function setup() {
740
+ * fill('hotpink');
741
+ * textSize(68);
742
+ * text('Hello!', 2, 68);
743
+ * }
744
+ */
745
+ function loadFont(url: string): FontFace & PromiseLike<FontFace>;
746
+
747
+ /** 📘
748
+ * Sets the current font to be used for rendering text.
749
+ *
750
+ * By default, the font is set to the [CSS font family](https://developer.mozilla.org/docs/Web/CSS/font-family)
751
+ * "sans-serif" or the last font loaded.
752
+ * @param {string} fontName name of the font family or a FontFace object
753
+ * @example
754
+ * createCanvas(200, 160);
755
+ * background(200);
756
+ *
757
+ * textFont('serif');
758
+ *
759
+ * textSize(32);
760
+ * text('Hello, world!', 15, 90);
761
+ * @example
762
+ * createCanvas(200);
763
+ * background(200);
764
+ *
765
+ * textFont('monospace');
766
+ *
767
+ * textSize(24);
768
+ * text('Hello, world!', 15, 90);
769
+ */
770
+ function textFont(fontName: string): void;
771
+
772
+ /** 📘
773
+ * Sets or gets the current font size. If no argument is provided, returns the current font size.
774
+ * @param {number} [size] size of the font in pixels
775
+ * @returns {number | void} current font size when no argument is provided
776
+ * @example
777
+ * function draw() {
778
+ * background(200);
779
+ *
780
+ * textSize(abs(mouseX));
781
+ * text('A', 10, 190);
782
+ * }
783
+ */
784
+ function textSize(size?: number): number | void;
785
+
786
+ /** 📘
787
+ * Sets or gets the current line height. If no argument is provided, returns the current line height.
788
+ * @param {number} [leading] line height in pixels
789
+ * @returns {number | void} current line height when no argument is provided
790
+ * @example
791
+ * function draw() {
792
+ * background(200);
793
+ *
794
+ * textSize(abs(mouseX));
795
+ * text('A', 10, 190);
796
+ * rect(10, 190, 5, -textLeading());
797
+ * }
798
+ */
799
+ function textLeading(leading?: number): number | void;
800
+
801
+ /** 📘
802
+ * Sets the current text style.
803
+ * @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
804
+ * @example
805
+ * createCanvas(200);
806
+ * background(200);
807
+ *
808
+ * textStyle(ITALIC);
809
+ *
810
+ * textSize(32);
811
+ * text('Hello, world!', 12, 106);
812
+ */
813
+ function textStyle(style: 'normal' | 'italic' | 'bold' | 'bolditalic'): void;
814
+
815
+ /** 📘
816
+ * Sets the horizontal and vertical alignment of text.
817
+ * @param {'left' | 'center' | 'right'} horiz horizontal alignment
818
+ * @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
819
+ * @example
820
+ * createCanvas(200);
821
+ * background(200);
822
+ * textSize(32);
823
+ *
824
+ * textAlign(CENTER, MIDDLE);
825
+ * text('Hello, world!', 100, 100);
826
+ */
827
+ function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'middle' | 'bottom' | 'alphabetic'): void;
828
+
829
+ /** 📘
830
+ * Sets the text weight.
831
+ *
832
+ * - 100: thin
833
+ * - 200: extra-light
834
+ * - 300: light
835
+ * - 400: normal/regular
836
+ * - 500: medium
837
+ * - 600: semi-bold
838
+ * - 700: bold
839
+ * - 800: bolder/extra-bold
840
+ * - 900: black/heavy
841
+ * @param {number | string} weight font weight
842
+ * @example
843
+ * createCanvas(200);
844
+ * background(200);
845
+ * textSize(32);
846
+ * textAlign(CENTER, MIDDLE);
847
+ *
848
+ * textWeight(100);
849
+ * text('Hello, world!', 100, 100);
850
+ */
851
+ function textWeight(weight: number | string): void;
852
+
853
+ /** 📘
854
+ * Calculates and returns the width of a given string of text.
855
+ * @param {string} str string to measure
856
+ * @returns {number} width of the text in pixels
857
+ * @example
858
+ * function draw() {
859
+ * background(200);
860
+ *
861
+ * textSize(abs(mouseX));
862
+ * rect(10, 190, textWidth('A'), -textLeading());
863
+ * text('A', 10, 190);
864
+ * }
865
+ */
866
+ function textWidth(str: string): number;
867
+
868
+ /** 📘
869
+ * Calculates and returns the ascent (the distance from the baseline to the top of the highest character) of the current font.
870
+ * @param {string} str string to measure
871
+ * @returns {number} ascent of the text in pixels
872
+ * @example
873
+ * function draw() {
874
+ * background(200);
875
+ *
876
+ * textSize(abs(mouseX));
877
+ * rect(10, 190, textWidth('A'), -textAscent());
878
+ * text('A', 10, 190);
879
+ * }
880
+ */
881
+ function textAscent(str: string): number;
882
+
883
+ /** 📘
884
+ * Calculates and returns the descent (the distance from the baseline to the bottom of the lowest character) of the current font.
885
+ * @param {string} str string to measure
886
+ * @returns {number} descent of the text in pixels
887
+ * @example
888
+ * createCanvas(200);
889
+ * background(200);
890
+ * textSize(64);
891
+ *
892
+ * rect(0, 100, 200, textDescent('q5'));
893
+ * text('q5', 10, 100);
894
+ */
895
+ function textDescent(str: string): number;
896
+
897
+ /** 📘
898
+ * Creates an image from a string of text.
899
+ * @param {string} str string of text
900
+ * @param {number} [wrapWidth] maximum line width in characters
901
+ * @param {number} [lineLimit] maximum number of lines
902
+ * @returns {Q5.Image} an image object representing the rendered text
903
+ * @example
904
+ * createCanvas(200);
905
+ * textSize(96);
906
+ *
907
+ * let img = createTextImage('🐶');
908
+ * img.filter(INVERT);
909
+ *
910
+ * function draw() {
911
+ * image(img, 55, 10);
912
+ * }
913
+ */
914
+ function createTextImage(str: string, wrapWidth: number, lineLimit: number): Q5.Image;
915
+
916
+ /** 📘
917
+ * Renders an image generated from text onto the canvas.
918
+ *
919
+ * If the first parameter is a string, an image of the text will be
920
+ * created and cached automatically.
921
+ *
922
+ * The positioning of the image is affected by the current text
923
+ * alignment and baseline settings.
924
+ *
925
+ * In q5 WebGPU, this function is the only way to draw multi-colored
926
+ * text, like emojis, and to use fonts that aren't in MSDF format.
927
+ * Using this function to draw text that changes every frame has
928
+ * a very high performance cost.
929
+ * @param {Q5.Image | string} img image or text
930
+ * @param {number} x x-coordinate where the image should be placed
931
+ * @param {number} y y-coordinate where the image should be placed
932
+ * @example
933
+ * createCanvas(200);
934
+ * background(200);
935
+ * textSize(96);
936
+ * textAlign(CENTER, CENTER);
937
+ *
938
+ * textImage('🐶', 100, 100);
939
+ * @example
940
+ * createCanvas(200);
941
+ *
942
+ * loadFont('/assets/Robotica.ttf');
943
+ *
944
+ * function setup() {
945
+ * background(200);
946
+ * textSize(66);
947
+ * textImage('Hello!', 0, 0);
948
+ * }
949
+ */
950
+ function textImage(img: Q5.Image | String, x: number, y: number): void;
951
+
952
+ /** 📘
953
+ * Number formatter, can be used to display a number as a string with
954
+ * a specified number of digits before and after the decimal point,
955
+ * optionally adding padding with zeros.
956
+ * @param {number} n number to format
957
+ * @param {number} l minimum number of digits to appear before the decimal point; the number is padded with zeros if necessary
958
+ * @param {number} r number of digits to appear after the decimal point
959
+ * @returns {string} a string representation of the number, formatted accordingly
960
+ * @example
961
+ * createCanvas(200, 100);
962
+ * background(200);
963
+ *
964
+ * textSize(32);
965
+ * text(nf(PI, 4, 5), 10, 60);
966
+ */
967
+ function nf(num: number, digits: number): string;
968
+
969
+ /** 📘
970
+ * Normal font style.
971
+ */
972
+ const NORMAL: 'normal';
973
+
974
+ /** 📘
975
+ * Italic font style.
976
+ */
977
+ const ITALIC: 'italic';
978
+
979
+ /** 📘
980
+ * Bold font weight.
981
+ */
982
+ const BOLD: 'bold';
983
+
984
+ /** 📘
985
+ * Bold and italic font style.
986
+ */
987
+ const BOLDITALIC: 'italic bold';
988
+
989
+ /** 📘
990
+ * Align text to the left.
991
+ */
992
+ const LEFT: 'left';
993
+
994
+ /** 📘
995
+ * Align text to the center.
996
+ */
997
+ const CENTER: 'center';
998
+
999
+ /** 📘
1000
+ * Align text to the right.
1001
+ */
1002
+ const RIGHT: 'right';
1003
+
1004
+ /** 📘
1005
+ * Align text to the top.
1006
+ */
1007
+ const TOP: 'top';
1008
+
1009
+ /** 📘
1010
+ * Align text to the bottom.
1011
+ */
1012
+ const BOTTOM: 'bottom';
1013
+
1014
+ /** 📘
1015
+ * Align text to the baseline (alphabetic).
1016
+ */
1017
+ const BASELINE: 'alphabetic';
1018
+
1019
+ // 🖲 input
1020
+
1021
+ /**
1022
+ * Note that input responses inside `draw` can be delayed by
1023
+ * up to one frame cycle: from the exact moment an input event occurs
1024
+ * to the next time a frame is drawn.
1025
+ *
1026
+ * Play sounds or trigger other non-visual feedback immediately
1027
+ * by responding to input events inside functions like
1028
+ * `mousePressed` and `keyPressed`.
1029
+ */
1030
+
1031
+ /** 🖲
1032
+ * Current X position of the mouse.
1033
+ * @example
1034
+ * function draw() {
1035
+ * background(200);
1036
+ * textSize(64);
1037
+ * text(round(mouseX), 50, 120);
1038
+ * }
1039
+ */
1040
+ let mouseX: number;
1041
+
1042
+ /** 🖲
1043
+ * Current Y position of the mouse.
1044
+ * @example
1045
+ * function draw() {
1046
+ * background(200);
1047
+ * circle(100, mouseY, 100);
1048
+ * }
1049
+ */
1050
+ let mouseY: number;
1051
+
1052
+ /** 🖲
1053
+ * Previous X position of the mouse.
1054
+ */
1055
+ let pmouseX: number;
1056
+
1057
+ /** 🖲
1058
+ * Previous Y position of the mouse.
1059
+ */
1060
+ let pmouseY: number;
1061
+
1062
+ /** 🖲
1063
+ * The current button being pressed: 'left', 'right', 'center').
1064
+ *
1065
+ * The default value is an empty string.
1066
+ * @example
1067
+ * function draw() {
1068
+ * background(200);
1069
+ * textSize(64);
1070
+ * text(mouseButton, 20, 120);
1071
+ * }
1072
+ */
1073
+ let mouseButton: string;
1074
+
1075
+ /** 🖲
1076
+ * True if the mouse is currently pressed, false otherwise.
1077
+ * @example
1078
+ * function draw() {
1079
+ * if (mouseIsPressed) background(100);
1080
+ * else background(200);
1081
+ * }
1082
+ */
1083
+ let mouseIsPressed: boolean;
1084
+
1085
+ /** 🖲
1086
+ * Define this function to respond to mouse down events.
1087
+ * @example
1088
+ * createCanvas(200);
1089
+ * let gray = 95;
1090
+ *
1091
+ * function mousePressed() {
1092
+ * background(gray % 256);
1093
+ * gray += 40;
1094
+ * }
1095
+ */
1096
+ function mousePressed(): void;
1097
+
1098
+ /** 🖲
1099
+ * Define this function to respond to mouse up events.
1100
+ * @example
1101
+ * createCanvas(200);
1102
+ * let gray = 95;
1103
+ *
1104
+ * function mouseReleased() {
1105
+ * background(gray % 256);
1106
+ * gray += 40;
1107
+ * }
1108
+ */
1109
+ function mouseReleased(): void;
1110
+
1111
+ /** 🖲
1112
+ * Define this function to respond to mouse move events.
1113
+ *
1114
+ * On touchscreen devices this function is not called
1115
+ * when the user drags their finger on the screen.
1116
+ * @example
1117
+ * createCanvas(200);
1118
+ * let gray = 95;
1119
+ *
1120
+ * function mouseMoved() {
1121
+ * background(gray % 256);
1122
+ * gray++;
1123
+ * }
1124
+ */
1125
+ function mouseMoved(): void;
1126
+
1127
+ /** 🖲
1128
+ * Define this function to respond to mouse drag events.
1129
+ *
1130
+ * Dragging the mouse is defined as moving the mouse
1131
+ * while a mouse button is pressed.
1132
+ * @example
1133
+ * createCanvas(200);
1134
+ * let gray = 95;
1135
+ *
1136
+ * function mouseDragged() {
1137
+ * background(gray % 256);
1138
+ * gray++;
1139
+ * }
1140
+ */
1141
+ function mouseDragged(): void;
1142
+
1143
+ /** 🖲
1144
+ * Define this function to respond to mouse double click events.
1145
+ * @example
1146
+ * createCanvas(200);
1147
+ * let gray = 95;
1148
+ *
1149
+ * function doubleClicked() {
1150
+ * background(gray % 256);
1151
+ * gray += 40;
1152
+ * }
1153
+ */
1154
+ function doubleClicked(): void;
1155
+
1156
+ /** 🖲
1157
+ * The name of the last key pressed.
1158
+ * @example
1159
+ * function draw() {
1160
+ * background(200);
1161
+ * textSize(64);
1162
+ * text(key, 20, 120);
1163
+ * }
1164
+ */
1165
+ let key: string;
1166
+
1167
+ /** 🖲
1168
+ * True if a key is currently pressed, false otherwise.
1169
+ * @example
1170
+ * function draw() {
1171
+ * if (keyIsPressed) background(100);
1172
+ * else background(200);
1173
+ * }
1174
+ */
1175
+ let keyIsPressed: boolean;
1176
+
1177
+ /** 🖲
1178
+ * Returns true if the user is pressing the specified key, false
1179
+ * otherwise. Accepts case-insensitive key names.
1180
+ * @param {string} key key to check
1181
+ * @returns {boolean} true if the key is pressed, false otherwise
1182
+ * @example
1183
+ * function draw() {
1184
+ * background(200);
1185
+ *
1186
+ * if (keyIsDown('f') && keyIsDown('j')) {
1187
+ * rect(50, 50, 100, 100);
1188
+ * }
1189
+ * }
1190
+ */
1191
+ function keyIsDown(key: string): boolean;
1192
+
1193
+ /** 🖲
1194
+ * Define this function to respond to key down events.
1195
+ * @example
1196
+ * createCanvas(200);
1197
+ *
1198
+ * let gray = 95;
1199
+ * function keyPressed() {
1200
+ * background(gray % 256);
1201
+ * gray += 40;
1202
+ * }
1203
+ */
1204
+ function keyPressed(): void;
1205
+
1206
+ /** 🖲
1207
+ * Define this function to respond to key up events.
1208
+ * @example
1209
+ * createCanvas(200);
1210
+ *
1211
+ * let gray = 95;
1212
+ * function keyReleased() {
1213
+ * background(gray % 256);
1214
+ * gray += 40;
1215
+ * }
1216
+ */
1217
+ function keyReleased(): void;
1218
+
1219
+ /** 🖲
1220
+ * Array containing all current touch points within the
1221
+ * browser window. Each touch being an object with
1222
+ * `id`, `x`, and `y` properties.
1223
+ * @example
1224
+ * function draw() {
1225
+ * background(200);
1226
+ * for (let touch of touches) {
1227
+ * circle(touch.x, touch.y, 100);
1228
+ * }
1229
+ * }
1230
+ */
1231
+ let touches: any[];
1232
+
1233
+ /** 🖲
1234
+ * Define this function to respond to touch down events
1235
+ * on the canvas.
1236
+ *
1237
+ * Return true to enable touch gestures like pinch-to-zoom
1238
+ * and scroll, which q5 disables on the canvas by default.
1239
+ * @example
1240
+ * createCanvas(200);
1241
+ *
1242
+ * let gray = 95;
1243
+ * function touchStarted() {
1244
+ * background(gray % 256);
1245
+ * gray += 40;
1246
+ * }
1247
+ */
1248
+ function touchStarted(): void;
1249
+
1250
+ /** 🖲
1251
+ * Define this function to respond to touch down events
1252
+ * on the canvas.
1253
+ *
1254
+ * Return true to enable touch gestures like pinch-to-zoom
1255
+ * and scroll, which q5 disables on the canvas by default.
1256
+ * @example
1257
+ * createCanvas(200);
1258
+ *
1259
+ * let gray = 95;
1260
+ * function touchEnded() {
1261
+ * background(gray % 256);
1262
+ * gray += 40;
1263
+ * }
1264
+ */
1265
+ function touchEnded(): void;
1266
+
1267
+ /** 🖲
1268
+ * Define this function to respond to touch move events
1269
+ * on the canvas.
1270
+ *
1271
+ * Return true to enable touch gestures like pinch-to-zoom
1272
+ * and scroll, which q5 disables on the canvas by default.
1273
+ * @example
1274
+ * createCanvas(200);
1275
+ * let gray = 95;
1276
+ *
1277
+ * function touchMoved() {
1278
+ * background(gray % 256);
1279
+ * gray++;
1280
+ * }
1281
+ */
1282
+ function touchMoved(): void;
1283
+
1284
+ /** 🖲
1285
+ * Object containing all current pointers within the
1286
+ * browser window.
1287
+ *
1288
+ * This includes mouse, touch, and pen pointers.
1289
+ *
1290
+ * Each pointer is an object with
1291
+ * `event`, `x`, and `y` properties.
1292
+ * The `event` property contains the original
1293
+ * [PointerEvent](https://developer.mozilla.org/docs/Web/API/PointerEvent).
1294
+ * @example
1295
+ * function draw() {
1296
+ * background(200);
1297
+ * for (let pointerID in pointers) {
1298
+ * let pointer = pointers[pointerID];
1299
+ * circle(pointer.x, pointer.y, 100);
1300
+ * }
1301
+ * }
1302
+ */
1303
+ let pointers: {};
1304
+
1305
+ /** 🖲
1306
+ * Sets the cursor to a [CSS cursor type](https://developer.mozilla.org/docs/Web/CSS/cursor) or image.
1307
+ * If an image is provided, optional x and y coordinates can
1308
+ * specify the active point of the cursor.
1309
+ * @param {string} name name of the cursor or the url to an image
1310
+ * @param {number} [x] x-coordinate of the cursor's point
1311
+ * @param {number} [y] y-coordinate of the cursor's point
1312
+ * @example
1313
+ * createCanvas(200, 100);
1314
+ * cursor('pointer');
1315
+ */
1316
+ function cursor(name: string, x?: number, y?: number): void;
1317
+
1318
+ /** 🖲
1319
+ * Hides the cursor within the bounds of the canvas.
1320
+ * @example
1321
+ * createCanvas(200, 100);
1322
+ * noCursor();
1323
+ */
1324
+ function noCursor(): void;
1325
+
1326
+ /** 🖲
1327
+ * Define this function to respond to mouse wheel events.
1328
+ *
1329
+ * `event.deltaX` and `event.deltaY` are the horizontal and vertical
1330
+ * scroll amounts, respectively.
1331
+ *
1332
+ * Return true to allow the default behavior of scrolling the page.
1333
+ * @example
1334
+ * let x = (y = 100);
1335
+ * function draw() {
1336
+ * circle(x, y, 10);
1337
+ * }
1338
+ * function mouseWheel(e) {
1339
+ * x += e.deltaX;
1340
+ * y += e.deltaY;
1341
+ * return false;
1342
+ * }
1343
+ */
1344
+ function mouseWheel(event: any): void;
1345
+
1346
+ /** 🖲
1347
+ * Requests that the pointer be locked to the document body, hiding
1348
+ * the cursor and allowing for unlimited movement.
1349
+ *
1350
+ * Operating systems enable mouse acceleration by default, which is useful when you sometimes want slow precise movement (think about you might use a graphics package), but also want to move great distances with a faster mouse movement (think about scrolling, and selecting several files). For some games however, raw mouse input data is preferred for controlling camera rotation — where the same distance movement, fast or slow, results in the same rotation.
1351
+ *
1352
+ * To exit pointer lock mode, call `document.exitPointerLock()`.
1353
+ * @param {boolean} unadjustedMovement set to true to disable OS-level mouse acceleration and access raw mouse input
1354
+ * @example
1355
+ * function draw() {
1356
+ * circle(mouseX / 10 + 100, mouseY / 10 + 100, 10);
1357
+ * }
1358
+ *
1359
+ * function doubleClicked() {
1360
+ * if (!document.pointerLockElement) {
1361
+ * pointerLock();
1362
+ * } else {
1363
+ * document.exitPointerLock();
1364
+ * }
1365
+ * }
1366
+ */
1367
+ function pointerLock(unadjustedMovement: boolean): void;
1368
+
1369
+ // 🎨 color
1370
+
1371
+ /** 🎨
1372
+ * Creates a new `Color` object, which is primarily useful for storing
1373
+ * a color that your sketch will reuse or modify later.
1374
+ *
1375
+ * With the default RGB color mode, colors have `r`/`red`, `g`/`green`, `b`/`blue`, and `a`/`alpha` components. The default color
1376
+ * format is integer, so set components to values between 0 and 255.
1377
+ *
1378
+ * In q5 WebGPU, the default color mode is RGB in float format, so
1379
+ * set color components to values between 0 and 1.
1380
+ *
1381
+ * The [`fill`](https://q5js.org/learn/#fill), [`stroke`](https://q5js.org/learn/#stroke), and [`background`](https://q5js.org/learn/#background) functions
1382
+ * accept the same wide range of color representations as this function.
1383
+ *
1384
+ * Here are some examples of valid use:
1385
+ *
1386
+ * - `color(255)` (grayscale)
1387
+ * - `color(255, 200)` (grayscale, alpha)
1388
+ * - `color(255, 0, 0)` (r, g, b)
1389
+ * - `color(255, 0, 0, 10)` (r, g, b, a)
1390
+ * - `color('red')` (colorName)
1391
+ * - `color('#ff0000')` (hexColor)
1392
+ * - `color([255, 0, 0])` (colorComponents)
1393
+ * @param {string | number | Color | number[]} c0 color or first color component
1394
+ * @param {number} [c1] second color component
1395
+ * @param {number} [c2] third color component
1396
+ * @param {number} [c3] fourth color component (alpha)
1397
+ * @returns {Color} a new `Color` object
1398
+ * @example
1399
+ * createCanvas(200);
1400
+ * rect(0, 0, 100, 200);
1401
+ *
1402
+ * // ( r, g, b, a)
1403
+ * let bottle = color(90, 100, 255, 100);
1404
+ * fill(bottle);
1405
+ * stroke(bottle);
1406
+ * strokeWeight(30);
1407
+ * circle(100, 100, 155);
1408
+ * @example
1409
+ * createCanvas(200);
1410
+ * // (gray, alpha)
1411
+ * let c = color(200, 50);
1412
+ *
1413
+ * function draw() {
1414
+ * background(c);
1415
+ * circle(mouseX, mouseY, 50);
1416
+ * c.g = (c.g + 1) % 256;
1417
+ * }
1418
+ * @example
1419
+ * createCanvas(200);
1420
+ *
1421
+ * // (r, g, b, a)
1422
+ * let c = color(0, 255, 255, 50);
1423
+ *
1424
+ * function draw() {
1425
+ * fill(c);
1426
+ * circle(mouseX, mouseY, 50);
1427
+ * }
1428
+ */
1429
+ function color(c0: string | number | Color | number[], c1?: number, c2?: number, c3?: number): Color;
1430
+
1431
+ /** 🎨
1432
+ * Sets the color mode for the sketch, which changes how colors are
1433
+ * interpreted and displayed.
1434
+ *
1435
+ * The default color mode is RGB in legacy integer format.
1436
+ *
1437
+ * In WebGPU, the default is RGB in float format (best performance).
1438
+ *
1439
+ * Color gamut is 'display-p3' by default, if the device supports HDR.
1440
+ * @param {'rgb' | 'oklch' | 'hsl' | 'hsb'} mode color mode
1441
+ * @param {1 | 255} format color format (1 for float, 255 for integer)
1442
+ * @param {'srgb' | 'display-p3'} [gamut] color gamut
1443
+ * @example
1444
+ * createCanvas(200);
1445
+ *
1446
+ * colorMode(RGB, 1);
1447
+ * fill(1, 0, 0);
1448
+ * rect(0, 0, 66, 200);
1449
+ * fill(0, 1, 0);
1450
+ * rect(66, 0, 67, 200);
1451
+ * fill(0, 0, 1);
1452
+ * rect(133, 0, 67, 200);
1453
+ * @example
1454
+ * createCanvas(200);
1455
+ *
1456
+ * colorMode(OKLCH);
1457
+ *
1458
+ * fill(0.25, 0.15, 0);
1459
+ * rect(0, 0, 100, 200);
1460
+ *
1461
+ * fill(0.75, 0.15, 0);
1462
+ * rect(100, 0, 100, 200);
1463
+ */
1464
+ function colorMode(mode: 'rgb' | 'oklch', format: 1 | 255, gamut: 'srgb' | 'display-p3'): void;
1465
+
1466
+ /** 🎨
1467
+ * RGB colors have components `r`/`red`, `g`/`green`, `b`/`blue`,
1468
+ * and `a`/`alpha`.
1469
+ *
1470
+ * By default when a canvas is using the HDR "display-p3" color space,
1471
+ * rgb colors are mapped to the full P3 gamut, even when they use the
1472
+ * legacy integer 0-255 format.
1473
+ * @example
1474
+ * createCanvas(200, 100);
1475
+ *
1476
+ * colorMode(RGB);
1477
+ *
1478
+ * background(255, 0, 0);
1479
+ */
1480
+ const RGB: 'rgb';
1481
+
1482
+ /** 🎨
1483
+ * OKLCH colors have components `l`/`lightness`, `c`/`chroma`,
1484
+ * `h`/`hue`, and `a`/`alpha`. It's more intuitive for humans
1485
+ * to work with color in these terms than RGB.
1486
+ *
1487
+ * OKLCH is perceptually uniform, meaning colors at the
1488
+ * same lightness and chroma (colorfulness) will appear to
1489
+ * have equal luminance, regardless of the hue.
1490
+ *
1491
+ * OKLCH can accurately represent all colors visible to the
1492
+ * human eye, unlike many other color spaces that are bounded
1493
+ * to a gamut. The maximum lightness and chroma values that
1494
+ * correspond to sRGB or P3 gamut limits vary depending on
1495
+ * the hue. Colors that are out of gamut will be clipped to
1496
+ * the nearest in-gamut color.
1497
+ *
1498
+ * Use the [OKLCH color picker](https://oklch.com) to find
1499
+ * in-gamut colors.
1500
+ *
1501
+ * - `lightness`: 0 to 1
1502
+ * - `chroma`: 0 to ~0.4
1503
+ * - `hue`: 0 to 360
1504
+ * - `alpha`: 0 to 1
1505
+ * @example
1506
+ * createCanvas(200, 100);
1507
+ *
1508
+ * colorMode(OKLCH);
1509
+ *
1510
+ * background(0.64, 0.3, 30);
1511
+ * @example
1512
+ * createCanvas(200);
1513
+ * colorMode(OKLCH);
1514
+ *
1515
+ * function draw() {
1516
+ * background(0.7, 0.16, frameCount % 360);
1517
+ * }
1518
+ */
1519
+ const OKLCH: 'oklch';
1520
+
1521
+ /** 🎨
1522
+ * HSL colors have components `h`/`hue`, `s`/`saturation`,
1523
+ * `l`/`lightness`, and `a`/`alpha`.
1524
+ *
1525
+ * HSL was created in the 1970s to approximate human perception
1526
+ * of color, trading accuracy for simpler computations. It's
1527
+ * not perceptually uniform, so colors with the same lightness
1528
+ * can appear darker or lighter, depending on their hue
1529
+ * and saturation. Yet, the lightness and saturation values that
1530
+ * correspond to gamut limits are always 100, regardless of the
1531
+ * hue. This can make HSL easier to work with than OKLCH.
1532
+ *
1533
+ * HSL colors are mapped to the full P3 gamut when
1534
+ * using the "display-p3" color space.
1535
+ *
1536
+ * - `hue`: 0 to 360
1537
+ * - `saturation`: 0 to 100
1538
+ * - `lightness`: 0 to 100
1539
+ * - `alpha`: 0 to 1
1540
+ * @example
1541
+ * createCanvas(200, 100);
1542
+ *
1543
+ * colorMode(HSL);
1544
+ *
1545
+ * background(0, 100, 50);
1546
+ * @example
1547
+ * createCanvas(200, 220);
1548
+ * noStroke();
1549
+ *
1550
+ * colorMode(HSL);
1551
+ * for (let h = 0; h < 360; h += 10) {
1552
+ * for (let l = 0; l <= 100; l += 10) {
1553
+ * fill(h, 100, l);
1554
+ * rect(h * (11 / 20), l * 2, 6, 20);
1555
+ * }
1556
+ * }
1557
+ */
1558
+ const HSL: 'hsl';
1559
+
1560
+ /** 🎨
1561
+ * HSB colors have components `h`/`hue`, `s`/`saturation`,
1562
+ * `b`/`brightness` (aka `v`/`value`), and `a`/`alpha`.
1563
+ *
1564
+ * HSB is similar to HSL, but instead of lightness
1565
+ * (black to white), it uses brightness (black to
1566
+ * full color). To produce white, set brightness
1567
+ * to 100 and saturation to 0.
1568
+ *
1569
+ * - `hue`: 0 to 360
1570
+ * - `saturation`: 0 to 100
1571
+ * - `brightness`: 0 to 100
1572
+ * - `alpha`: 0 to 1
1573
+ * @example
1574
+ * createCanvas(200, 100);
1575
+ *
1576
+ * colorMode(HSB);
1577
+ *
1578
+ * background(0, 100, 100);
1579
+ * @example
1580
+ * createCanvas(200, 220);
1581
+ * noStroke();
1582
+ *
1583
+ * colorMode(HSB);
1584
+ * for (let h = 0; h < 360; h += 10) {
1585
+ * for (let b = 0; b <= 100; b += 10) {
1586
+ * fill(h, 100, b);
1587
+ * rect(h * (11 / 20), b * 2, 6, 20);
1588
+ * }
1589
+ * }
1590
+ */
1591
+ const HSB: 'hsb';
1592
+
1593
+ /** 🎨
1594
+ * Limits the color gamut to the sRGB color space.
1595
+ *
1596
+ * If your display is HDR capable, note that full red appears
1597
+ * less saturated and darker in this example, as it would on
1598
+ * an SDR display.
1599
+ * @example
1600
+ * createCanvas(200, 100);
1601
+ *
1602
+ * colorMode(RGB, 255, SRGB);
1603
+ *
1604
+ * background(255, 0, 0);
1605
+ */
1606
+ const SRGB: 'srgb';
1607
+
1608
+ /** 🎨
1609
+ * Expands the color gamut to the P3 color space.
1610
+ *
1611
+ * This is the default color gamut on devices that support HDR.
1612
+ *
1613
+ * If your display is HDR capable, note that full red appears
1614
+ * fully saturated and bright in the following example.
1615
+ * @example
1616
+ * createCanvas(200, 100);
1617
+ *
1618
+ * colorMode(RGB, 255, DISPLAY_P3);
1619
+ *
1620
+ * background(255, 0, 0);
1621
+ */
1622
+ const DISPLAY_P3: 'display-p3';
1623
+
1624
+ /** 🎨
1625
+ * Draws over the entire canvas with a color or image.
1626
+ *
1627
+ * Like the [`color`](https://q5js.org/learn/#color) function,
1628
+ * this function can accept colors in a wide range of formats:
1629
+ * CSS color string, grayscale value, and color component values.
1630
+ * @param {Color | Q5.Image} filler a color or image to draw
1631
+ * @example
1632
+ * createCanvas(200, 100);
1633
+ * background('crimson');
1634
+ * @example
1635
+ * function draw() {
1636
+ * background(128, 32);
1637
+ * circle(mouseX, mouseY, 20);
1638
+ * }
1639
+ */
1640
+ function background(filler: Color | Q5.Image): void;
1641
+
1642
+ class Color {
1643
+
1644
+ /** 🎨
1645
+ * This constructor strictly accepts 4 numbers, which are the color
1646
+ * components.
1647
+ *
1648
+ * Use the `color` function for greater flexibility, it runs
1649
+ * this constructor internally.
1650
+ *
1651
+ * `Color` is not actually a class itself, it's a reference to a
1652
+ * Q5 color class based on the color mode, format, and gamut.
1653
+ */
1654
+ constructor(c0: number, c1: number, c2: number, c3: number);
1655
+
1656
+ /** 🎨
1657
+ * Checks if this color is exactly equal to another color.
1658
+ */
1659
+ equals(other: Color): boolean;
1660
+
1661
+ /** 🎨
1662
+ * Checks if the color is the same as another color,
1663
+ * disregarding their alpha values.
1664
+ */
1665
+ isSameColor(other: Color): boolean;
1666
+
1667
+ /** 🎨
1668
+ * Produces a CSS color string representation.
1669
+ */
1670
+ toString(): string;
1671
+
1672
+ /** 🎨
1673
+ * An array of the color's components.
1674
+ */
1675
+ levels: number[];
1676
+ }
1677
+
1678
+ // 💅 styles
1679
+
1680
+ /** 💅
1681
+ * Sets the fill color. The default is white.
1682
+ *
1683
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
1684
+ * can accept colors in a wide range of formats: as a CSS color string,
1685
+ * a `Color` object, grayscale value, or color component values.
1686
+ * @param {Color} color fill color
1687
+ * @example
1688
+ * createCanvas(200);
1689
+ * background(200);
1690
+ *
1691
+ * fill('red');
1692
+ * circle(80, 80, 80);
1693
+ *
1694
+ * fill('lime');
1695
+ * square(80, 80, 80);
1696
+ */
1697
+ function fill(color: Color): void;
1698
+
1699
+ /** 💅
1700
+ * Sets the stroke (outline) color. The default is black.
1701
+ *
1702
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
1703
+ * can accept colors in a wide range of formats: as a CSS color string,
1704
+ * a `Color` object, grayscale value, or color component values.
1705
+ * @param {Color} color stroke color
1706
+ * @example
1707
+ * createCanvas(200);
1708
+ * background(200);
1709
+ * fill(36);
1710
+ *
1711
+ * stroke('red');
1712
+ * circle(80, 80, 80);
1713
+ *
1714
+ * stroke('lime');
1715
+ * square(80, 80, 80);
1716
+ */
1717
+ function stroke(color: Color): void;
1718
+
1719
+ /** 💅
1720
+ * After calling this function, drawing will not be filled.
1721
+ * @example
1722
+ * createCanvas(200);
1723
+ * background(200);
1724
+ *
1725
+ * noFill();
1726
+ *
1727
+ * stroke('red');
1728
+ * circle(80, 80, 80);
1729
+ * stroke('lime');
1730
+ * square(80, 80, 80);
1731
+ */
1732
+ function noFill(): void;
1733
+
1734
+ /** 💅
1735
+ * After calling this function, drawing will not have a stroke (outline).
1736
+ * @example
1737
+ * createCanvas(200);
1738
+ * background(200);
1739
+ * fill(36);
1740
+ * stroke('red');
1741
+ * circle(80, 80, 80);
1742
+ *
1743
+ * noStroke();
1744
+ * square(80, 80, 80);
1745
+ */
1746
+ function noStroke(): void;
1747
+
1748
+ /** 💅
1749
+ * Sets the size of the stroke used for lines and the border around drawings.
1750
+ * @param {number} weight size of the stroke in pixels
1751
+ * @example
1752
+ * createCanvas(200);
1753
+ * background(200);
1754
+ * stroke('red');
1755
+ * circle(50, 100, 80);
1756
+ *
1757
+ * strokeWeight(12);
1758
+ * circle(150, 100, 80);
1759
+ */
1760
+ function strokeWeight(weight: number): void;
1761
+
1762
+ /** 💅
1763
+ * Sets the global opacity, which affects all subsequent drawing operations, except `background`. Default is 1, fully opaque.
1764
+ *
1765
+ * In q5 WebGPU this function only affects images.
1766
+ * @param {number} alpha opacity level, ranging from 0 to 1
1767
+ * @example
1768
+ * createCanvas(200);
1769
+ * background(200);
1770
+ *
1771
+ * opacity(1);
1772
+ * circle(80, 80, 80);
1773
+ *
1774
+ * opacity(0.2);
1775
+ * square(80, 80, 80);
1776
+ */
1777
+ function opacity(alpha: number): void;
1778
+
1779
+ /** 💅
1780
+ * Sets the shadow color. The default is transparent (no shadow).
1781
+ *
1782
+ * Shadows apply to anything drawn to the canvas, including filled
1783
+ * shapes, strokes, text, and images.
1784
+ *
1785
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
1786
+ * can accept colors in a wide range of formats: as a CSS color string,
1787
+ * a `Color` object, grayscale value, or color component values.
1788
+ *
1789
+ * Not available in q5 WebGPU.
1790
+ * @param {Color} color shadow color
1791
+ * @example
1792
+ * createCanvas(200);
1793
+ * background(200);
1794
+ *
1795
+ * noFill();
1796
+ * shadow('black');
1797
+ * rect(64, 60, 80, 80);
1798
+ * @example
1799
+ * createCanvas(200);
1800
+ * let logo = loadImage('/assets/p5play_logo.webp');
1801
+ *
1802
+ * function setup() {
1803
+ * background(200);
1804
+ * shadow(0);
1805
+ * image(logo, 36, 36, 128, 128);
1806
+ * }
1807
+ */
1808
+ function shadow(color: string | Color): void;
1809
+
1810
+ /** 💅
1811
+ * Disables the shadow effect.
1812
+ *
1813
+ * Not available in q5 WebGPU.
1814
+ * @example
1815
+ * createCanvas(200);
1816
+ * background(200);
1817
+ * noStroke();
1818
+ * shadow('black');
1819
+ * rect(14, 14, 80, 80);
1820
+ *
1821
+ * noShadow();
1822
+ * rect(104, 104, 80, 80);
1823
+ */
1824
+ function noShadow(): void;
1825
+
1826
+ /** 💅
1827
+ * Sets the shadow offset and blur radius.
1828
+ *
1829
+ * When q5 starts, shadow offset is (10, 10) with a blur of 10.
1830
+ *
1831
+ * Not available in q5 WebGPU.
1832
+ * @param {number} offsetX horizontal offset of the shadow
1833
+ * @param {number} offsetY vertical offset of the shadow, defaults to be the same as offsetX
1834
+ * @param {number} blur blur radius of the shadow, defaults to 0
1835
+ * @example
1836
+ * createCanvas(200);
1837
+ * noStroke();
1838
+ * shadow(50);
1839
+ *
1840
+ * function draw() {
1841
+ * background(200);
1842
+ * shadowBox(-20, mouseY, 10);
1843
+ * circle(100, 100, 80, 80);
1844
+ * }
1845
+ * @example
1846
+ * createCanvas(200);
1847
+ * background(200);
1848
+ * noStroke();
1849
+ *
1850
+ * shadow('aqua');
1851
+ * shadowBox(20);
1852
+ * rect(50, 50, 100, 100);
1853
+ * textSize(64);
1854
+ * text('q5', 60, 115);
1855
+ */
1856
+ function shadowBox(offsetX: number, offsetY: number, blur: number): void;
1857
+
1858
+ /** 💅
1859
+ * Set the global composite operation for the canvas context.
1860
+ *
1861
+ * Not available in q5 WebGPU.
1862
+ * @param {string} val composite operation
1863
+ */
1864
+ function blendMode(val: string): void;
1865
+
1866
+ /** 💅
1867
+ * Set the line cap style to `ROUND`, `SQUARE`, or `PROJECT`.
1868
+ *
1869
+ * Not available in q5 WebGPU.
1870
+ * @param {CanvasLineCap} val line cap style
1871
+ * @example
1872
+ * createCanvas(200);
1873
+ * background(200);
1874
+ * strokeWeight(20);
1875
+ *
1876
+ * strokeCap(ROUND);
1877
+ * line(50, 50, 150, 50);
1878
+ *
1879
+ * strokeCap(SQUARE);
1880
+ * line(50, 100, 150, 100);
1881
+ *
1882
+ * strokeCap(PROJECT);
1883
+ * line(50, 150, 150, 150);
1884
+ */
1885
+ function strokeCap(val: CanvasLineCap): void;
1886
+
1887
+ /** 💅
1888
+ * Set the line join style to `ROUND`, `BEVEL`, or `MITER`.
1889
+ *
1890
+ * Not available in q5 WebGPU.
1891
+ * @param {CanvasLineJoin} val line join style
1892
+ * @example
1893
+ * createCanvas(200);
1894
+ * background(200);
1895
+ * strokeWeight(10);
1896
+ *
1897
+ * strokeJoin(ROUND);
1898
+ * triangle(50, 20, 150, 20, 50, 70);
1899
+ *
1900
+ * strokeJoin(BEVEL);
1901
+ * triangle(150, 50, 50, 100, 150, 150);
1902
+ *
1903
+ * strokeJoin(MITER);
1904
+ * triangle(50, 130, 150, 180, 50, 180);
1905
+ */
1906
+ function strokeJoin(val: CanvasLineJoin): void;
1907
+
1908
+ /** 💅
1909
+ * Sets the canvas to erase mode, where shapes will erase what's
1910
+ * underneath them instead of drawing over it.
1911
+ *
1912
+ * Not available in q5 WebGPU.
1913
+ * @param {number} [fillAlpha] opacity level of the fill color
1914
+ * @param {number} [strokeAlpha] opacity level of the stroke color
1915
+ */
1916
+ function erase(fillAlpha?: number, strokeAlpha?: number): void;
1917
+
1918
+ /** 💅
1919
+ * Resets the canvas from erase mode to normal drawing mode.
1920
+ *
1921
+ * Not available in q5 WebGPU.
1922
+ */
1923
+ function noErase(): void;
1924
+
1925
+ /** 💅
1926
+ * Saves the current drawing style settings.
1927
+ *
1928
+ * This includes the fill, stroke, stroke weight, tint, image mode,
1929
+ * rect mode, ellipse mode, text size, text align, text baseline, and
1930
+ * shadow settings.
1931
+ * @example
1932
+ * createCanvas(200);
1933
+ * background(200);
1934
+ *
1935
+ * pushStyles();
1936
+ * fill('blue');
1937
+ * circle(50, 50, 80);
1938
+ *
1939
+ * popStyles();
1940
+ * circle(150, 150, 80);
1941
+ */
1942
+ function pushStyles(): void;
1943
+
1944
+ /** 💅
1945
+ * Restores the previously saved drawing style settings.
1946
+ * @example
1947
+ * createCanvas(200);
1948
+ * background(200);
1949
+ *
1950
+ * pushStyles();
1951
+ * fill('blue');
1952
+ * circle(50, 50, 80);
1953
+ *
1954
+ * popStyles();
1955
+ * circle(150, 150, 80);
1956
+ */
1957
+ function popStyles(): void;
1958
+
1959
+ /** 💅
1960
+ * Clears the canvas, making every pixel completely transparent.
1961
+ *
1962
+ * Note that the canvas can only be seen through if it has an alpha channel.
1963
+ *
1964
+ * #### webgpu
1965
+ * @example
1966
+ * await createCanvas(200, { alpha: true });
1967
+ *
1968
+ * q5.draw = function () {
1969
+ * clear();
1970
+ * circle((frameCount % 200) - 100, 0, 80);
1971
+ * };
1972
+ * @example
1973
+ * createCanvas(200, 200, { alpha: true });
1974
+ *
1975
+ * function draw() {
1976
+ * clear();
1977
+ * circle(frameCount % 200, 100, 80);
1978
+ * }
1979
+ */
1980
+ function clear(): void;
1981
+
1982
+ /** 💅
1983
+ * Checks if a given point is within the current path's fill area.
1984
+ *
1985
+ * Not available in q5 WebGPU.
1986
+ * @param {number} x x-coordinate of the point
1987
+ * @param {number} y y-coordinate of the point
1988
+ * @returns {boolean} true if the point is within the fill area, false otherwise
1989
+ */
1990
+ function inFill(x: number, y: number): boolean;
1991
+
1992
+ /** 💅
1993
+ * Checks if a given point is within the current path's stroke.
1994
+ *
1995
+ * Not available in q5 WebGPU.
1996
+ * @param {number} x x-coordinate of the point
1997
+ * @param {number} y y-coordinate of the point
1998
+ * @returns {boolean} true if the point is within the stroke, false otherwise
1999
+ */
2000
+ function inStroke(x: number, y: number): boolean;
2001
+
2002
+ // 🦋 transforms
2003
+
2004
+ /** 🦋
2005
+ * Translates the origin of the drawing context.
2006
+ * @param {number} x translation along the x-axis
2007
+ * @param {number} y translation along the y-axis
2008
+ * @example
2009
+ * function draw() {
2010
+ * background(200);
2011
+ *
2012
+ * translate(150, 150);
2013
+ * circle(0, 0, 80);
2014
+ * }
2015
+ */
2016
+ function translate(x: number, y: number): void;
2017
+
2018
+ /** 🦋
2019
+ * Rotates the drawing context.
2020
+ * @param {number} angle rotation angle in radians
2021
+ * @example
2022
+ * function draw() {
2023
+ * background(200);
2024
+ *
2025
+ * translate(100, 100);
2026
+ * rotate(mouseX / 50);
2027
+ *
2028
+ * rectMode(CENTER);
2029
+ * square(0, 0, 50);
2030
+ * }
2031
+ */
2032
+ function rotate(angle: number): void;
2033
+
2034
+ /** 🦋
2035
+ * Scales the drawing context.
2036
+ *
2037
+ * If only one input parameter is provided,
2038
+ * the drawing context will be scaled uniformly.
2039
+ * @param {number} x scaling factor along the x-axis
2040
+ * @param {number} [y] scaling factor along the y-axis
2041
+ * @example
2042
+ * function draw() {
2043
+ * background(200);
2044
+ *
2045
+ * scale(mouseX / 10);
2046
+ * circle(0, 0, 20);
2047
+ * }
2048
+ */
2049
+ function scale(x: number, y?: number): void;
2050
+
2051
+ /** 🦋
2052
+ * Shears the drawing context along the x-axis.
2053
+ * @param {number} angle shear angle in radians
2054
+ * @example
2055
+ * function draw() {
2056
+ * background(200);
2057
+ *
2058
+ * translate(25, 60);
2059
+ * shearX(mouseX / 100);
2060
+ * square(0, 0, 80);
2061
+ * }
2062
+ */
2063
+ function shearX(angle: number): void;
2064
+
2065
+ /** 🦋
2066
+ * Shears the drawing context along the y-axis.
2067
+ * @param {number} angle shear angle in radians
2068
+ * @example
2069
+ * function draw() {
2070
+ * background(200);
2071
+ *
2072
+ * translate(25, 60);
2073
+ * shearY(mouseX / 100);
2074
+ * square(0, 0, 80);
2075
+ * }
2076
+ */
2077
+ function shearY(angle: number): void;
2078
+
2079
+ /** 🦋
2080
+ * Applies a transformation matrix.
2081
+ *
2082
+ * Accepts a 3x3 or 4x4 matrix as either an array or multiple arguments.
2083
+ *
2084
+ * Note that in q5 WebGPU, the identity matrix (default)
2085
+ * has a negative y scale to flip the y-axis to match
2086
+ * the Canvas2D renderer.
2087
+ * @param {number} a
2088
+ * @param {number} b
2089
+ * @param {number} c
2090
+ * @param {number} d
2091
+ * @param {number} e
2092
+ * @param {number} f
2093
+ * @example
2094
+ * function draw() {
2095
+ * background(200);
2096
+ *
2097
+ * applyMatrix(2, 1, 1, 1, 100, 100);
2098
+ * circle(0, 0, 80);
2099
+ * }
2100
+ */
2101
+ function applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number): void;
2102
+
2103
+ /** 🦋
2104
+ * Resets the transformation matrix.
2105
+ *
2106
+ * q5 runs this function before every time the `draw` function is run,
2107
+ * so that transformations don't carry over to the next frame.
2108
+ * @example
2109
+ * createCanvas(200);
2110
+ * background(200);
2111
+ *
2112
+ * translate(100, 100);
2113
+ * circle(0, 0, 80);
2114
+ *
2115
+ * resetMatrix();
2116
+ * square(0, 0, 50);
2117
+ */
2118
+ function resetMatrix(): void;
2119
+
2120
+ /** 🦋
2121
+ * Saves the current transformation matrix.
2122
+ * @example
2123
+ * createCanvas(200);
2124
+ * background(200);
2125
+ * translate(100, 100);
2126
+ *
2127
+ * pushMatrix();
2128
+ * rotate(QUARTER_PI);
2129
+ * ellipse(0, 0, 120, 40);
2130
+ * popMatrix();
2131
+ *
2132
+ * ellipse(0, 0, 120, 40);
2133
+ */
2134
+ function pushMatrix(): void;
2135
+
2136
+ /** 🦋
2137
+ * Restores the previously saved transformation matrix.
2138
+ * @example
2139
+ * createCanvas(200);
2140
+ * background(200);
2141
+ * translate(100, 100);
2142
+ *
2143
+ * pushMatrix();
2144
+ * rotate(QUARTER_PI);
2145
+ * ellipse(0, 0, 120, 40);
2146
+ * popMatrix();
2147
+ *
2148
+ * ellipse(0, 0, 120, 40);
2149
+ */
2150
+ function popMatrix(): void;
2151
+
2152
+ /** 🦋
2153
+ * Saves the current drawing style settings and transformations.
2154
+ * @example
2155
+ * createCanvas(200);
2156
+ *
2157
+ * push();
2158
+ * fill('blue');
2159
+ * translate(100, 100);
2160
+ * circle(0, 0, 80);
2161
+ * pop();
2162
+ *
2163
+ * square(0, 0, 50);
2164
+ */
2165
+ function push(): void;
2166
+
2167
+ /** 🦋
2168
+ * Restores the previously saved drawing style settings and transformations.
2169
+ * @example
2170
+ * createCanvas(200);
2171
+ *
2172
+ * push();
2173
+ * fill('blue');
2174
+ * translate(100, 100);
2175
+ * circle(0, 0, 80);
2176
+ * pop();
2177
+ *
2178
+ * square(0, 0, 50);
2179
+ */
2180
+ function pop(): void;
2181
+
2182
+ // 💻 display
2183
+
2184
+ /** 💻
2185
+ * Customize how your canvas is presented.
2186
+ * @param {string} mode NORMAL, CENTER, or MAXED
2187
+ * @param {string} renderQuality SMOOTH or PIXELATED
2188
+ * @param {number} scale can also be given as a string (for example "x2")
2189
+ * @example
2190
+ * createCanvas(50, 25);
2191
+ *
2192
+ * displayMode(CENTER, PIXELATED, 4);
2193
+ *
2194
+ * circle(25, 12.5, 16);
2195
+ */
2196
+ function displayMode(mode: string, renderQuality: string, scale: string | number): void;
2197
+
2198
+ /** 💻
2199
+ * A `displayMode` setting.
2200
+ *
2201
+ * The canvas will be scaled to fill the parent element,
2202
+ * with letterboxing if necessary to preserve its aspect ratio.
2203
+ */
2204
+ const MAXED: 'maxed';
2205
+
2206
+ /** 💻
2207
+ * A `displayMode` render quality.
2208
+ *
2209
+ * Smooth upscaling is used if the canvas is scaled.
2210
+ */
2211
+ const SMOOTH: 'smooth';
2212
+
2213
+ /** 💻
2214
+ * A `displayMode` render quality.
2215
+ *
2216
+ * Pixels are rendered as sharp squares if the canvas is scaled.
2217
+ */
2218
+ const PIXELATED: 'pixelated';
2219
+
2220
+ /** 💻
2221
+ * Enables or disables fullscreen mode.
2222
+ * @param {boolean} [v] boolean indicating whether to enable or disable fullscreen mode
2223
+ */
2224
+ function fullscreen(v?: boolean): void;
2225
+
2226
+ /** 💻
2227
+ * The width of the window.
2228
+ * @example
2229
+ * function draw() {
2230
+ * background(200);
2231
+ * textSize(64);
2232
+ * textAlign(CENTER, CENTER);
2233
+ * text(windowWidth, 100, 100);
2234
+ * }
2235
+ */
2236
+ var windowWidth: number;
2237
+
2238
+ /** 💻
2239
+ * The height of the window.
2240
+ * @example
2241
+ * function draw() {
2242
+ * background(200);
2243
+ * textSize(64);
2244
+ * textAlign(CENTER, CENTER);
2245
+ * text(windowHeight, 100, 100);
2246
+ * }
2247
+ */
2248
+ var windowHeight: number;
2249
+
2250
+ /** 💻
2251
+ * The width of the canvas.
2252
+ */
2253
+ var width: number;
2254
+
2255
+ /** 💻
2256
+ * The height of the canvas.
2257
+ */
2258
+ var height: number;
2259
+
2260
+ /** 💻
2261
+ * Half the width of the canvas.
2262
+ */
2263
+ var halfWidth: number;
2264
+
2265
+ /** 💻
2266
+ * Half the height of the canvas.
2267
+ */
2268
+ var halfHeight: number;
2269
+
2270
+ /** 💻
2271
+ * The canvas element associated with the Q5 instance.
2272
+ *
2273
+ * If a canvas is not explicitly created with `createCanvas()`, but a q5 function like `draw` or `mousePressed` is defined, a default canvas of size 200x200 will be created automatically.
2274
+ */
2275
+ var canvas: HTMLCanvasElement;
2276
+
2277
+ /** 💻
2278
+ * Resizes the canvas to the specified width and height.
2279
+ * @param {number} w width of the canvas
2280
+ * @param {number} h height of the canvas
2281
+ * @example
2282
+ * createCanvas(200, 100);
2283
+ *
2284
+ * function draw() {
2285
+ * background(200);
2286
+ * }
2287
+ *
2288
+ * function mousePressed() {
2289
+ * resizeCanvas(200, 200);
2290
+ * }
2291
+ */
2292
+ function resizeCanvas(w: number, h: number): void;
2293
+
2294
+ /** 💻
2295
+ * The number of frames that have been displayed since the program started.
2296
+ * @example
2297
+ * function draw() {
2298
+ * background(200);
2299
+ * textSize(64);
2300
+ * text(frameCount, 8, 120);
2301
+ * }
2302
+ */
2303
+ var frameCount: number;
2304
+
2305
+ /** 💻
2306
+ * Stops the draw loop.
2307
+ * @example
2308
+ * function draw() {
2309
+ * circle(frameCount * 5, 100, 80);
2310
+ * noLoop();
2311
+ * }
2312
+ */
2313
+ function noLoop(): void;
2314
+
2315
+ /** 💻
2316
+ * Redraws the canvas n times. If no input parameter is provided,
2317
+ * it calls the draw function once.
2318
+ *
2319
+ * This is an async function.
2320
+ * @param {number} [n] number of times to redraw the canvas, default is 1
2321
+ * @example
2322
+ * createCanvas(200);
2323
+ * noLoop();
2324
+ *
2325
+ * function draw() {
2326
+ * circle(frameCount * 5, 100, 80);
2327
+ * }
2328
+ * function mousePressed() {
2329
+ * redraw(10);
2330
+ * }
2331
+ */
2332
+ function redraw(n?: number): void;
2333
+
2334
+ /** 💻
2335
+ * Starts the draw loop again if it was stopped.
2336
+ * @example
2337
+ * createCanvas(200);
2338
+ * noLoop();
2339
+ *
2340
+ * function draw() {
2341
+ * circle(frameCount * 5, 100, 80);
2342
+ * }
2343
+ * function mousePressed() {
2344
+ * loop();
2345
+ * }
2346
+ */
2347
+ function loop(): void;
2348
+
2349
+ /** 💻
2350
+ * Sets the target frame rate or gets an approximation of the
2351
+ * sketch's current frame rate.
2352
+ *
2353
+ * Even when the sketch is running at a consistent frame rate,
2354
+ * the current frame rate value will fluctuate. Use your web browser's
2355
+ * developer tools for more accurate performance analysis.
2356
+ * @param {number} [hertz] target frame rate, default is 60
2357
+ * @returns {number} current frame rate
2358
+ * @example
2359
+ * function draw() {
2360
+ * background(200);
2361
+ *
2362
+ * if (mouseIsPressed) frameRate(10);
2363
+ * else frameRate(60);
2364
+ *
2365
+ * circle(frameCount % 200, 100, 80);
2366
+ * }
2367
+ * @example
2368
+ * function draw() {
2369
+ * background(200);
2370
+ * textSize(64);
2371
+ * text(round(frameRate()), 65, 120);
2372
+ * }
2373
+ */
2374
+ function frameRate(hertz?: number): number;
2375
+
2376
+ /** 💻
2377
+ * The desired frame rate of the sketch.
2378
+ * @returns {number} target frame rate
2379
+ * @example
2380
+ * function draw() {
2381
+ * background(200);
2382
+ * textSize(64);
2383
+ *
2384
+ * text(getTargetFrameRate(), 65, 120);
2385
+ * }
2386
+ */
2387
+ function getTargetFrameRate(): number;
2388
+
2389
+ /** 💻
2390
+ * Gets the current FPS, in terms of how many frames could be generated
2391
+ * in one second, which can be higher than the target frame rate.
2392
+ *
2393
+ * Use your web browser's developer tools for more in-depth
2394
+ * performance analysis.
2395
+ * @returns {number} frames per second
2396
+ * @example
2397
+ * function draw() {
2398
+ * background(200);
2399
+ * frameRate(1);
2400
+ * textSize(64);
2401
+ *
2402
+ * text(getFPS(), 8, 120);
2403
+ * }
2404
+ */
2405
+ function getFPS(): number;
2406
+
2407
+ /** 💻
2408
+ * Runs after each `draw` function call and post-draw q5 addon processes, if any.
2409
+ *
2410
+ * Useful for adding post-processing effects when it's not possible
2411
+ * to do so at the end of the `draw` function, such as when using
2412
+ * addons like p5play that auto-draw to the canvas after the `draw`
2413
+ * function is run.
2414
+ * @example
2415
+ * function draw() {
2416
+ * background(200);
2417
+ * circle(frameCount % 200, 100, 80);
2418
+ * }
2419
+ *
2420
+ * function postProcess() {
2421
+ * filter(INVERT);
2422
+ * }
2423
+ */
2424
+ function postProcess(): void;
2425
+
2426
+ /** 💻
2427
+ * Sets the pixel density of the canvas.
2428
+ * @param {number} v pixel density value
2429
+ * @returns {number} pixel density
2430
+ * @example
2431
+ * createCanvas(200, 100);
2432
+ * background(200);
2433
+ * pixelDensity(1);
2434
+ * circle(100, 50, 80);
2435
+ */
2436
+ function pixelDensity(v: number): number;
2437
+
2438
+ /** 💻
2439
+ * Returns the current display density.
2440
+ *
2441
+ * On most modern displays, this value will be 2 or 3.
2442
+ * @returns {number} display density
2443
+ * @example
2444
+ * createCanvas(200, 100);
2445
+ * background(200);
2446
+ * textSize(64);
2447
+ * text(displayDensity(), 10, 20);
2448
+ */
2449
+ function displayDensity(): number;
2450
+
2451
+ /** 💻
2452
+ * The time passed since the last frame was drawn.
2453
+ *
2454
+ * With the default frame rate of 60, delta time will be
2455
+ * approximately 16.6
2456
+ *
2457
+ * Can be used to keep movements tied to real time if the sketch
2458
+ * is often dropping below the target frame rate. Although if frame
2459
+ * rates are consistently low, consider reducing the target frame
2460
+ * rate instead.
2461
+ * @example
2462
+ * function draw() {
2463
+ * background(200);
2464
+ * text(deltaTime, 60, 106);
2465
+ * }
2466
+ * @example
2467
+ * let x = 0;
2468
+ * function draw() {
2469
+ * background(200);
2470
+ * // simulate frame rate drops
2471
+ * frameRate(random(30, 60));
2472
+ *
2473
+ * x += deltaTime * 0.2;
2474
+ * circle(x % 200, 100, 20);
2475
+ * }
2476
+ */
2477
+ var deltaTime: number;
2478
+
2479
+ /** 💻
2480
+ * The 2D rendering context for the canvas, if using the Canvas2D
2481
+ * renderer.
2482
+ */
2483
+ var ctx: CanvasRenderingContext2D;
2484
+
2485
+ var drawingContext: CanvasRenderingContext2D;
2486
+
2487
+ // 🧮 math
2488
+
2489
+ /** 🧮
2490
+ * Generates a random value.
2491
+ *
2492
+ * - If no inputs are provided, returns a number between 0 and 1.
2493
+ * - If one numerical input is provided, returns a number between 0 and the provided value.
2494
+ * - If two numerical inputs are provided, returns a number between the two values.
2495
+ * - If an array is provided, returns a random element from the array.
2496
+ * @param {number | any[]} [low] lower bound (inclusive) or an array
2497
+ * @param {number} [high] upper bound (exclusive)
2498
+ * @returns {number | any} a random number or element
2499
+ * @example
2500
+ * createCanvas(200);
2501
+ * background(200);
2502
+ * frameRate(5);
2503
+ *
2504
+ * function draw() {
2505
+ * circle(100, 100, random(20, 200));
2506
+ * }
2507
+ * @example
2508
+ * function draw() {
2509
+ * circle(random(200), random(200), 10);
2510
+ * }
2511
+ */
2512
+ function random(low?: number | any[], high?: number): number | any;
2513
+
2514
+ /** 🧮
2515
+ * Generates a random number within a symmetric range around zero.
2516
+ *
2517
+ * Can be used to create a jitter effect (random displacement).
2518
+ *
2519
+ * Equivalent to `random(-amount, amount)`.
2520
+ * @param {number} amount absolute maximum amount of jitter, default is 1
2521
+ * @returns {number} random number between -val and val
2522
+ * @example
2523
+ * function draw() {
2524
+ * circle(mouseX + jit(3), mouseY + jit(3), 5);
2525
+ * }
2526
+ * @example
2527
+ * let q = await Q5.WebGPU();
2528
+ * createCanvas(200, 100);
2529
+ *
2530
+ * q.draw = () => {
2531
+ * circle(jit(50), 0, random(50));
2532
+ * };
2533
+ */
2534
+ function jit(amount: number): number;
2535
+
2536
+ /** 🧮
2537
+ * Generates a noise value based on the x, y, and z inputs.
2538
+ *
2539
+ * Uses [Perlin Noise](https://en.wikipedia.org/wiki/Perlin_noise) by default.
2540
+ * @param {number} [x] x-coordinate input
2541
+ * @param {number} [y] y-coordinate input
2542
+ * @param {number} [z] z-coordinate input
2543
+ * @returns {number} a noise value
2544
+ * @example
2545
+ * function draw() {
2546
+ * background(200);
2547
+ * let n = noise(frameCount * 0.01);
2548
+ * circle(100, 100, n * 200);
2549
+ * }
2550
+ * @example
2551
+ * function draw() {
2552
+ * background(200);
2553
+ * let t = (frameCount + mouseX) * 0.02;
2554
+ * for (let x = -5; x < 220; x += 10) {
2555
+ * let n = noise(t, x * 0.1);
2556
+ * circle(x, 100, n * 40);
2557
+ * }
2558
+ * }
2559
+ */
2560
+ function noise(x?: number, y?: number, z?: number): number;
2561
+
2562
+ /** 🧮
2563
+ * Calculates the distance between two points.
2564
+ *
2565
+ * This function also accepts two objects with `x` and `y` properties.
2566
+ * @param {number} x1 x-coordinate of the first point
2567
+ * @param {number} y1 y-coordinate of the first point
2568
+ * @param {number} x2 x-coordinate of the second point
2569
+ * @param {number} y2 y-coordinate of the second point
2570
+ * @returns {number} distance between the points
2571
+ * @example
2572
+ * function draw() {
2573
+ * background(200);
2574
+ * circle(100, 100, 20);
2575
+ * circle(mouseX, mouseY, 20);
2576
+ *
2577
+ * let d = dist(100, 100, mouseX, mouseY);
2578
+ * text(round(d), 20, 20);
2579
+ * }
2580
+ */
2581
+ function dist(x1: number, y1: number, x2: number, y2: number): number;
2582
+
2583
+ /** 🧮
2584
+ * Maps a number from one range to another.
2585
+ * @param {number} val incoming value to be converted
2586
+ * @param {number} start1 lower bound of the value's current range
2587
+ * @param {number} stop1 upper bound of the value's current range
2588
+ * @param {number} start2 lower bound of the value's target range
2589
+ * @param {number} stop2 upper bound of the value's target range
2590
+ * @returns {number} mapped value
2591
+ */
2592
+ function map(val: number, start1: number, stop1: number, start2: number, stop2: number): number;
2593
+
2594
+ /** 🧮
2595
+ * Sets the mode for interpreting and drawing angles. Can be either 'degrees' or 'radians'.
2596
+ * @param {'degrees' | 'radians'} mode mode to set for angle interpretation
2597
+ */
2598
+ function angleMode(mode: 'degrees' | 'radians'): void;
2599
+
2600
+ /** 🧮
2601
+ * Converts degrees to radians.
2602
+ * @param {number} degrees angle in degrees
2603
+ * @returns {number} angle in radians
2604
+ */
2605
+ function radians(degrees: number): number;
2606
+
2607
+ /** 🧮
2608
+ * Converts radians to degrees.
2609
+ * @param {number} radians angle in radians
2610
+ * @returns {number} angle in degrees
2611
+ */
2612
+ function degrees(radians: number): number;
2613
+
2614
+ /** 🧮
2615
+ * Calculates a number between two numbers at a specific increment.
2616
+ * @param {number} start first number
2617
+ * @param {number} stop second number
2618
+ * @param {number} amt amount to interpolate between the two values
2619
+ * @returns {number} interpolated number
2620
+ */
2621
+ function lerp(start: number, stop: number, amt: number): number;
2622
+
2623
+ /** 🧮
2624
+ * Constrains a value between a minimum and maximum value.
2625
+ * @param {number} n number to constrain
2626
+ * @param {number} low lower bound
2627
+ * @param {number} high upper bound
2628
+ * @returns {number} constrained value
2629
+ */
2630
+ function constrain(n: number, low: number, high: number): number;
2631
+
2632
+ /** 🧮
2633
+ * Normalizes a number from another range into a value between 0 and 1.
2634
+ * @param {number} n number to normalize
2635
+ * @param {number} start lower bound of the range
2636
+ * @param {number} stop upper bound of the range
2637
+ * @returns {number} normalized number
2638
+ */
2639
+ function norm(n: number, start: number, stop: number): number;
2640
+
2641
+ /** 🧮
2642
+ * Calculates the fractional part of a number.
2643
+ * @param {number} n a number
2644
+ * @returns {number} fractional part of the number
2645
+ */
2646
+ function fract(n: number): number;
2647
+
2648
+ /** 🧮
2649
+ * Calculates the absolute value of a number.
2650
+ * @param {number} n a number
2651
+ * @returns {number} absolute value of the number
2652
+ */
2653
+ function abs(n: number): number;
2654
+
2655
+ /** 🧮
2656
+ * Rounds a number.
2657
+ * @param {number} n number to round
2658
+ * @param {number} [d] number of decimal places to round to
2659
+ * @returns {number} rounded number
2660
+ * @example
2661
+ * createCanvas(200, 100);
2662
+ * background(200);
2663
+ * textSize(32);
2664
+ * text(round(PI, 5), 10, 60);
2665
+ */
2666
+ function round(n: number, d: number): number;
2667
+
2668
+ /** 🧮
2669
+ * Rounds a number up.
2670
+ * @param {number} n a number
2671
+ * @returns {number} rounded number
2672
+ * @example
2673
+ * createCanvas(200, 100);
2674
+ * background(200);
2675
+ * textSize(32);
2676
+ * text(ceil(PI), 10, 60);
2677
+ */
2678
+ function ceil(n: number): number;
2679
+
2680
+ /** 🧮
2681
+ * Rounds a number down.
2682
+ * @param {number} n a number
2683
+ * @returns {number} rounded number
2684
+ * @example
2685
+ * createCanvas(200, 100);
2686
+ * background(200);
2687
+ * textSize(32);
2688
+ * text(floor(-PI), 10, 60);
2689
+ */
2690
+ function floor(n: number): number;
2691
+
2692
+ /** 🧮
2693
+ * Returns the smallest value in a sequence of numbers.
2694
+ * @param {...number} args numbers to compare
2695
+ * @returns {number} minimum
2696
+ * @example
2697
+ * function draw() {
2698
+ * background(min(mouseX, 100));
2699
+ * circle(min(mouseX, 100), 0, 80);
2700
+ * }
2701
+ */
2702
+ function min(...args: number[]): number;
2703
+
2704
+ /** 🧮
2705
+ * Returns the largest value in a sequence of numbers.
2706
+ * @param {...number} args numbers to compare
2707
+ * @returns {number} maximum
2708
+ * @example
2709
+ * function draw() {
2710
+ * background(max(mouseX, 100));
2711
+ * circle(max(mouseX, 100), 0, 80);
2712
+ * }
2713
+ */
2714
+ function max(...args: number[]): number;
2715
+
2716
+ /** 🧮
2717
+ * Calculates the value of a base raised to a power.
2718
+ *
2719
+ * For example, `pow(2, 3)` calculates 2 _ 2 _ 2 which is 8.
2720
+ * @param {number} base base
2721
+ * @param {number} exponent exponent
2722
+ * @returns {number} base raised to the power of exponent
2723
+ */
2724
+ function pow(base: number, exponent: number): number;
2725
+
2726
+ /** 🧮
2727
+ * Calculates the square of a number.
2728
+ * @param {number} n number to square
2729
+ * @returns {number} square of the number
2730
+ */
2731
+ function sq(n: number): number;
2732
+
2733
+ /** 🧮
2734
+ * Calculates the square root of a number.
2735
+ * @param {number} n a number
2736
+ * @returns {number} square root of the number
2737
+ */
2738
+ function sqrt(n: number): number;
2739
+
2740
+ /** 🧮
2741
+ * Calculates the natural logarithm (base e) of a number.
2742
+ * @param {number} n a number
2743
+ * @returns {number} natural logarithm of the number
2744
+ */
2745
+ function loge(n: number): number;
2746
+
2747
+ /** 🧮
2748
+ * Calculates e raised to the power of a number.
2749
+ * @param {number} exponent power to raise e to
2750
+ * @returns {number} e raised to the power of exponent
2751
+ */
2752
+ function exp(exponent: number): number;
2753
+
2754
+ /** 🧮
2755
+ * Sets the seed for the random number generator.
2756
+ * @param {number} seed seed value
2757
+ */
2758
+ function randomSeed(seed: number): void;
2759
+
2760
+ /** 🧮
2761
+ * Sets the random number generation method.
2762
+ * @param {any} method method to use for random number generation
2763
+ */
2764
+ function randomGenerator(method: any): void;
2765
+
2766
+ /** 🧮
2767
+ * Generates a random number following a Gaussian (normal) distribution.
2768
+ * @param {number} mean mean (center) of the distribution
2769
+ * @param {number} std standard deviation (spread or "width") of the distribution
2770
+ * @returns {number} a random number following a Gaussian distribution
2771
+ */
2772
+ function randomGaussian(mean: number, std: number): number;
2773
+
2774
+ /** 🧮
2775
+ * Generates a random number following an exponential distribution.
2776
+ * @returns {number} a random number following an exponential distribution
2777
+ */
2778
+ function randomExponential(): number;
2779
+
2780
+ /** 🧮
2781
+ * Sets the noise generation mode.
2782
+ *
2783
+ * Only the default mode, "perlin", is included in q5.js. Use of the
2784
+ * other modes requires the q5-noiser module.
2785
+ * @param {'perlin' | 'simplex' | 'blocky'} mode noise generation mode
2786
+ */
2787
+ function noiseMode(mode: 'perlin' | 'simplex' | 'blocky'): void;
2788
+
2789
+ /** 🧮
2790
+ * Sets the seed value for noise generation.
2791
+ * @param {number} seed seed value
2792
+ */
2793
+ function noiseSeed(seed: number): void;
2794
+
2795
+ /** 🧮
2796
+ * Sets the level of detail for noise generation.
2797
+ * @param {number} lod level of detail (number of octaves)
2798
+ * @param {number} falloff falloff rate for each octave
2799
+ */
2800
+ function noiseDetail(lod: number, falloff: number): void;
2801
+
2802
+ /** 🧮
2803
+ * The ratio of a circle's circumference to its diameter.
2804
+ * Approximately 3.14159.
2805
+ */
2806
+ const PI: number;
2807
+
2808
+ /** 🧮
2809
+ * 2 \* PI.
2810
+ * Approximately 6.28319.
2811
+ */
2812
+ const TWO_PI: number;
2813
+
2814
+ /** 🧮
2815
+ * 2 \* PI.
2816
+ * Approximately 6.28319.
2817
+ */
2818
+ const TAU: number;
2819
+
2820
+ /** 🧮
2821
+ * Half of PI.
2822
+ * Approximately 1.5708.
2823
+ */
2824
+ const HALF_PI: number;
2825
+
2826
+ /** 🧮
2827
+ * A quarter of PI.
2828
+ * Approximately 0.7854.
2829
+ */
2830
+ const QUARTER_PI: number;
2831
+
2832
+ // 🔊 sound
2833
+
2834
+ /**
2835
+ * q5.js includes low latency sound playback and basic mixing powered
2836
+ * by WebAudio.
2837
+ *
2838
+ * For audio filtering, synthesis, and analysis, consider using
2839
+ * [p5.sound](https://p5js.org/reference/p5.sound/).
2840
+ */
2841
+
2842
+ /** 🔊
2843
+ * Loads audio data from a file and returns a `Q5.Sound` object.
2844
+ *
2845
+ * Use functions like `play`, `pause`, and `stop` to
2846
+ * control playback. Note that sounds can only be played after the
2847
+ * first user interaction with the page!
2848
+ *
2849
+ * Set `volume` to a value between 0 (silent) and 1 (full volume).
2850
+ * Set `pan` to a value between -1 (left) and 1 (right) to adjust
2851
+ * the sound's stereo position. Set `loop` to true to loop the sound.
2852
+ *
2853
+ * Use `loaded`, `paused`, and `ended` to check the sound's status.
2854
+ *
2855
+ * The entire sound file must be loaded before playback can start,
2856
+ * to stream larger audio files use the `loadAudio` function instead.
2857
+ *
2858
+ * For backwards compatibility with the p5.sound API, the functions
2859
+ * `setVolume`, `setLoop`, `setPan`, `isLoaded`, and `isPlaying`
2860
+ * are also implemented, but their use is deprecated.
2861
+ * @param {string} url sound file
2862
+ * @returns {Sound & PromiseLike<Sound>} a new `Sound` object
2863
+ * @example
2864
+ * createCanvas(200);
2865
+ *
2866
+ * let sound = loadSound('/assets/jump.wav');
2867
+ * sound.volume = 0.3;
2868
+ *
2869
+ * function mousePressed() {
2870
+ * sound.play();
2871
+ * }
2872
+ */
2873
+ function loadSound(url: string): Sound & PromiseLike<Sound>;
2874
+
2875
+ /** 🔊
2876
+ * Loads audio data from a file and returns an [HTMLAudioElement](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement).
2877
+ *
2878
+ * Audio is considered loaded when the [canplaythrough event](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplaythrough_event) is fired.
2879
+ *
2880
+ * Note that audio can only be played after the first user
2881
+ * interaction with the page!
2882
+ * @example
2883
+ * createCanvas(200);
2884
+ *
2885
+ * let audio = loadAudio('/assets/retro.flac');
2886
+ * audio.volume = 0.4;
2887
+ *
2888
+ * function mousePressed() {
2889
+ * audio.play();
2890
+ * }
2891
+ */
2892
+ function loadAudio(url: string): HTMLAudioElement & PromiseLike<HTMLAudioElement>;
2893
+
2894
+ /** 🔊
2895
+ * Returns the AudioContext in use or undefined if it doesn't exist.
2896
+ * @returns {AudioContext} AudioContext instance
2897
+ */
2898
+ function getAudioContext(): AudioContext | void;
2899
+
2900
+ /** 🔊
2901
+ * Creates a new AudioContext or resumes it if it was suspended.
2902
+ * @returns {Promise<void>} a promise that resolves when the AudioContext is resumed
2903
+ */
2904
+ function userStartAudio(): Promise<void>;
2905
+
2906
+ class Sound {
2907
+
2908
+ /** 🔊
2909
+ * Creates a new `Q5.Sound` object.
2910
+ */
2911
+ constructor();
2912
+
2913
+ /** 🔊
2914
+ * Set the sound's volume to a value between
2915
+ * 0 (silent) and 1 (full volume).
2916
+ */
2917
+ volume: number;
2918
+
2919
+ /** 🔊
2920
+ * Set the sound's stereo position between -1 (left) and 1 (right).
2921
+ */
2922
+ pan: number;
2923
+
2924
+ /** 🔊
2925
+ * Set to true to make the sound loop continuously.
2926
+ */
2927
+ loop: boolean;
2928
+
2929
+ /** 🔊
2930
+ * True if the sound data has finished loading.
2931
+ */
2932
+ loaded: boolean;
2933
+
2934
+ /** 🔊
2935
+ * True if the sound is currently paused.
2936
+ */
2937
+ paused: boolean;
2938
+
2939
+ /** 🔊
2940
+ * True if the sound has finished playing.
2941
+ */
2942
+ ended: boolean;
2943
+
2944
+ /** 🔊
2945
+ * Plays the sound.
2946
+ *
2947
+ * If this function is run when the sound is already playing,
2948
+ * a new playback will start, causing a layering effect.
2949
+ *
2950
+ * If this function is run when the sound is paused,
2951
+ * all playback instances will be resumed.
2952
+ */
2953
+ play(): void;
2954
+
2955
+ /** 🔊
2956
+ * Pauses the sound, allowing it to be resumed.
2957
+ */
2958
+ pause(): void;
2959
+
2960
+ /** 🔊
2961
+ * Stops the sound, resetting its playback position
2962
+ * to the beginning.
2963
+ *
2964
+ * Removes all playback instances.
2965
+ */
2966
+ stop(): void;
2967
+ }
2968
+
2969
+ // 📑 dom
2970
+
2971
+ /**
2972
+ * The Document Object Model (DOM) is an interface for
2973
+ * creating and editing web pages with JavaScript.
2974
+ */
2975
+
2976
+ /** 📑
2977
+ * Creates a new HTML element and adds it to the page. `createEl` is
2978
+ * an alias.
2979
+ *
2980
+ * Modify the element's CSS [`style`](https://developer.mozilla.org/docs/Web/API/HTMLElement/style) to change its appearance.
2981
+ *
2982
+ * Use [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) to respond to events such as:
2983
+ *
2984
+ * - "click": when the element is clicked
2985
+ * - "mouseover": when the mouse hovers over the element
2986
+ * - "mouseout": when the mouse stops hovering over the element
2987
+ * - "input": when a form element's value changes
2988
+ *
2989
+ * q5 adds some extra functionality to the elements it creates:
2990
+ *
2991
+ * - the `position` function makes it easy to place the element
2992
+ * relative to the canvas
2993
+ * - the `size` function sets the width and height of the element
2994
+ * - alternatively, use the element's `x`, `y`, `width`, and `height` properties
2995
+ * @param {string} tag tag name of the element
2996
+ * @param {string} [content] content of the element
2997
+ * @returns {HTMLElement} element
2998
+ * @example
2999
+ * createCanvas(200);
3000
+ *
3001
+ * let el = createEl('div', '*');
3002
+ * el.position(50, 50);
3003
+ * el.size(100, 100);
3004
+ * el.style.fontSize = '136px';
3005
+ * el.style.textAlign = 'center';
3006
+ * el.style.backgroundColor = 'blue';
3007
+ * el.style.color = 'white';
3008
+ */
3009
+ function createElement(tag: string, content?: string): HTMLElement;
3010
+
3011
+ /** 📑
3012
+ * Creates a link element.
3013
+ * @param {string} href url
3014
+ * @param {string} [text] text content
3015
+ * @param {boolean} [newTab] whether to open the link in a new tab
3016
+ * @example
3017
+ * createCanvas(200);
3018
+ *
3019
+ * let link = createA('https://q5js.org', 'q5.js');
3020
+ * link.position(16, 42);
3021
+ * link.style.fontSize = '80px';
3022
+ *
3023
+ * link.addEventListener('mouseover', () => {
3024
+ * background('cyan');
3025
+ * });
3026
+ */
3027
+ function createA(href: string, text?: string): HTMLAnchorElement;
3028
+
3029
+ /** 📑
3030
+ * Creates a button element.
3031
+ * @param {string} [content] text content
3032
+ * @example
3033
+ * createCanvas(200, 100);
3034
+ *
3035
+ * let btn = createButton('Click me!');
3036
+ *
3037
+ * btn.addEventListener('click', () => {
3038
+ * background(random(100, 255));
3039
+ * });
3040
+ */
3041
+ function createButton(content?: string): HTMLButtonElement;
3042
+
3043
+ /** 📑
3044
+ * Creates a checkbox element.
3045
+ *
3046
+ * Use the `checked` property to get or set the checkbox's state.
3047
+ *
3048
+ * The `label` property is the text label element next to the checkbox.
3049
+ * @param {string} [label] text label placed next to the checkbox
3050
+ * @param {boolean} [checked] initial state
3051
+ * @example
3052
+ * createCanvas(200, 100);
3053
+ *
3054
+ * let box = createCheckbox('Check me!');
3055
+ * box.label.style.color = 'lime';
3056
+ *
3057
+ * box.addEventListener('input', () => {
3058
+ * if (box.checked) background('lime');
3059
+ * else background('black');
3060
+ * });
3061
+ */
3062
+ function createCheckbox(label?: string, checked?: boolean): HTMLInputElement;
3063
+
3064
+ /** 📑
3065
+ * Creates a color input element.
3066
+ *
3067
+ * Use the `value` property to get or set the color value.
3068
+ * @param {string} [value] initial color value
3069
+ * @example
3070
+ * createCanvas(200, 100);
3071
+ *
3072
+ * let picker = createColorPicker();
3073
+ * picker.value = '#fd7575';
3074
+ *
3075
+ * function draw() {
3076
+ * background(picker.value);
3077
+ * }
3078
+ */
3079
+ function createColorPicker(value?: string): HTMLInputElement;
3080
+
3081
+ /** 📑
3082
+ * Creates an image element.
3083
+ * @param {string} src url of the image
3084
+ * @example
3085
+ * createCanvas(200, 100);
3086
+ *
3087
+ * let img = createImg('/assets/p5play_logo.webp');
3088
+ * img.position(0, 0).size(100, 100);
3089
+ */
3090
+ function createImg(src: string): HTMLImageElement;
3091
+
3092
+ /** 📑
3093
+ * Creates an input element.
3094
+ *
3095
+ * Use the `value` property to get or set the input's value.
3096
+ *
3097
+ * Use the `placeholder` property to set label text that appears
3098
+ * inside the input when it's empty.
3099
+ *
3100
+ * See MDN's [input documentation](https://developer.mozilla.org/docs/Web/HTML/Element/input#input_types) for the full list of input types.
3101
+ * @param {string} [value] initial value
3102
+ * @param {string} [type] text input type, can be 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
3103
+ * @example
3104
+ * createCanvas(200, 100);
3105
+ * textSize(64);
3106
+ *
3107
+ * let input = createInput();
3108
+ * input.placeholder = 'Type here!';
3109
+ * input.size(200, 32);
3110
+ *
3111
+ * input.addEventListener('input', () => {
3112
+ * background('orange');
3113
+ * text(input.value, 10, 70);
3114
+ * });
3115
+ */
3116
+ function createInput(value?: string, type?: string): HTMLInputElement;
3117
+
3118
+ /** 📑
3119
+ * Creates a paragraph element.
3120
+ * @param {string} [content] text content
3121
+ * @example
3122
+ * createCanvas(200, 50);
3123
+ * background('coral');
3124
+ *
3125
+ * let p = createP('Hello, world!');
3126
+ * p.style.color = 'pink';
3127
+ */
3128
+ function createP(content?: string): HTMLParagraphElement;
3129
+
3130
+ /** 📑
3131
+ * Creates a radio button group.
3132
+ *
3133
+ * Use the `option(label, value)` function to add new radio buttons
3134
+ * to the group.
3135
+ *
3136
+ * Use the `value` property to get or set the value of the selected radio button.
3137
+ * @param {string} [groupName]
3138
+ * @example
3139
+ * createCanvas(200, 160);
3140
+ *
3141
+ * let radio = createRadio();
3142
+ * radio.option('square', '1').option('circle', '2');
3143
+ *
3144
+ * function draw() {
3145
+ * background(200);
3146
+ * if (radio.value == '1') square(75, 25, 80);
3147
+ * if (radio.value == '2') circle(100, 50, 80);
3148
+ * }
3149
+ */
3150
+ function createRadio(groupName?: string): HTMLDivElement;
3151
+
3152
+ /** 📑
3153
+ * Creates a select element.
3154
+ *
3155
+ * Use the `option(label, value)` function to add new options to
3156
+ * the select element.
3157
+ *
3158
+ * Set `multiple` to `true` to allow multiple options to be selected.
3159
+ *
3160
+ * Use the `value` property to get or set the selected option value.
3161
+ *
3162
+ * Use the `selected` property get the labels of the selected
3163
+ * options or set the selected options by label. Can be a single
3164
+ * string or an array of strings.
3165
+ * @param {string} [placeholder] optional placeholder text that appears before an option is selected
3166
+ * @example
3167
+ * createCanvas(200, 100);
3168
+ *
3169
+ * let sel = createSelect('Select a color');
3170
+ * sel.option('Red', '#f55').option('Green', '#5f5');
3171
+ *
3172
+ * sel.addEventListener('change', () => {
3173
+ * background(sel.value);
3174
+ * });
3175
+ */
3176
+ function createSelect(placeholder?: string): HTMLSelectElement;
3177
+
3178
+ /** 📑
3179
+ * Creates a slider element.
3180
+ *
3181
+ * Use the `value` property to get or set the slider's value.
3182
+ *
3183
+ * Use the `val` function to get the slider's value as a number.
3184
+ * @param {number} min minimum value
3185
+ * @param {number} max maximum value
3186
+ * @param {number} [value] initial value
3187
+ * @param {number} [step] step size
3188
+ * @example
3189
+ * createCanvas(200);
3190
+ *
3191
+ * let slider = createSlider(0, 255);
3192
+ * slider.position(10, 10).size(180);
3193
+ *
3194
+ * function draw() {
3195
+ * background(slider.val());
3196
+ * }
3197
+ */
3198
+ function createSlider(min: number, max: number, value?: number, step?: number): HTMLInputElement;
3199
+
3200
+ /** 📑
3201
+ * Creates a video element.
3202
+ *
3203
+ * Note that videos must be muted to autoplay and the `play` and
3204
+ * `pause` functions can only be run after a user interaction.
3205
+ *
3206
+ * The video element can be hidden and its content can be
3207
+ * displayed on the canvas using the `image` function.
3208
+ * @param {string} src url of the video
3209
+ * @returns {HTMLVideoElement & PromiseLike<HTMLVideoElement>} a new video element
3210
+ * @example
3211
+ * createCanvas(1);
3212
+ *
3213
+ * let vid = createVideo('/assets/apollo4.mp4');
3214
+ * vid.size(200, 150);
3215
+ * vid.autoplay = vid.muted = vid.loop = true;
3216
+ * vid.controls = true;
3217
+ * @example
3218
+ * createCanvas(200, 150);
3219
+ * let vid = createVideo('/assets/apollo4.mp4');
3220
+ * vid.hide();
3221
+ *
3222
+ * function mousePressed() {
3223
+ * vid.currentTime = 0;
3224
+ * vid.play();
3225
+ * }
3226
+ * function draw() {
3227
+ * image(vid, 0, 0, 200, 150);
3228
+ * filter(HUE_ROTATE, 90);
3229
+ * }
3230
+ */
3231
+ function createVideo(src: string): HTMLVideoElement & PromiseLike<HTMLVideoElement>;
3232
+
3233
+ /** 📑
3234
+ * Creates a capture from a connected camera, such as a webcam.
3235
+ *
3236
+ * The capture video element can be hidden and its content can be
3237
+ * displayed on the canvas using the `image` function.
3238
+ *
3239
+ * Can preload to ensure the capture is ready to use when your
3240
+ * sketch starts.
3241
+ *
3242
+ * Requests the highest video resolution from the user facing camera
3243
+ * by default. The first parameter to this function can be used to
3244
+ * specify the constraints for the capture. See [`getUserMedia`](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia)
3245
+ * for more info.
3246
+ * @param {string} [type] type of capture, can be only `VIDEO` or only `AUDIO`, the default is to use both video and audio
3247
+ * @param {boolean} [flipped] whether to mirror the video vertically, true by default
3248
+ * @returns {HTMLVideoElement & PromiseLike<HTMLVideoElement>} a new video element
3249
+ * @example
3250
+ * function mousePressed() {
3251
+ * let cap = createCapture(VIDEO);
3252
+ * cap.size(200, 112.5);
3253
+ * canvas.remove();
3254
+ * }
3255
+ * @example
3256
+ * let cap;
3257
+ * function mousePressed() {
3258
+ * cap = createCapture(VIDEO);
3259
+ * cap.hide();
3260
+ * }
3261
+ *
3262
+ * function draw() {
3263
+ * let y = frameCount % height;
3264
+ * image(cap, 0, y, 200, 200);
3265
+ * }
3266
+ * @example
3267
+ * function mousePressed() {
3268
+ * let cap = createCapture({
3269
+ * video: { width: 640, height: 480 }
3270
+ * });
3271
+ * cap.size(200, 150);
3272
+ * canvas.remove();
3273
+ * }
3274
+ */
3275
+ function createCapture(type?: string, flipped?: boolean): HTMLVideoElement & PromiseLike<HTMLVideoElement>;
3276
+
3277
+ /** 📑
3278
+ * Finds the first element in the DOM that matches the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
3279
+ * @param {string} selector
3280
+ * @returns {HTMLElement} element
3281
+ */
3282
+ function findElement(selector: string): HTMLElement;
3283
+
3284
+ /** 📑
3285
+ * Finds all elements in the DOM that match the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
3286
+ * @param {string} selector
3287
+ * @returns {HTMLElement[]} elements
3288
+ */
3289
+ function findElements(selector: string): HTMLElement[];
3290
+
3291
+ // 🎞 record
3292
+
3293
+ /** 🎞
3294
+ * Creates a recorder. Simply hit record to start recording!
3295
+ *
3296
+ * The following properties can be set via the recorder UI or
3297
+ * programmatically.
3298
+ *
3299
+ * - `format` is set to "H.264" by default.
3300
+ * - `bitrate` is a number in megabits per second (mbps). Its default
3301
+ * value is determined by the height of the canvas. Increasing the
3302
+ * bitrate will increase the quality and file size of the recording.
3303
+ * - `captureAudio` is set to true by default. Set to false to disable
3304
+ * audio recording.
3305
+ *
3306
+ * Note that recordings are done at a variable frame rate (VFR), which
3307
+ * makes the output video incompatible with some editing software.
3308
+ * For more info, see the
3309
+ * ["Recording the Canvas"](https://github.com/q5js/q5.js/wiki/Recording-the-Canvas).
3310
+ * wiki page.
3311
+ * @returns {HTMLElement} a recorder, q5 DOM element
3312
+ * @example
3313
+ * createCanvas(200);
3314
+ *
3315
+ * let rec = createRecorder();
3316
+ * rec.bitrate = 10;
3317
+ *
3318
+ * function draw() {
3319
+ * circle(mouseX, random(height), 10);
3320
+ * }
3321
+ */
3322
+ function createRecorder(): HTMLElement;
3323
+
3324
+ /** 🎞
3325
+ * Starts recording the canvas or resumes recording if it was paused.
3326
+ *
3327
+ * If no recorder exists, one is created but not displayed.
3328
+ */
3329
+ function record(): void;
3330
+
3331
+ /** 🎞
3332
+ * Pauses the canvas recording, if one is in progress.
3333
+ */
3334
+ function pauseRecording(): void;
3335
+
3336
+ /** 🎞
3337
+ * Discards the current recording.
3338
+ */
3339
+ function deleteRecording(): void;
3340
+
3341
+ /** 🎞
3342
+ * Saves the current recording as a video file.
3343
+ * @param {string} fileName
3344
+ * @example
3345
+ * function draw() {
3346
+ * square(mouseX, random(200), 10);
3347
+ * }
3348
+ *
3349
+ * function mousePressed() {
3350
+ * if (!recording) record();
3351
+ * else saveRecording('squares');
3352
+ * }
3353
+ */
3354
+ function saveRecording(fileName: string): void;
3355
+
3356
+ /** 🎞
3357
+ * True if the canvas is currently being recorded.
3358
+ */
3359
+ var recording: boolean;
3360
+
3361
+ // 🛠 utilities
3362
+
3363
+ /** 🛠
3364
+ * Loads a file or multiple files.
3365
+ *
3366
+ * File type is determined by file extension. q5 supports loading
3367
+ * text, json, csv, font, audio, and image files.
3368
+ * @param {...string} urls
3369
+ * @returns {Promise<any[]>} a promise that resolves with objects
3370
+ * @example
3371
+ * createCanvas(200);
3372
+ * let logo = load('/q5js_logo.avif');
3373
+ *
3374
+ * function draw() {
3375
+ * image(logo, 0, 0, 200, 200);
3376
+ * }
3377
+ */
3378
+ function load(...urls: string[]): PromiseLike<any[]>;
3379
+
3380
+ /** 🛠
3381
+ * Saves data to a file.
3382
+ *
3383
+ * If data is not specified, the canvas will be saved.
3384
+ *
3385
+ * If no arguments are provided, the canvas will be saved as
3386
+ * an image file named "untitled.png".
3387
+ * @param {object} [data] canvas, image, or JS object
3388
+ * @param {string} [fileName] filename to save as
3389
+ * @example
3390
+ * createCanvas(200);
3391
+ * background(200);
3392
+ * circle(100, 100, 50);
3393
+ *
3394
+ * function mousePressed() {
3395
+ * save('circle.png');
3396
+ * }
3397
+ * @example
3398
+ * createCanvas(200);
3399
+ *
3400
+ * textSize(180);
3401
+ * let bolt = createTextImage('⚡️');
3402
+ * image(bolt, 16, -56);
3403
+ *
3404
+ * function mousePressed() {
3405
+ * save(bolt, 'bolt.png');
3406
+ * }
3407
+ */
3408
+ function save(data?: object, fileName?: string): void;
3409
+
3410
+ /** 🛠
3411
+ * Loads a text file from the specified url.
3412
+ * @param {string} url text file
3413
+ * @returns {object & PromiseLike<string>} an object containing the loaded text in the property `obj.text` or a promise
3414
+ */
3415
+ function loadText(url: string): object & PromiseLike<string>;
3416
+
3417
+ /** 🛠
3418
+ * Loads a JSON file from the specified url.
3419
+ * @param {string} url JSON file
3420
+ * @returns {any & PromiseLike<any>} an object or array containing the loaded JSON or a promise
3421
+ */
3422
+ function loadJSON(url: string): any & PromiseLike<any>;
3423
+
3424
+ /** 🛠
3425
+ * Loads a CSV file from the specified url.
3426
+ * @param {string} url CSV file
3427
+ * @returns {object[] & PromiseLike<object[]>} an array of objects containing the loaded CSV or a promise
3428
+ */
3429
+ function loadCSV(url: string): object[] & PromiseLike<object[]>;
3430
+
3431
+ /** 🛠
3432
+ * Loads an xml file from the specified url.
3433
+ * @param {string} url xml file
3434
+ * @returns {Element & PromiseLike<Element>} an object containing the loaded XML in a property called `obj.DOM` or a promise
3435
+ * @example
3436
+ * async function setup() {
3437
+ * createCanvas(200);
3438
+ * background(200);
3439
+ * textSize(32);
3440
+ *
3441
+ * let myXML = await loadXML('/assets/animals.xml');
3442
+ *
3443
+ * let mammals = myXML.getElementsByTagName('mammal');
3444
+ * let y = 64;
3445
+ * for (let mammal of mammals) {
3446
+ * text(mammal.textContent, 20, (y += 32));
3447
+ * }
3448
+ * }
3449
+ */
3450
+ function loadXML(url: string): object & PromiseLike<Element>;
3451
+
3452
+ /** 🛠
3453
+ * nf is short for number format. It formats a number
3454
+ * to a string with a specified number of digits.
3455
+ * @param {number} num number to format
3456
+ * @param {number} digits number of digits to format to
3457
+ * @returns {string} formatted number
3458
+ */
3459
+ function nf(num: number, digits: number): string;
3460
+
3461
+ /** 🛠
3462
+ * Shuffles the elements of an array.
3463
+ * @param {any[]} arr array to shuffle
3464
+ * @param {boolean} [modify] whether to modify the original array, false by default which copies the array before shuffling
3465
+ * @returns {any[]} shuffled array
3466
+ */
3467
+ function shuffle(arr: any[]): any[];
3468
+
3469
+ /** 🛠
3470
+ * Stores an item in localStorage.
3471
+ * @param {string} key key under which to store the item
3472
+ * @param {string} val value to store
3473
+ */
3474
+ function storeItem(key: string, val: string): void;
3475
+
3476
+ /** 🛠
3477
+ * Retrieves an item from localStorage.
3478
+ * @param {string} key key of the item to retrieve
3479
+ * @returns {string} value of the retrieved item
3480
+ */
3481
+ function getItem(key: string): string;
3482
+
3483
+ /** 🛠
3484
+ * Removes an item from localStorage.
3485
+ * @param {string} key key of the item to remove
3486
+ */
3487
+ function removeItem(key: string): void;
3488
+
3489
+ /** 🛠
3490
+ * Clears all items from localStorage.
3491
+ */
3492
+ function clearStorage(): void;
3493
+
3494
+ /** 🛠
3495
+ * Returns the current year.
3496
+ * @returns {number} current year
3497
+ */
3498
+ function year(): number;
3499
+
3500
+ /** 🛠
3501
+ * Returns the current day of the month.
3502
+ * @returns {number} current day
3503
+ */
3504
+ function day(): number;
3505
+
3506
+ /** 🛠
3507
+ * Returns the current hour.
3508
+ * @returns {number} current hour
3509
+ */
3510
+ function hour(): number;
3511
+
3512
+ /** 🛠
3513
+ * Returns the current minute.
3514
+ * @returns {number} current minute
3515
+ */
3516
+ function minute(): number;
3517
+
3518
+ /** 🛠
3519
+ * Returns the current second.
3520
+ * @returns {number} current second
3521
+ */
3522
+ function second(): number;
3523
+
3524
+ // ↗ vector
3525
+
3526
+ class Vector {
3527
+
3528
+ /** ↗
3529
+ * Constructs a new Vector object.
3530
+ * @param {number} x x component of the vector
3531
+ * @param {number} y y component of the vector
3532
+ * @param {number} [z] optional. The z component of the vector
3533
+ */
3534
+ constructor(x: number, y: number, z?: number);
3535
+
3536
+ /** ↗
3537
+ * The x component of the vector.
3538
+ */
3539
+ x: number;
3540
+
3541
+ /** ↗
3542
+ * The y component of the vector.
3543
+ */
3544
+ y: number;
3545
+
3546
+ /** ↗
3547
+ * The z component of the vector, if applicable.
3548
+ */
3549
+ z: number;
3550
+
3551
+ /** ↗
3552
+ * Adds a vector to this vector.
3553
+ * @param {Vector} v vector to add
3554
+ * @returns {Vector} resulting vector after addition
3555
+ */
3556
+ add(v: Vector): Vector;
3557
+
3558
+ /** ↗
3559
+ * Subtracts a vector from this vector.
3560
+ * @param {Vector} v vector to subtract
3561
+ * @returns {Vector} resulting vector after subtraction
3562
+ */
3563
+ sub(v: Vector): Vector;
3564
+
3565
+ /** ↗
3566
+ * Multiplies this vector by a scalar or element-wise by another vector.
3567
+ * @param {number | Vector} n scalar to multiply by, or a vector for element-wise multiplication
3568
+ * @returns {Vector} resulting vector after multiplication
3569
+ */
3570
+ mult(n: number | Vector): Vector;
3571
+
3572
+ /** ↗
3573
+ * Divides this vector by a scalar or element-wise by another vector.
3574
+ * @param {number | Vector} n scalar to divide by, or a vector for element-wise division
3575
+ * @returns {Vector} resulting vector after division
3576
+ */
3577
+ div(n: number | Vector): Vector;
3578
+
3579
+ /** ↗
3580
+ * Calculates the magnitude (length) of the vector.
3581
+ * @returns {number} magnitude of the vector
3582
+ */
3583
+ mag(): number;
3584
+
3585
+ /** ↗
3586
+ * Normalizes the vector to a length of 1 (making it a unit vector).
3587
+ * @returns {Vector} this vector after normalization
3588
+ */
3589
+ normalize(): Vector;
3590
+
3591
+ /** ↗
3592
+ * Sets the magnitude of the vector to the specified length.
3593
+ * @param {number} len new length of the vector
3594
+ * @returns {Vector} this vector after setting magnitude
3595
+ */
3596
+ setMag(len: number): Vector;
3597
+
3598
+ /** ↗
3599
+ * Calculates the dot product of this vector and another vector.
3600
+ * @param {Vector} v other vector
3601
+ * @returns {number} dot product
3602
+ */
3603
+ dot(v: Vector): number;
3604
+
3605
+ /** ↗
3606
+ * Calculates the cross product of this vector and another vector.
3607
+ * @param {Vector} v other vector
3608
+ * @returns {Vector} a new vector that is the cross product of this vector and the given vector
3609
+ */
3610
+ cross(v: Vector): Vector;
3611
+
3612
+ /** ↗
3613
+ * Calculates the distance between this vector and another vector.
3614
+ * @param {Vector} v other vector
3615
+ * @returns {number} distance
3616
+ */
3617
+ dist(v: Vector): number;
3618
+
3619
+ /** ↗
3620
+ * Copies this vector.
3621
+ * @returns {Vector} a new vector with the same components as this one
3622
+ */
3623
+ copy(): Vector;
3624
+
3625
+ /** ↗
3626
+ * Sets the components of the vector.
3627
+ * @param {number} x x component
3628
+ * @param {number} y y component
3629
+ * @param {number} [z] optional. The z component
3630
+ * @returns {void}
3631
+ */
3632
+ set(x: number, y: number, z?: number): void;
3633
+
3634
+ /** ↗
3635
+ * Limits the magnitude of the vector to the value used for the max parameter.
3636
+ * @param {number} max maximum magnitude for the vector
3637
+ * @returns {Vector} this vector after limiting
3638
+ */
3639
+ limit(max: number): Vector;
3640
+
3641
+ /** ↗
3642
+ * Calculates the angle of rotation for this vector (only 2D vectors).
3643
+ * @returns {number} angle of rotation
3644
+ */
3645
+ heading(): number;
3646
+
3647
+ /** ↗
3648
+ * Rotates the vector to a specific angle without changing its magnitude.
3649
+ * @param {number} angle angle in radians
3650
+ * @returns {Vector} this vector after setting the heading
3651
+ */
3652
+ setHeading(angle: number): Vector;
3653
+
3654
+ /** ↗
3655
+ * Rotates the vector by the given angle (only 2D vectors).
3656
+ * @param {number} angle angle of rotation in radians
3657
+ * @returns {Vector} this vector after rotation
3658
+ */
3659
+ rotate(angle: number): Vector;
3660
+
3661
+ /** ↗
3662
+ * Linearly interpolates between this vector and another vector.
3663
+ * @param {Vector} v vector to interpolate towards
3664
+ * @param {number} amt amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)
3665
+ * @returns {Vector} this vector after interpolation
3666
+ */
3667
+ lerp(v: Vector, amt: number): Vector;
3668
+
3669
+ /** ↗
3670
+ * Linearly interpolates between this vector and another vector, including the magnitude.
3671
+ * @param {Vector} v vector to interpolate towards
3672
+ * @param {number} amt amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)
3673
+ * @returns {Vector} this vector after spherical interpolation
3674
+ */
3675
+ slerp(v: Vector, amt: number): Vector;
3676
+ static fromAngle(angle: number, length?: number): Vector;
3677
+
3678
+ }
3679
+
3680
+ // 🖌 shaping
3681
+
3682
+ /** 🖌
3683
+ * Draws an arc, which is a section of an ellipse.
3684
+ *
3685
+ * `ellipseMode` affects how the arc is drawn.
3686
+ *
3687
+ * q5 WebGPU only supports the default `PIE_OPEN` mode.
3688
+ * @param {number} x x-coordinate
3689
+ * @param {number} y y-coordinate
3690
+ * @param {number} w width of the ellipse
3691
+ * @param {number} h height of the ellipse
3692
+ * @param {number} start angle to start the arc
3693
+ * @param {number} stop angle to stop the arc
3694
+ * @param {number} [mode] shape and stroke style setting, default is `PIE_OPEN` for a pie shape with an unclosed stroke, can be `PIE`, `CHORD`, or `CHORD_OPEN`
3695
+ * @example
3696
+ * createCanvas(200);
3697
+ * background(200);
3698
+ *
3699
+ * arc(40, 40, 40, 40, 0.8, -0.8);
3700
+ * arc(80, 80, 40, 40, 0.8, -0.8, PIE);
3701
+ * arc(120, 120, 40, 40, 0.8, -0.8, CHORD_OPEN);
3702
+ * arc(160, 160, 40, 40, 0.8, -0.8, CHORD);
3703
+ */
3704
+ function arc(x: number, y: number, w: number, h: number, start: number, stop: number, mode?: number): void;
3705
+
3706
+ /** 🖌
3707
+ * Draws a curve.
3708
+ */
3709
+ function curve(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
3710
+
3711
+ /** 🖌
3712
+ * Sets the amount of straight line segments used to make a curve.
3713
+ *
3714
+ * Only takes effect in q5 WebGPU.
3715
+ * @param {number} val curve detail level, default is 20
3716
+ */
3717
+ function curveDetail(val: number): void;
3718
+
3719
+ /** 🖌
3720
+ * Starts storing vertices for a convex shape.
3721
+ */
3722
+ function beginShape(): void;
3723
+
3724
+ /** 🖌
3725
+ * Ends storing vertices for a convex shape.
3726
+ */
3727
+ function endShape(): void;
3728
+
3729
+ /** 🖌
3730
+ * Starts storing vertices for a contour.
3731
+ *
3732
+ * Not available in q5 WebGPU.
3733
+ */
3734
+ function beginContour(): void;
3735
+
3736
+ /** 🖌
3737
+ * Ends storing vertices for a contour.
3738
+ *
3739
+ * Not available in q5 WebGPU.
3740
+ */
3741
+ function endContour(): void;
3742
+
3743
+ /** 🖌
3744
+ * Specifies a vertex in a shape.
3745
+ * @param {number} x x-coordinate
3746
+ * @param {number} y y-coordinate
3747
+ */
3748
+ function vertex(x: number, y: number): void;
3749
+
3750
+ /** 🖌
3751
+ * Specifies a Bezier vertex in a shape.
3752
+ * @param {number} cp1x x-coordinate of the first control point
3753
+ * @param {number} cp1y y-coordinate of the first control point
3754
+ * @param {number} cp2x x-coordinate of the second control point
3755
+ * @param {number} cp2y y-coordinate of the second control point
3756
+ * @param {number} x x-coordinate of the anchor point
3757
+ * @param {number} y y-coordinate of the anchor point
3758
+ */
3759
+ function bezierVertex(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
3760
+
3761
+ /** 🖌
3762
+ * Specifies a quadratic Bezier vertex in a shape.
3763
+ * @param {number} cp1x x-coordinate of the control point
3764
+ * @param {number} cp1y y-coordinate of the control point
3765
+ * @param {number} x x-coordinate of the anchor point
3766
+ * @param {number} y y-coordinate of the anchor point
3767
+ */
3768
+ function quadraticVertex(cp1x: number, cp1y: number, x: number, y: number): void;
3769
+
3770
+ /** 🖌
3771
+ * Draws a Bezier curve.
3772
+ * @param {number} x1 x-coordinate of the first anchor point
3773
+ * @param {number} y1 y-coordinate of the first anchor point
3774
+ * @param {number} x2 x-coordinate of the first control point
3775
+ * @param {number} y2 y-coordinate of the first control point
3776
+ * @param {number} x3 x-coordinate of the second control point
3777
+ * @param {number} y3 y-coordinate of the second control point
3778
+ * @param {number} x4 x-coordinate of the second anchor point
3779
+ * @param {number} y4 y-coordinate of the second anchor point
3780
+ */
3781
+ function bezier(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
3782
+
3783
+ /** 🖌
3784
+ * Draws a triangle.
3785
+ * @param {number} x1 x-coordinate of the first vertex
3786
+ * @param {number} y1 y-coordinate of the first vertex
3787
+ * @param {number} x2 x-coordinate of the second vertex
3788
+ * @param {number} y2 y-coordinate of the second vertex
3789
+ * @param {number} x3 x-coordinate of the third vertex
3790
+ * @param {number} y3 y-coordinate of the third vertex
3791
+ */
3792
+ function triangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void;
3793
+
3794
+ /** 🖌
3795
+ * Draws a quadrilateral.
3796
+ * @param {number} x1 x-coordinate of the first vertex
3797
+ * @param {number} y1 y-coordinate of the first vertex
3798
+ * @param {number} x2 x-coordinate of the second vertex
3799
+ * @param {number} y2 y-coordinate of the second vertex
3800
+ * @param {number} x3 x-coordinate of the third vertex
3801
+ * @param {number} y3 y-coordinate of the third vertex
3802
+ * @param {number} x4 x-coordinate of the fourth vertex
3803
+ * @param {number} y4 y-coordinate of the fourth vertex
3804
+ */
3805
+ function quad(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
3806
+
3807
+ // ⚙ advanced
3808
+
3809
+ /** ⚙
3810
+ * Alias for `Q5`.
3811
+ */
3812
+ const q5: typeof Q5;
3813
+
3814
+ class Q5 {
3815
+
3816
+ /** ⚙
3817
+ * Creates an [instance](https://github.com/q5js/q5.js/wiki/Instance-Mode) of Q5.
3818
+ *
3819
+ * Used by the global `createCanvas` function.
3820
+ * @param {string | Function} [scope]
3821
+ * @param {HTMLElement} [parent] element that the canvas will be placed inside
3822
+ * @example
3823
+ * let q = new Q5('namespace');
3824
+ * q.createCanvas(200, 100);
3825
+ * q.circle(100, 50, 20);
3826
+ */
3827
+ constructor(scope?: string | Function, parent?: HTMLElement);
3828
+
3829
+ /** ⚙
3830
+ * Turn off q5's friendly error messages.
3831
+ */
3832
+ static disableFriendlyErrors: boolean;
3833
+
3834
+ /** ⚙
3835
+ * Set to true to keep draw looping after an error.
3836
+ */
3837
+ static errorTolerant: boolean;
3838
+
3839
+ /** ⚙
3840
+ * True if the device supports HDR (the display-p3 colorspace).
3841
+ */
3842
+ static supportsHDR: boolean;
3843
+
3844
+ /** ⚙
3845
+ * Sets the default canvas context attributes used for newly created
3846
+ * canvases and internal graphics. These options are overwritten by any
3847
+ * per-canvas options you pass to `createCanvas`.
3848
+ */
3849
+ static canvasOptions: object;
3850
+
3851
+ /** ⚙
3852
+ * A WebGPU memory allocation limit.
3853
+ *
3854
+ * The maximum number of transformation matrixes
3855
+ * that can be used in a single draw call.
3856
+ */
3857
+ static MAX_TRANSFORMS: number;
3858
+
3859
+ /** ⚙
3860
+ * A WebGPU memory allocation limit.
3861
+ *
3862
+ * The maximum number of rectangles
3863
+ * (calls to `rect`, `square`, `capsule`)
3864
+ * that can be drawn in a single draw call.
3865
+ */
3866
+ static MAX_RECTS: number;
3867
+
3868
+ /** ⚙
3869
+ * A WebGPU memory allocation limit.
3870
+ *
3871
+ * The maximum number of ellipses
3872
+ * (calls to `ellipse`, `circle`, and `arc`)
3873
+ * that can be drawn in a single draw call.
3874
+ */
3875
+ static MAX_ELLIPSES: number;
3876
+
3877
+ /** ⚙
3878
+ * A WebGPU memory allocation limit.
3879
+ *
3880
+ * The maximum number of text characters
3881
+ * that can be drawn in a single draw call.
3882
+ */
3883
+ static MAX_CHARS: number;
3884
+
3885
+ /** ⚙
3886
+ * A WebGPU memory allocation limit.
3887
+ *
3888
+ * The maximum number of separate calls to `text`
3889
+ * that can be drawn in a single draw call.
3890
+ */
3891
+ static MAX_TEXTS: number;
3892
+
3893
+ /** ⚙
3894
+ * Creates a new Q5 instance that uses [q5's WebGPU renderer](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer).
3895
+ */
3896
+ static WebGPU(): Q5;
3897
+
3898
+ /** ⚙
3899
+ * Addons can augment q5 with new functionality by adding hooks,
3900
+ * functions to be run at specific phases in the q5 lifecycle.
3901
+ *
3902
+ * Inside the function, `this` refers to the Q5 instance.
3903
+ * @param {string} lifecycle init, presetup, postsetup, predraw, postdraw, or remove
3904
+ * @param {Function} fn The function to be run at the specified lifecycle phase.
3905
+ */
3906
+ static addHook(lifecycle: string, fn: Function): void;
3907
+
3908
+ /** ⚙
3909
+ * p5.js v2 compatible way to register an addon with q5.
3910
+ * @param {Function} addon A function that receives `Q5`, `Q5.prototype`, and a `lifecycles` object.
3911
+ */
3912
+ static registerAddon(addon: Function): void;
3913
+
3914
+ /** ⚙
3915
+ * An object containing q5's modules, functions that run when q5 loads.
3916
+ *
3917
+ * Each function receives two input parameters:
3918
+ *
3919
+ * - the q5 instance
3920
+ * - a proxy for editing the q5 instance and corresponding properties of the global scope
3921
+ */
3922
+ static modules: object;
3923
+
3924
+ /** ⚙
3925
+ * The q5 draw function is run 60 times per second by default.
3926
+ */
3927
+ draw(): void;
3928
+
3929
+ /** ⚙
3930
+ * Runs after each `draw` function call and post-draw q5 addon processes, if any.
3931
+ *
3932
+ * Useful for adding post-processing effects when it's not possible
3933
+ * to do so at the end of the `draw` function, such as when using
3934
+ * addons like p5play that auto-draw to the canvas after the `draw`
3935
+ * function is run.
3936
+ */
3937
+ postProcess(): void;
3938
+ update(): void; //-
3939
+
3940
+ drawFrame(): void; //-
3941
+
3942
+ static Image: {
3943
+ new (w: number, h: number, opt?: any): Q5.Image;
3944
+ };
3945
+
3946
+ }
3947
+
3948
+ }
3949
+
3950
+ export {};