q5 3.9.1 → 4.0.0

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