q5 2.16.0 → 2.17.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.
Files changed (5) hide show
  1. package/deno.json +1 -1
  2. package/package.json +2 -2
  3. package/q5.d.ts +570 -213
  4. package/q5.js +267 -5
  5. package/q5.min.js +2 -2
package/q5.d.ts CHANGED
@@ -80,7 +80,7 @@ function draw() {
80
80
  * it calls the draw function once.
81
81
  * @param {number} [n] number of times to redraw the canvas, default is 1
82
82
  * @example
83
- createCanvas(200, 200);
83
+ createCanvas(200);
84
84
  noLoop();
85
85
 
86
86
  function draw() {
@@ -95,7 +95,7 @@ function mousePressed() {
95
95
  /** ⭐️
96
96
  * Starts the draw loop again if it was stopped.
97
97
  * @example
98
- createCanvas(200, 200);
98
+ createCanvas(200);
99
99
  noLoop();
100
100
 
101
101
  function draw() {
@@ -248,7 +248,7 @@ function draw() {
248
248
  var deltaTime: number;
249
249
 
250
250
  /** ⭐️
251
- * q5 uses the same preload system as Java Processing and p5.js v1
251
+ * q5 uses the same preload system as p5.js v1
252
252
  * to load assets asynchronously, before the setup and draw
253
253
  * functions are run. It makes it very easy for users to
254
254
  * load many images, sounds, and other assets at the same time.
@@ -257,7 +257,7 @@ function draw() {
257
257
  * favor of having load* functions, such as `loadImage`,
258
258
  * return promises.
259
259
  *
260
- * In q5 the `load` function can be used to load a file or
260
+ * In q5 the [`load`](https://q5js.org/learn/#load) function can be used to load a file or
261
261
  * multiple files, and it returns a promise that resolves
262
262
  * when the file(s) are loaded.
263
263
  *
@@ -281,7 +281,7 @@ function draw() {
281
281
  *
282
282
  * Running `new Q5()` enables the use of q5 functions and variables
283
283
  * anywhere in your code. You can also start Q5 in global mode by
284
- * running [`createCanvas`](https://q5js.org/learn/#canvas-createCanvas).
284
+ * running [`createCanvas`](https://q5js.org/learn/#createCanvas).
285
285
  *
286
286
  * By default q5 uses the CanvasRenderingContext2D based c2d renderer.
287
287
  *
@@ -332,10 +332,11 @@ circle(100, 50, 80);
332
332
  * Start using q5 by running this function!
333
333
  *
334
334
  * If this function is not run by the user, a 200x200 canvas will be
335
- * created automatically before the draw loop starts. Although in q5
336
- * WebGPU, this function must be run before running other q5 functions.
337
- * @param {number} [w] width of the canvas, default is windowWidth
338
- * @param {number} [h] height of the canvas, default is windowHeight
335
+ * created automatically before the draw loop starts.
336
+ *
337
+ * In q5 WebGPU, this function must be run before running other q5 functions.
338
+ * @param {number} [w] width or size of the canvas
339
+ * @param {number} [h] height of the canvas
339
340
  * @param {Object} [opt] options for the canvas
340
341
  * @param {boolean} [opt.alpha] whether the canvas should have an alpha channel that allows it to be seen through, default is false
341
342
  * @param {string} [opt.colorSpace] color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
@@ -355,91 +356,89 @@ function draw() {
355
356
 
356
357
  /** ⬜️
357
358
  * The canvas element associated with the Q5 instance.
359
+ *
360
+ * @prop {number} w
361
+ * @prop {number} width
362
+ * @prop {number} h
363
+ * @prop {number} height
364
+ * @prop {number} hw half the width
365
+ * @prop {number} hh half the height
366
+ * @prop {string} renderer either "c2d" (Canvas2D) or "webgpu"
358
367
  */
359
368
  var canvas: HTMLCanvasElement;
360
369
 
361
- /** ⬜️
362
- * The width of the canvas.
363
- * Can also be accessed via `canvas.w`/`canvas.width`.
364
- */
365
- var width: number;
366
-
367
- /** ⬜️
368
- * The height of the canvas.
369
- * Can also be accessed via `canvas.h`/`canvas.height`.
370
- */
371
- var height: number;
372
-
373
370
  /** ⬜️
374
371
  * Clears the canvas, making every pixel completely transparent.
375
372
  *
376
- * The canvas can only be seen through if it has an alpha channel though.
373
+ * Note that the canvas can only be seen through if it has an alpha channel.
377
374
  */
378
375
  function clear(): void;
379
376
 
380
377
  /** ⬜️
381
378
  * Sets the fill color for shapes. The default is white.
382
379
  *
383
- * Like the [`color`](https://q5js.org/learn/#color) function, this function can accept colors in a wide range of formats: CSS color string, hex string, grayscale value, and color component values.
384
- * @param {string | Color} color fill color
380
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
381
+ * can accept colors in a wide range of formats: as a CSS color string,
382
+ * a `Color` object, grayscale value, or color component values.
383
+ * @param {Color} color fill color
385
384
  * @example
386
- function draw() {
387
- background(200);
385
+ createCanvas(200);
386
+ background(200);
388
387
 
389
- fill('red');
390
- circle(80, 80, 80);
388
+ fill('red');
389
+ circle(80, 80, 80);
391
390
 
392
- fill('lime');
393
- square(80, 80, 80);
394
- }
391
+ fill('lime');
392
+ square(80, 80, 80);
395
393
  */
396
- function fill(color: string | Color): void;
394
+ function fill(color: Color): void;
397
395
 
398
396
  /** ⬜️
399
397
  * Sets the stroke (outline) color for shapes. The default is black.
400
398
  *
401
- * Like the [`color`](https://q5js.org/learn/#color) function, this function can accept colors in a wide range of formats: CSS color string, hex string, grayscale value, and color component values.
402
- * @param {string | Color} color stroke color
399
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
400
+ * can accept colors in a wide range of formats: as a CSS color string,
401
+ * a `Color` object, grayscale value, or color component values.
402
+ * @param {Color} color stroke color
403
403
  * @example
404
- function draw() {
405
- background(200);
406
- fill(36);
404
+ createCanvas(200);
405
+ background(200);
406
+ fill(36);
407
407
 
408
- stroke('red');
409
- circle(80, 80, 80);
410
- stroke('lime');
411
- square(80, 80, 80);
412
- }
408
+ stroke('red');
409
+ circle(80, 80, 80);
410
+
411
+ stroke('lime');
412
+ square(80, 80, 80);
413
413
  */
414
- function stroke(color: string | Color): void;
414
+ function stroke(color: Color): void;
415
415
 
416
416
  /** ⬜️
417
417
  * After calling this function, shapes will not be filled.
418
418
  * @example
419
- function draw() {
420
- background(200);
419
+ createCanvas(200);
420
+ background(200);
421
421
 
422
- noFill();
423
- stroke('red');
424
- circle(80, 80, 80);
425
- stroke('lime');
426
- square(80, 80, 80);
427
- }
422
+ noFill();
423
+
424
+ stroke('red');
425
+ circle(80, 80, 80);
426
+ stroke('lime');
427
+ square(80, 80, 80);
428
428
  */
429
429
  function noFill(): void;
430
430
 
431
431
  /** ⬜️
432
432
  * After calling this function, shapes will not have a stroke (outline).
433
433
  * @example
434
- function draw() {
435
- background(200);
436
- fill(36);
437
- stroke('red');
438
- circle(80, 80, 80);
434
+ createCanvas(200);
435
+ background(200);
436
+ fill(36);
437
+ stroke('red');
438
+ circle(80, 80, 80);
439
439
 
440
- noStroke();
441
- square(80, 80, 80);
442
- }
440
+ noStroke();
441
+ square(80, 80, 80);
443
442
  */
444
443
  function noStroke(): void;
445
444
 
@@ -447,15 +446,13 @@ function draw() {
447
446
  * Sets the size of the stroke used for lines and the border around shapes.
448
447
  * @param {number} weight size of the stroke in pixels
449
448
  * @example
450
- function setup() {
451
- createCanvas(200, 200);
452
- background(200);
453
- stroke('red');
454
- circle(50, 100, 80);
449
+ createCanvas(200);
450
+ background(200);
451
+ stroke('red');
452
+ circle(50, 100, 80);
455
453
 
456
- strokeWeight(20);
457
- circle(150, 100, 80)
458
- }
454
+ strokeWeight(20);
455
+ circle(150, 100, 80);
459
456
  */
460
457
  function strokeWeight(weight: number): void;
461
458
 
@@ -463,15 +460,14 @@ function setup() {
463
460
  * Sets the global opacity, which affects all subsequent drawing operations, except `background`. Default is 1, fully opaque.
464
461
  * @param {number} alpha opacity level, ranging from 0 to 1
465
462
  * @example
466
- function draw() {
467
- background(200);
468
-
469
- opacity(1);
470
- circle(80, 80, 80);
463
+ createCanvas(200);
464
+ background(200);
471
465
 
472
- opacity(0.2);
473
- square(80, 80, 80);
474
- }
466
+ opacity(1);
467
+ circle(80, 80, 80);
468
+
469
+ opacity(0.2);
470
+ square(80, 80, 80);
475
471
  */
476
472
  function opacity(alpha: number): void;
477
473
 
@@ -481,19 +477,20 @@ function draw() {
481
477
  * Shadows apply to anything drawn to the canvas, including filled
482
478
  * shapes, strokes, text, and images.
483
479
  *
484
- * Like the [`color`](https://q5js.org/learn/#color) function, this function can accept colors in a wide range of formats: CSS color string, hex string, grayscale value, and color component values.
485
- * @param {string | Color} color shadow color
480
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
481
+ * can accept colors in a wide range of formats: as a CSS color string,
482
+ * a `Color` object, grayscale value, or color component values.
483
+ * @param {Color} color shadow color
486
484
  * @example
487
- function draw() {
488
- background(200);
489
-
490
- noFill();
491
- shadow('black');
492
- rect(64, 60, 80, 80);
493
- text('q5', 100, 100);
494
- }
485
+ createCanvas(200);
486
+ background(200);
487
+
488
+ noFill();
489
+ shadow('black');
490
+ rect(64, 60, 80, 80);
491
+ text('q5', 100, 100);
495
492
  * @example
496
- createCanvas(200, 200);
493
+ createCanvas(200);
497
494
  let logo = loadImage('/assets/p5play_logo.webp');
498
495
 
499
496
  function setup() {
@@ -507,15 +504,14 @@ function setup() {
507
504
  /** ⬜️
508
505
  * Disables the shadow effect.
509
506
  * @example
510
- function draw() {
511
- background(200);
512
- noStroke();
513
- shadow('black');
514
- rect(14, 14, 80, 80);
507
+ createCanvas(200);
508
+ background(200);
509
+ noStroke();
510
+ shadow('black');
511
+ rect(14, 14, 80, 80);
515
512
 
516
- noShadow();
517
- rect(104, 104, 80, 80);
518
- }
513
+ noShadow();
514
+ rect(104, 104, 80, 80);
519
515
  */
520
516
  function noShadow(): void;
521
517
 
@@ -527,27 +523,36 @@ function draw() {
527
523
  * @param {number} offsetY vertical offset of the shadow, defaults to be the same as offsetX
528
524
  * @param {number} blur blur radius of the shadow, defaults to 0
529
525
  * @example
530
- function draw() {
531
- background(200);
532
- noStroke();
533
- shadow('red');
526
+ createCanvas(200);
527
+ background(200);
528
+ noStroke();
529
+ shadow('red');
534
530
 
535
- shadowBox(-20, -8, 50);
536
- circle(100, 100, 80, 80);
537
- }
531
+ shadowBox(-20, -8, 50);
532
+ circle(100, 100, 80, 80);
538
533
  * @example
539
- function draw() {
540
- background(200);
541
- noStroke();
542
- shadow('aqua');
543
- shadowBox(20);
544
- rect(50, 50, 100, 100);
545
- textSize(64);
546
- text('q5', 60, 115);
547
- }
534
+ createCanvas(200);
535
+ background(200);
536
+ noStroke();
537
+
538
+ shadow('aqua');
539
+ shadowBox(20);
540
+ rect(50, 50, 100, 100);
541
+ textSize(64);
542
+ text('q5', 60, 115);
548
543
  */
549
544
  function shadowBox(offsetX: number, offsetY: number, blur: number): void;
550
545
 
546
+ /** ⬜️
547
+ * The width of the canvas.
548
+ */
549
+ var width: number;
550
+
551
+ /** ⬜️
552
+ * The height of the canvas.
553
+ */
554
+ var height: number;
555
+
551
556
  /** ⬜️
552
557
  * Translates the origin of the drawing context.
553
558
  * @param {number} x translation along the x-axis
@@ -649,35 +654,42 @@ function draw() {
649
654
  * q5 runs this function before every time the `draw` function is run,
650
655
  * so that transformations don't carry over to the next frame.
651
656
  * @example
652
- function draw() {
653
- background(200);
657
+ createCanvas(200);
658
+ background(200);
654
659
 
655
- translate(100, 100);
656
- circle(0, 0, 80);
660
+ translate(100, 100);
661
+ circle(0, 0, 80);
657
662
 
658
- resetMatrix();
659
- square(0, 0, 50);
660
- }
663
+ resetMatrix();
664
+ square(0, 0, 50);
661
665
  */
662
666
  function resetMatrix(): void;
663
667
 
664
668
  /** ⬜️
665
669
  * Saves the current transformation matrix.
666
670
  * @example
667
- function draw() {
668
- background(200);
669
- translate(100, 100);
670
- pushMatrix();
671
- rotate(QUARTER_PI);
672
- ellipse(0, 0, 120, 40);
673
- popMatrix();
674
- ellipse(0, 0, 120, 40);
675
- }
671
+ createCanvas(200);
672
+ background(200);
673
+ translate(100, 100);
674
+ pushMatrix();
675
+ rotate(QUARTER_PI);
676
+ ellipse(0, 0, 120, 40);
677
+ popMatrix();
678
+ ellipse(0, 0, 120, 40);
676
679
  */
677
680
  function pushMatrix(): void;
678
681
 
679
682
  /** ⬜️
680
683
  * Restores the previously saved transformation matrix.
684
+ * @example
685
+ createCanvas(200);
686
+ background(200);
687
+ translate(100, 100);
688
+ pushMatrix();
689
+ rotate(QUARTER_PI);
690
+ ellipse(0, 0, 120, 40);
691
+ popMatrix();
692
+ ellipse(0, 0, 120, 40);
681
693
  */
682
694
  function popMatrix(): void;
683
695
 
@@ -708,7 +720,7 @@ function draw() {
708
720
  /** ⬜️
709
721
  * Saves the current drawing style settings and transformations.
710
722
  * @example
711
- createCanvas(200, 200);
723
+ createCanvas(200);
712
724
 
713
725
  push();
714
726
  fill('blue');
@@ -757,7 +769,7 @@ square(0, 0, 50);
757
769
  * on the unit provided to this function.
758
770
  * @param {number} unit unit to scale by
759
771
  * @example
760
- createCanvas(200, 200);
772
+ createCanvas(200);
761
773
  flexibleCanvas(100);
762
774
  // rect will appear in the middle of the canvas
763
775
  rect(20, 20, 60, 60);
@@ -790,12 +802,17 @@ rect(20, 20, 60, 60);
790
802
  * @param {string} mode
791
803
  * - "normal": (default) no styling to canvas or its parent element
792
804
  * - "centered": canvas will be centered horizontally and vertically within its parent and if the window is smaller than the canvas, the canvas will be resized to avoid clipping
793
- * - "maxed": canvas will fill the parent element, same as fullscreen for a canvas inside a `main` element
794
- * - "fullscreen": canvas will fill the screen with letterboxing if necessary to preserve its aspect ratio
805
+ * - "maxed": canvas will fill the parent element, with letterboxing if necessary to preserve its aspect ratio
795
806
  * @param {string} renderQuality
796
807
  * - "smooth": (default) no change to the default render quality
797
808
  * - "pixelated": runs `pixelDensity(1)` and `noSmooth()` then sets the canvas CSS styles `image-rendering: pixelated` and `font-smooth: never`
798
809
  * @param {number} scale can also be given as a string (for example "x2")
810
+ * @example
811
+ createCanvas(50, 25);
812
+
813
+ displayMode('centered', 'pixelated', 4);
814
+
815
+ circle(25, 12.5, 16);
799
816
  */
800
817
  function displayMode(mode: string, renderQuality: string, scale: string | number): void;
801
818
 
@@ -803,32 +820,58 @@ rect(20, 20, 60, 60);
803
820
 
804
821
  /** 🧑‍🎨
805
822
  * Draws over the entire canvas with a color or image.
806
- * @param {string | number} color color or image to draw
823
+ *
824
+ * Like the [`color`](https://q5js.org/learn/#color) function,
825
+ * this function can accept colors in a wide range of formats:
826
+ * CSS color string, grayscale value, and color component values.
827
+ * @param {Color | Image} filler a color or image to draw
828
+ * @example
829
+ createCanvas(200, 100);
830
+ background('crimson');
831
+ * @example
832
+ function draw() {
833
+ background(128, 20);
834
+ circle(mouseX, mouseY, 20);
835
+ }
807
836
  */
808
- function background(color: string | number): void;
837
+ function background(filler: Color | Image): void;
809
838
 
810
839
  /** 🧑‍🎨
811
- * Draws a rectangle.
840
+ * Draws a rectangle or a rounded rectangle.
812
841
  * @param {number} x x-coordinate
813
842
  * @param {number} y y-coordinate
814
843
  * @param {number} w width of the rectangle
815
844
  * @param {number} [h] height of the rectangle
816
- * @param {number} [tl] top-left radius for rounded corners
817
- * @param {number} [tr] top-right radius for rounded corners
818
- * @param {number} [br] bottom-right radius for rounded corners
819
- * @param {number} [bl] bottom-left radius for rounded corners
845
+ * @param {number} [tl] top-left radius
846
+ * @param {number} [tr] top-right radius
847
+ * @param {number} [br] bottom-right radius
848
+ * @param {number} [bl] bottom-left radius
849
+ * @example
850
+ createCanvas(200);
851
+ background(200);
852
+
853
+ rect(30, 20, 40, 60);
854
+ rect(80, 70, 40, 60, 10);
855
+ rect(130, 120, 40, 60, 30, 2, 8, 20);
820
856
  */
821
857
  function rect(x: number, y: number, w: number, h?: number, tl?: number, tr?: number, br?: number, bl?: number): void;
822
858
 
823
859
  /** 🧑‍🎨
824
- * Draws a square.
860
+ * Draws a square or a rounded square.
825
861
  * @param {number} x x-coordinate
826
862
  * @param {number} y y-coordinate
827
863
  * @param {number} size size of the sides of the square
828
- * @param {number} [tl] top-left radius for rounded corners
829
- * @param {number} [tr] top-right radius for rounded corners
830
- * @param {number} [br] bottom-right radius for rounded corners
831
- * @param {number} [bl] bottom-left radius for rounded corners
864
+ * @param {number} [tl] top-left radius
865
+ * @param {number} [tr] top-right radius
866
+ * @param {number} [br] bottom-right radius
867
+ * @param {number} [bl] bottom-left radius
868
+ * @example
869
+ createCanvas(200);
870
+ background(200);
871
+
872
+ square(30, 30, 40);
873
+ square(80, 80, 40, 10);
874
+ square(130, 130, 40, 30, 2, 8, 20);
832
875
  */
833
876
  function square(x: number, y: number, size: number, tl?: number, tr?: number, br?: number, bl?: number): void;
834
877
 
@@ -837,6 +880,9 @@ rect(20, 20, 60, 60);
837
880
  * @param {number} x x-coordinate
838
881
  * @param {number} y y-coordinate
839
882
  * @param {number} diameter diameter of the circle
883
+ * @example
884
+ createCanvas(200, 100);
885
+ circle(100, 50, 80);
840
886
  */
841
887
  function circle(x: number, y: number, diameter: number): void;
842
888
 
@@ -846,6 +892,9 @@ rect(20, 20, 60, 60);
846
892
  * @param {number} y y-coordinate
847
893
  * @param {number} width width of the ellipse
848
894
  * @param {number} [height] height of the ellipse
895
+ * @example
896
+ createCanvas(200, 100);
897
+ ellipse(100, 50, 160, 80);
849
898
  */
850
899
  function ellipse(x: number, y: number, width: number, height?: number): void;
851
900
 
@@ -861,14 +910,13 @@ rect(20, 20, 60, 60);
861
910
  * @param {number} stop angle to stop the arc
862
911
  * @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`
863
912
  * @example
864
- function draw() {
865
- background(200);
913
+ createCanvas(200);
914
+ background(200);
866
915
 
867
- arc(40, 40, 40, 40, 0.8, -0.8);
868
- arc(80, 80, 40, 40, 0.8, -0.8, PIE);
869
- arc(120, 120, 40, 40, 0.8, -0.8, CHORD_OPEN);
870
- arc(160, 160, 40, 40, 0.8, -0.8, CHORD);
871
- }
916
+ arc(40, 40, 40, 40, 0.8, -0.8);
917
+ arc(80, 80, 40, 40, 0.8, -0.8, PIE);
918
+ arc(120, 120, 40, 40, 0.8, -0.8, CHORD_OPEN);
919
+ arc(160, 160, 40, 40, 0.8, -0.8, CHORD);
872
920
  */
873
921
  function arc(x: number, y: number, w: number, h: number, start: number, stop: number, mode?: number): void;
874
922
 
@@ -878,6 +926,10 @@ function draw() {
878
926
  * @param {number} y1 y-coordinate of the first point
879
927
  * @param {number} x2 x-coordinate of the second point
880
928
  * @param {number} y2 y-coordinate of the second point
929
+ * @example
930
+ createCanvas(200, 100);
931
+ stroke('lime');
932
+ line(20, 20, 180, 80);
881
933
  */
882
934
  function line(x1: number, y1: number, x2: number, y2: number): void;
883
935
 
@@ -885,6 +937,13 @@ function draw() {
885
937
  * Draws a point on the canvas.
886
938
  * @param {number} x x-coordinate
887
939
  * @param {number} y y-coordinate
940
+ * @example
941
+ createCanvas(200, 100);
942
+ stroke('white');
943
+ point(75, 50);
944
+
945
+ strokeWeight(10);
946
+ point(125, 50);
888
947
  */
889
948
  function point(x: number, y: number): void;
890
949
 
@@ -1029,6 +1088,8 @@ function draw() {
1029
1088
 
1030
1089
  /** 🧑‍🎨
1031
1090
  * Checks if a given point is within the current path's fill area.
1091
+ *
1092
+ * Not available in q5 WebGPU.
1032
1093
  * @param {number} x x-coordinate of the point
1033
1094
  * @param {number} y y-coordinate of the point
1034
1095
  * @returns {boolean} true if the point is within the fill area, false otherwise
@@ -1037,12 +1098,240 @@ function draw() {
1037
1098
 
1038
1099
  /** 🧑‍🎨
1039
1100
  * Checks if a given point is within the current path's stroke.
1101
+ *
1102
+ * Not available in q5 WebGPU.
1040
1103
  * @param {number} x x-coordinate of the point
1041
1104
  * @param {number} y y-coordinate of the point
1042
1105
  * @returns {boolean} true if the point is within the stroke, false otherwise
1043
1106
  */
1044
1107
  function inStroke(x: number, y: number): boolean;
1045
1108
 
1109
+ // 📑 dom
1110
+
1111
+ /** 📑
1112
+ * Creates a new HTML element.
1113
+ *
1114
+ * q5 adds functions like `position` and `size` to the element
1115
+ * that make it easy to position elements above the canvas.
1116
+ *
1117
+ * Modify the element's CSS [`style`](https://developer.mozilla.org/docs/Web/API/HTMLElement/style) to change its appearance.
1118
+ *
1119
+ * `createEl` is an alias for this function.
1120
+ * @param {string} tag tag name of the element
1121
+ * @param {string} [content] content of the element
1122
+ * @returns {HTMLElement} created DOM element
1123
+ * @example
1124
+ createCanvas(200);
1125
+
1126
+ let el = createEl('div', '*');
1127
+ el.position(0, 0);
1128
+ el.size(100, 100);
1129
+ el.style.fontSize = '136px';
1130
+ el.style.textAlign = 'center';
1131
+ el.style.backgroundColor = 'blue';
1132
+ el.style.color = 'white';
1133
+ */
1134
+ function createElement(tag: string, content?: string): HTMLElement;
1135
+
1136
+ /** 📑
1137
+ * Creates a link element.
1138
+ * @param {string} href url
1139
+ * @param {string} [text] text content
1140
+ * @param {boolean} [newTab] whether to open the link in a new tab
1141
+ * @example
1142
+ createCanvas(200, 100);
1143
+
1144
+ let link = createA('https://q5js.org', 'q5.js');
1145
+ link.position(0, 0);
1146
+ link.style.fontSize = '80px';
1147
+ */
1148
+ function createA(href: string, text?: string): HTMLAnchorElement;
1149
+
1150
+ /** 📑
1151
+ * Creates a button element.
1152
+ *
1153
+ * Use [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) to respond to button click events.
1154
+ * @param {string} [content] text content
1155
+ * @example
1156
+ createCanvas(200, 100);
1157
+
1158
+ let btn = createButton('Click me!');
1159
+
1160
+ btn.addEventListener('click', () => {
1161
+ background(random(100, 255));
1162
+ });
1163
+ */
1164
+ function createButton(content?: string): HTMLButtonElement;
1165
+
1166
+ /** 📑
1167
+ * Creates a checkbox element.
1168
+ *
1169
+ * Use the `checked` property to get or set the checkbox's state.
1170
+ *
1171
+ * The `label` property is the text label element next to the checkbox.
1172
+ * @param {string} [label] text label placed next to the checkbox
1173
+ * @param {boolean} [checked] initial state
1174
+ * @example
1175
+ createCanvas(200, 100);
1176
+
1177
+ let box = createCheckbox('Check me!');
1178
+ box.label.style.color = 'lime';
1179
+
1180
+ box.addEventListener('change', () => {
1181
+ if (box.checked) background('lime');
1182
+ else background('black');
1183
+ });
1184
+ */
1185
+ function createCheckbox(label?: string, checked?: boolean): HTMLInputElement;
1186
+
1187
+ /** 📑
1188
+ * Creates a color input element.
1189
+ *
1190
+ * Use the `value` property to get or set the color value.
1191
+ * @param {string} [value] initial color value
1192
+ * @example
1193
+ createCanvas(200, 100);
1194
+
1195
+ let picker = createColorPicker();
1196
+ picker.value = '#fd7575';
1197
+
1198
+ function draw() {
1199
+ background(picker.value);
1200
+ }
1201
+ */
1202
+ function createColorPicker(value?: string): HTMLInputElement;
1203
+
1204
+ /** 📑
1205
+ * Creates an img element.
1206
+ * @param {string} src url of the image
1207
+ * @example
1208
+ createCanvas(200, 100);
1209
+
1210
+ let img = createImg('/assets/p5play_logo.webp')
1211
+ .position(0, 0)
1212
+ .size(100, 100);
1213
+ */
1214
+ function createImg(src: string): HTMLImageElement;
1215
+
1216
+ /** 📑
1217
+ * Creates an input element.
1218
+ *
1219
+ * Use the `value` property to get or set the input's value.
1220
+ *
1221
+ * See MDN's [input documentation](https://developer.mozilla.org/docs/Web/HTML/Element/input#input_types) for the full list of input types.
1222
+ * @param {string} [value] initial value
1223
+ * @param {string} [type] text input type, can be 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
1224
+ * @example
1225
+ createCanvas(200, 100);
1226
+ textSize(64);
1227
+
1228
+ let input = createInput();
1229
+ input.placeholder = 'Type here!';
1230
+ input.size(200, 32);
1231
+
1232
+ input.addEventListener('input', () => {
1233
+ background('orange');
1234
+ text(input.value, 10, 70);
1235
+ });
1236
+ */
1237
+ function createInput(value?: string, type?: string): HTMLInputElement;
1238
+
1239
+ /** 📑
1240
+ * Creates a paragraph element.
1241
+ * @param {string} [content] text content
1242
+ * @example
1243
+ createCanvas(200, 50);
1244
+ background('coral');
1245
+
1246
+ let p = createP('Hello, world!');
1247
+ p.style.color = 'pink';
1248
+ */
1249
+ function createP(content?: string): HTMLParagraphElement;
1250
+
1251
+ /** 📑
1252
+ * Creates a radio button group.
1253
+ *
1254
+ * Use the `option(label, value)` function to add new radio buttons
1255
+ * to the group.
1256
+ *
1257
+ * Use the `value` property to get or set the value of the selected radio button.
1258
+ * @param {string} [groupName]
1259
+ * @example
1260
+ createCanvas(200, 100);
1261
+
1262
+ let radio = createRadio()
1263
+ .option('square', '1')
1264
+ .option('circle', '2');
1265
+ radio.style.color = 'aqua';
1266
+
1267
+ function draw() {
1268
+ background(200);
1269
+ if (radio.value == '1') square(75, 25, 50);
1270
+ if (radio.value == '2') circle(100, 50, 50);
1271
+ }
1272
+ */
1273
+ function createRadio(groupName): HTMLDivElement;
1274
+
1275
+ /** 📑
1276
+ * Creates a select element.
1277
+ *
1278
+ * Use the `option(label, value)` function to add new options to
1279
+ * the select element.
1280
+ *
1281
+ * Set `multiple` to `true` to allow multiple options to be selected.
1282
+ *
1283
+ * Use the `value` property to get or set the selected option.
1284
+ *
1285
+ * Use the `selected` property to get the selected option or options.
1286
+ * @param {boolean} [placeholder] optional placeholder text that appears when no option is selected
1287
+ * @example
1288
+ createCanvas(200, 100);
1289
+
1290
+ let sel = createSelect('Select a color')
1291
+ .option('Red', '#f55')
1292
+ .option('Green', '#5f5');
1293
+
1294
+ sel.addEventListener('change', () => {
1295
+ background(sel.value);
1296
+ });
1297
+ */
1298
+ function createSelect(placeholder): HTMLSelectElement;
1299
+
1300
+ /** 📑
1301
+ * Creates a slider element.
1302
+ *
1303
+ * Use the `value` property to get or set the slider's value.
1304
+ *
1305
+ * Use the `val` function to get the slider's value as a number.
1306
+ * @param {number} min minimum value
1307
+ * @param {number} max maximum value
1308
+ * @param {number} [value] initial value
1309
+ * @param {number} [step] step size
1310
+ * @example
1311
+ createCanvas(200);
1312
+
1313
+ let slider = createSlider(0, 255)
1314
+ .position(10, 10)
1315
+ .size(180);
1316
+
1317
+ function draw() {
1318
+ background(slider.val());
1319
+ }
1320
+ */
1321
+ function createSlider(min: number, max: number, value?: number, step?: number): HTMLInputElement;
1322
+
1323
+ /** 📑
1324
+ * Creates a video element.
1325
+ * @param {string} src url of the video
1326
+ * @example
1327
+ createCanvas(200, 100);
1328
+
1329
+ // let vid = createVideo('/assets/q5js_video.mp4');
1330
+ // vid.controls = true;
1331
+ // vid.loop = true;
1332
+ */
1333
+ function createVideo(src: string): HTMLVideoElement;
1334
+
1046
1335
  // 🌆 image
1047
1336
 
1048
1337
  /** 🌆
@@ -1051,7 +1340,7 @@ function draw() {
1051
1340
  * @param {(img: any) => void} [cb] callback function after the image is loaded
1052
1341
  * @param {any} [opt] optional parameters for loading the image
1053
1342
  * @example
1054
- createCanvas(200, 200);
1343
+ createCanvas(200);
1055
1344
 
1056
1345
  let logo = loadImage('/q5js_logo.webp');
1057
1346
 
@@ -1073,7 +1362,7 @@ function draw() {
1073
1362
  * @param {number} [sw] width of the subsection of the source image
1074
1363
  * @param {number} [sh] height of the subsection of the source image
1075
1364
  * @example
1076
- createCanvas(200, 200);
1365
+ createCanvas(200);
1077
1366
 
1078
1367
  let logo = loadImage('/q5js_logo.webp');
1079
1368
 
@@ -1090,7 +1379,7 @@ function draw() {
1090
1379
  * `CENTER`: images will be drawn centered at (dx, dy)
1091
1380
  * @param {string} mode
1092
1381
  * @example
1093
- createCanvas(200, 200);
1382
+ createCanvas(200);
1094
1383
 
1095
1384
  let logo = loadImage('/q5js_logo.webp');
1096
1385
 
@@ -1121,7 +1410,7 @@ function draw() {
1121
1410
  * @param {number} w new width
1122
1411
  * @param {number} h new height
1123
1412
  * @example
1124
- createCanvas(200, 200);
1413
+ createCanvas(200);
1125
1414
 
1126
1415
  let logo = loadImage('/q5js_logo.webp');
1127
1416
 
@@ -1143,7 +1432,7 @@ function setup() {
1143
1432
  * their actual size. This is the default setting, so running this
1144
1433
  * function only has an effect if `noSmooth` has been called.
1145
1434
  * @example
1146
- createCanvas(200, 200);
1435
+ createCanvas(200);
1147
1436
 
1148
1437
  let icon = loadImage('/q5js_icon.png');
1149
1438
 
@@ -1156,7 +1445,7 @@ function setup() {
1156
1445
  /** 🌆
1157
1446
  * Disables smooth image rendering for a pixelated look.
1158
1447
  * @example
1159
- createCanvas(200, 200);
1448
+ createCanvas(200);
1160
1449
 
1161
1450
  let icon = loadImage('/q5js_icon.png');
1162
1451
 
@@ -1187,7 +1476,7 @@ function setup() {
1187
1476
  * each copy separately.
1188
1477
  * @param {string | number} color tint color
1189
1478
  * @example
1190
- createCanvas(200, 200);
1479
+ createCanvas(200);
1191
1480
 
1192
1481
  let logo = loadImage('/q5js_logo.webp');
1193
1482
 
@@ -1226,7 +1515,7 @@ function setup() {
1226
1515
  * @param {number} [h] height of the area
1227
1516
  * @returns {Image | number[]}
1228
1517
  * @example
1229
- createCanvas(200, 200);
1518
+ createCanvas(200);
1230
1519
 
1231
1520
  let logo = loadImage('/q5js_logo.webp');
1232
1521
 
@@ -1248,7 +1537,7 @@ function setup() {
1248
1537
  * @param {number} y
1249
1538
  * @param {any} c color, canvas, or image
1250
1539
  * @example
1251
- createCanvas(200, 200);
1540
+ createCanvas(200);
1252
1541
  let c = color('lime');
1253
1542
 
1254
1543
  function draw() {
@@ -1276,7 +1565,7 @@ function draw() {
1276
1565
  * @param {number} dw width of the destination region
1277
1566
  * @param {number} dh height of the destination region
1278
1567
  * @example
1279
- createCanvas(200, 200);
1568
+ createCanvas(200);
1280
1569
 
1281
1570
  let logo = loadImage('/q5js_logo.webp');
1282
1571
 
@@ -1295,7 +1584,7 @@ function setup() {
1295
1584
  /** 🌆
1296
1585
  * Loads pixel data into the canvas' or image's `pixels` array.
1297
1586
  * @example
1298
- createCanvas(200, 200);
1587
+ createCanvas(200);
1299
1588
  let icon = loadImage('/q5js_icon.png');
1300
1589
 
1301
1590
  function setup() {
@@ -1310,7 +1599,7 @@ function setup() {
1310
1599
  /** 🌆
1311
1600
  * Applies changes in the `pixels` array to the canvas or image.
1312
1601
  * @example
1313
- createCanvas(200, 200);
1602
+ createCanvas(200);
1314
1603
  function setup() {
1315
1604
  for (let x = 0; x < 200; x += 5) {
1316
1605
  for (let y = 0; y < 200; y += 5) {
@@ -1338,7 +1627,7 @@ function setup() {
1338
1627
  * @param {string} type filter type or a CSS filter string
1339
1628
  * @param {number} [value] optional value, depends on filter type
1340
1629
  * @example
1341
- createCanvas(200, 200);
1630
+ createCanvas(200);
1342
1631
  let logo = loadImage('/q5js_logo.webp');
1343
1632
 
1344
1633
  function setup() {
@@ -1401,29 +1690,29 @@ function setup() {
1401
1690
 
1402
1691
  /** ✍️
1403
1692
  * Renders text to the screen. Text can be positioned with the x and y
1404
- * parameters and can optionally be constrained by a character limit
1405
- * per line and a line limit.
1693
+ * parameters and can optionally be constrained.
1406
1694
  * @param {string} str string of text to display
1407
1695
  * @param {number} x x-coordinate of the text's position
1408
1696
  * @param {number} y y-coordinate of the text's position
1409
- * @param {number} [w] character limit per line
1410
- * @param {number} [h] line limit
1697
+ * @param {number} [wrapWidth] maximum line width in characters
1698
+ * @param {number} [lineLimit] maximum number of lines
1411
1699
  * @example
1412
- createCanvas(200, 200);
1700
+ createCanvas(200);
1413
1701
  background('silver');
1414
1702
 
1415
1703
  textSize(32);
1416
1704
  text('Hello, world!', 12, 106);
1417
1705
  * @example
1418
- createCanvas(200, 200);
1706
+ createCanvas(200);
1419
1707
  background(200);
1420
1708
  textSize(20);
1421
1709
 
1422
1710
  let info = "q5.js is a JavaScript library for creative coding. It's a sequel to p5.js that's optimized for interactive art.";
1423
1711
 
1424
1712
  text(info, 12, 30, 20, 6);
1713
+ //
1425
1714
  */
1426
- function text(str: string, x: number, y: number, w?: number, h?: number): void;
1715
+ function text(str: string, x: number, y: number, wrapWidth?: number, lineLimit?: number): void;
1427
1716
 
1428
1717
  /** ✍️
1429
1718
  * Loads a font from a URL and optionally runs a callback function
@@ -1444,7 +1733,7 @@ text(info, 12, 30, 20, 6);
1444
1733
  * @param {(font: FontFace) => void} [cb] optional callback function that receives the font name as an argument once the font is loaded
1445
1734
  * @returns {FontFace} font
1446
1735
  * @example
1447
- createCanvas(200, 200);
1736
+ createCanvas(200);
1448
1737
 
1449
1738
  loadFont('/assets/Robotica.ttf');
1450
1739
 
@@ -1467,7 +1756,7 @@ function setup() {
1467
1756
  * https://developer.mozilla.org/docs/Web/CSS/font-family
1468
1757
  * @param {string} fontName name of the font family or a FontFace object
1469
1758
  * @example
1470
- createCanvas(200, 200);
1759
+ createCanvas(200);
1471
1760
  background(200);
1472
1761
 
1473
1762
  textFont('serif');
@@ -1510,7 +1799,7 @@ function draw() {
1510
1799
  * Sets the current text style.
1511
1800
  * @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
1512
1801
  * @example
1513
- createCanvas(200, 200);
1802
+ createCanvas(200);
1514
1803
  background(200);
1515
1804
 
1516
1805
  textStyle(ITALIC);
@@ -1525,7 +1814,7 @@ text('Hello, world!', 12, 106);
1525
1814
  * @param {'left' | 'center' | 'right'} horiz horizontal alignment
1526
1815
  * @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
1527
1816
  * @example
1528
- createCanvas(200, 200);
1817
+ createCanvas(200);
1529
1818
  background(200);
1530
1819
 
1531
1820
  textAlign(CENTER, MIDDLE);
@@ -1570,7 +1859,7 @@ function draw() {
1570
1859
  * @param {string} str string to measure
1571
1860
  * @returns {number} descent of the text in pixels
1572
1861
  * @example
1573
- createCanvas(200, 200);
1862
+ createCanvas(200);
1574
1863
  background(200);
1575
1864
  textSize(64);
1576
1865
 
@@ -1580,15 +1869,13 @@ createCanvas(200, 200);
1580
1869
  function textDescent(str: string): number;
1581
1870
 
1582
1871
  /** ✍️
1583
- * Creates an image from a string of text. Width and height
1584
- * will not be the width and height of the text image, but of
1585
- * the bounding box that the text will be constrained within.
1872
+ * Creates an image from a string of text.
1586
1873
  * @param {string} str string of text
1587
- * @param {number} w width of the bounding box
1588
- * @param {number} h height of the bounding box
1874
+ * @param {number} [wrapWidth] maximum line width in characters
1875
+ * @param {number} [lineLimit] maximum number of lines
1589
1876
  * @returns {Q5.Image} an image object representing the rendered text
1590
1877
  */
1591
- function createTextImage(str: string, w: number, h: number): Q5.Image;
1878
+ function createTextImage(str: string, wrapWidth: number, lineLimit: number): Q5.Image;
1592
1879
 
1593
1880
  /** ✍️
1594
1881
  * Renders an image generated from text onto the canvas. The
@@ -1672,27 +1959,49 @@ createCanvas(200, 200);
1672
1959
  // 🎨 color
1673
1960
 
1674
1961
  /** 🎨
1675
- * Creates a new `Color` object. This function can parse different
1676
- * color representations depending on the current color mode.
1962
+ * Creates a new `Color` object, which is primarily useful for storing
1963
+ * a color that your sketch will reuse or modify later.
1677
1964
  *
1678
- * RGB colors have components `r`/`red`, `g`/`green`, `b`/`blue`,
1679
- * and `a`/`alpha`.
1965
+ * With the default RGB color mode, colors have these components:
1966
+ *
1967
+ * `r`/`red`, `g`/`green`, `b`/`blue`, and `a`/`alpha`.
1968
+ *
1969
+ * The default color format is integer, so set color components
1970
+ * to values between 0 and 255.
1680
1971
  *
1681
- * When only one numeric input is provided, it'll be interpreted
1682
- * as a grayscale value. If only two numeric inputs are provided,
1683
- * they will be used as grayscale and alpha values.
1972
+ * In q5 WebGPU, the default color mode is RGB in float format, so
1973
+ * set color components to values between 0 and 1.
1684
1974
  *
1685
- * `fill`, `stroke`, and `background` functions can accept the same
1686
- * wide range of inputs as this function.
1687
- * @param {string | number | Color | number[]} c0 first color component, a CSS color string, a `Color` object (to make copy), or an array of components
1975
+ * The [`fill`](https://q5js.org/learn/#fill), [`stroke`](https://q5js.org/learn/#stroke), and [`background`](https://q5js.org/learn/#background) functions
1976
+ * accept the same wide range of color representations as this function.
1977
+ *
1978
+ * Here are some examples of valid use:
1979
+ *
1980
+ * - `color(255)` (grayscale)
1981
+ * - `color(255, 200)` (grayscale, alpha)
1982
+ * - `color(255, 0, 0)` (r, g, b)
1983
+ * - `color(255, 0, 0, 10)` (r, g, b, a)
1984
+ * - `color('red')` (colorName)
1985
+ * - `color('#ff0000')` (hexColor)
1986
+ * - `color([255, 0, 0])` (colorComponents)
1987
+ * @param {string | number | Color | number[]} c0 color or first color component
1688
1988
  * @param {number} [c1] second color component
1689
1989
  * @param {number} [c2] third color component
1690
1990
  * @param {number} [c3] fourth color component (alpha)
1691
1991
  * @returns {Color} a new `Color` object
1692
1992
  * @example
1693
- createCanvas(200, 200);
1993
+ createCanvas(200);
1994
+ // (gray, alpha)
1995
+ let darkGray = color(55, 100);
1996
+ background(darkGray);
1997
+ // (r, g, b, a)
1998
+ let blueBottle = color(0, 0, 200, 20);
1999
+ fill(blueBottle);
2000
+ circle(100, 50, 50);
2001
+ * @example
2002
+ createCanvas(200);
1694
2003
 
1695
- let c = color(128);
2004
+ let c = color('gray');
1696
2005
 
1697
2006
  function draw() {
1698
2007
  background(c);
@@ -1712,7 +2021,7 @@ function draw() {
1712
2021
  * @param {'rgb' | 'srgb' | 'oklch'} mode color mode
1713
2022
  * @param {1 | 255} format color format (1 for float, 255 for integer)
1714
2023
  * @example
1715
- createCanvas(200, 200);
2024
+ createCanvas(200);
1716
2025
 
1717
2026
  colorMode(RGB, 1);
1718
2027
  fill(1, 0, 0);
@@ -1722,7 +2031,7 @@ rect(66, 0, 67, 200);
1722
2031
  fill(0, 0, 1);
1723
2032
  rect(133, 0, 67, 200);
1724
2033
  * @example
1725
- createCanvas(200, 200);
2034
+ createCanvas(200);
1726
2035
 
1727
2036
  colorMode(OKLCH);
1728
2037
 
@@ -1743,7 +2052,7 @@ rect(100, 0, 100, 200);
1743
2052
  * rgb colors are mapped to the full P3 gamut, even when they use the
1744
2053
  * legacy integer format.
1745
2054
  * @example
1746
- createCanvas(200, 200);
2055
+ createCanvas(200);
1747
2056
 
1748
2057
  function setup() {
1749
2058
  background(255, 0, 0);
@@ -1758,7 +2067,7 @@ function setup() {
1758
2067
  * example, note that full red appears less saturated, as it would
1759
2068
  * on an SDR display.
1760
2069
  * @example
1761
- createCanvas(200, 200);
2070
+ createCanvas(200);
1762
2071
 
1763
2072
  colorMode(SRGB, 255);
1764
2073
 
@@ -1792,7 +2101,7 @@ function setup() {
1792
2101
  *
1793
2102
  * Note how seamless the hue transitions are in the following example.
1794
2103
  * @example
1795
- createCanvas(200, 200);
2104
+ createCanvas(200);
1796
2105
  colorMode(OKLCH);
1797
2106
 
1798
2107
  function draw() {
@@ -1851,7 +2160,7 @@ function draw() {
1851
2160
  * True if the mouse is currently pressed, false otherwise.
1852
2161
  * @example
1853
2162
  function draw() {
1854
- if (mouseIsPressed) background(0);
2163
+ if (mouseIsPressed) background(100);
1855
2164
  else background(200);
1856
2165
  }
1857
2166
  */
@@ -1872,7 +2181,7 @@ function draw() {
1872
2181
  * True if a key is currently pressed, false otherwise.
1873
2182
  * @example
1874
2183
  function draw() {
1875
- if (keyIsPressed) background(0);
2184
+ if (keyIsPressed) background(100);
1876
2185
  else background(200);
1877
2186
  }
1878
2187
  */
@@ -1894,13 +2203,8 @@ function draw() {
1894
2203
  function keyIsDown(key: string): boolean;
1895
2204
 
1896
2205
  /** 🖲️
1897
- * The keyCode of the last key pressed.
1898
- * @deprecated
1899
- */
1900
- let keyCode: number;
1901
-
1902
- /** 🖲️
1903
- * Array of current touches, each touch being an object with x, y, id, etc.
2206
+ * Array of current touches, each touch being an object with
2207
+ * id, x, and y properties.
1904
2208
  */
1905
2209
  let touches: any[];
1906
2210
 
@@ -1917,7 +2221,7 @@ function draw() {
1917
2221
  /** 🖲️
1918
2222
  * Hides the cursor within the bounds of the canvas.
1919
2223
  * @example
1920
- createCanvas(200, 200);
2224
+ createCanvas(200);
1921
2225
  noCursor();
1922
2226
  */
1923
2227
  function noCursor(): void;
@@ -2123,7 +2427,7 @@ noCursor();
2123
2427
  * @param {string} url sound file
2124
2428
  * @returns {Sound} a new `Sound` object
2125
2429
  * @example
2126
- createCanvas(200, 200);
2430
+ createCanvas(200);
2127
2431
 
2128
2432
  let sound = loadSound('/assets/jump.wav');
2129
2433
  sound.volume = 0.3;
@@ -2144,7 +2448,7 @@ function mousePressed() {
2144
2448
  * @param url audio file
2145
2449
  * @returns {HTMLAudioElement} an HTMLAudioElement
2146
2450
  * @example
2147
- createCanvas(200, 200);
2451
+ createCanvas(200);
2148
2452
 
2149
2453
  let audio = loadAudio('/assets/retro.flac');
2150
2454
  audio.volume = 0.4;
@@ -2170,10 +2474,63 @@ function mousePressed() {
2170
2474
  class Sound {
2171
2475
  /** 🔊
2172
2476
  * Creates a new `Q5.Sound` object.
2173
- *
2174
- * See the `loadSound` documentation for more info.
2175
2477
  */
2176
2478
  constructor();
2479
+
2480
+ /** 🔊
2481
+ * Set the sound's volume to a value between
2482
+ * 0 (silent) and 1 (full volume).
2483
+ */
2484
+ volume: number;
2485
+
2486
+ /** 🔊
2487
+ * Set the sound's stereo position between -1 (left) and 1 (right).
2488
+ */
2489
+ pan: number;
2490
+
2491
+ /** 🔊
2492
+ * Set to true to make the sound loop continuously.
2493
+ */
2494
+ loop: boolean;
2495
+
2496
+ /** 🔊
2497
+ * True if the sound data has finished loading.
2498
+ */
2499
+ loaded: boolean;
2500
+
2501
+ /** 🔊
2502
+ * True if the sound is currently paused.
2503
+ */
2504
+ paused: boolean;
2505
+
2506
+ /** 🔊
2507
+ * True if the sound has finished playing.
2508
+ */
2509
+ ended: boolean;
2510
+
2511
+ /** 🔊
2512
+ * Plays the sound.
2513
+ *
2514
+ * If this function is run when the sound is already playing,
2515
+ * a new playback will start, causing a layering effect.
2516
+ *
2517
+ * If this function is run when the sound is paused,
2518
+ * all playback instances will be resumed.
2519
+ */
2520
+ play(): void;
2521
+
2522
+ /** 🔊
2523
+ * Pauses the sound, allowing it to be resumed.
2524
+ */
2525
+ pause(): void;
2526
+
2527
+ /** 🔊
2528
+ * Stops the sound, resetting its playback position
2529
+ * to the beginning.
2530
+ *
2531
+ * Removes all playback instances.
2532
+ */
2533
+ stop(): void;
2177
2534
  }
2178
2535
 
2179
2536
  // 🛠️ utilities
@@ -2200,7 +2557,7 @@ function draw() {
2200
2557
  }
2201
2558
  * @example
2202
2559
  new Q5();
2203
- createCanvas(200, 200);
2560
+ createCanvas(200);
2204
2561
 
2205
2562
  // use with top level await in a module
2206
2563
  await load('/assets/Robotica.ttf');
@@ -2209,7 +2566,7 @@ background(255);
2209
2566
  text('Hello, world!', 20, 100);
2210
2567
  * @example
2211
2568
  let q = new Q5();
2212
- createCanvas(200, 200);
2569
+ createCanvas(200);
2213
2570
 
2214
2571
  let [jump, retro] = await load(
2215
2572
  '/assets/jump.wav', '/assets/retro.flac'