q5 3.9.4 → 4.0.1

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