q5 3.3.3 → 3.4.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 +1 -1
  3. package/q5.d.ts +278 -373
  4. package/q5.js +54 -16
  5. package/q5.min.js +2 -2
package/q5.d.ts CHANGED
@@ -19,66 +19,17 @@ declare global {
19
19
  /** ⭐️
20
20
  * The draw function is run 60 times per second by default.
21
21
  * @example
22
- function draw() {
22
+ Q5.draw = function () {
23
23
  background('silver');
24
24
  circle(frameCount % 200, 100, 80);
25
25
  }
26
26
  */
27
27
  function draw(): void;
28
28
 
29
- /** ⭐️
30
- * The setup function is run once, when the program starts.
31
- *
32
- * It can also be defined as an async function and used to load assets.
33
- * @example
34
- function setup() {
35
- createCanvas(200, 100);
36
- background('aqua');
37
- }
38
- * @example
39
- let logo;
40
-
41
- async function setup() {
42
- logo = await loadImage('/q5js_logo.avif');
43
- }
44
-
45
- function draw() {
46
- background(logo);
47
- }
48
- */
49
- function setup(): void;
50
-
51
- /** ⭐️
52
- * Load assets in the preload function to ensure that they'll be
53
- * ready to use in the setup and draw functions.
54
- *
55
- * q5's preload system can also be used without a preload function
56
- * if you create a canvas first, as shown in the second example.
57
- * @example
58
- let logo;
59
-
60
- function preload() {
61
- logo = loadImage('/q5js_logo.avif');
62
- }
63
-
64
- function draw() {
65
- background(logo);
66
- }
67
- * @example
68
- createCanvas(200, 100);
69
-
70
- let logo = loadImage('/q5js_logo.avif');
71
-
72
- function draw() {
73
- background(logo);
74
- }
75
- */
76
- function preload(): void;
77
-
78
29
  /** ⭐️
79
30
  * The number of frames that have been displayed since the program started.
80
31
  * @example
81
- function draw() {
32
+ Q5.draw = function () {
82
33
  background(200);
83
34
  textSize(64);
84
35
  text(frameCount, 8, 120);
@@ -89,7 +40,7 @@ function draw() {
89
40
  /** ⭐️
90
41
  * Stops the draw loop.
91
42
  * @example
92
- function draw() {
43
+ Q5.draw = function () {
93
44
  circle(frameCount * 5, 100, 80);
94
45
  noLoop();
95
46
  }
@@ -103,13 +54,13 @@ function draw() {
103
54
  * This is an async function.
104
55
  * @param {number} [n] number of times to redraw the canvas, default is 1
105
56
  * @example
106
- createCanvas(200);
57
+ await createCanvas(200);
107
58
  noLoop();
108
59
 
109
- function draw() {
60
+ Q5.draw = function () {
110
61
  circle(frameCount * 5, 100, 80);
111
62
  }
112
- function mousePressed() {
63
+ Q5.mousePressed = function () {
113
64
  redraw(10);
114
65
  }
115
66
  */
@@ -118,13 +69,13 @@ function mousePressed() {
118
69
  /** ⭐️
119
70
  * Starts the draw loop again if it was stopped.
120
71
  * @example
121
- createCanvas(200);
72
+ await createCanvas(200);
122
73
  noLoop();
123
74
 
124
- function draw() {
75
+ Q5.draw = function () {
125
76
  circle(frameCount * 5, 100, 80);
126
77
  }
127
- function mousePressed() {
78
+ Q5.mousePressed = function () {
128
79
  loop();
129
80
  }
130
81
  */
@@ -140,7 +91,7 @@ function mousePressed() {
140
91
  * @param {number} [hertz] target frame rate, default is 60
141
92
  * @returns {number} current frame rate
142
93
  * @example
143
- function draw() {
94
+ Q5.draw = function () {
144
95
  background(200);
145
96
 
146
97
  if (mouseIsPressed) frameRate(10);
@@ -149,7 +100,7 @@ function draw() {
149
100
  circle(frameCount % 200, 100, 80);
150
101
  }
151
102
  * @example
152
- function draw() {
103
+ Q5.draw = function () {
153
104
  background(200);
154
105
  textSize(64);
155
106
  text(round(frameRate()), 65, 120);
@@ -161,7 +112,7 @@ function draw() {
161
112
  * The desired frame rate of the sketch.
162
113
  * @returns {number} target frame rate
163
114
  * @example
164
- function draw() {
115
+ Q5.draw = function () {
165
116
  background(200);
166
117
  textSize(64);
167
118
 
@@ -178,7 +129,7 @@ function draw() {
178
129
  * performance analysis.
179
130
  * @returns {number} frames per second
180
131
  * @example
181
- function draw() {
132
+ Q5.draw = function () {
182
133
  background(200);
183
134
  frameRate(1);
184
135
  textSize(64);
@@ -207,12 +158,12 @@ function draw() {
207
158
  * addons like p5play that auto-draw to the canvas after the `draw`
208
159
  * function is run.
209
160
  * @example
210
- function draw() {
161
+ Q5.draw = function () {
211
162
  background(200);
212
163
  circle(frameCount % 200, 100, 80);
213
164
  }
214
165
 
215
- function postProcess() {
166
+ Q5.postProcess = function () {
216
167
  filter(INVERT);
217
168
  }
218
169
  */
@@ -221,7 +172,7 @@ function postProcess() {
221
172
  /** ⭐️
222
173
  * The width of the window.
223
174
  * @example
224
- function draw() {
175
+ Q5.draw = function () {
225
176
  background(200);
226
177
  textSize(64);
227
178
  textAlign(CENTER, CENTER);
@@ -233,7 +184,7 @@ function draw() {
233
184
  /** ⭐️
234
185
  * The height of the window.
235
186
  * @example
236
- function draw() {
187
+ Q5.draw = function () {
237
188
  background(200);
238
189
  textSize(64);
239
190
  textAlign(CENTER, CENTER);
@@ -253,13 +204,13 @@ function draw() {
253
204
  * rates are consistently low, consider reducing the target frame
254
205
  * rate instead.
255
206
  * @example
256
- function draw() {
207
+ Q5.draw = function () {
257
208
  background(200);
258
209
  text(deltaTime, 60, 106);
259
210
  }
260
211
  * @example
261
212
  let x = 0;
262
- function draw() {
213
+ Q5.draw = function () {
263
214
  background(200);
264
215
  // simulate frame rate drops
265
216
  frameRate(random(30, 60));
@@ -287,7 +238,7 @@ function draw() {
287
238
  *
288
239
  * @param {boolean} [val] Whether load* functions should return promises or not. If this parameter is undefined the value is set to true.
289
240
  * @example
290
- createCanvas(200);
241
+ await createCanvas(200);
291
242
 
292
243
  usePromiseLoading();
293
244
 
@@ -316,10 +267,6 @@ background(logo);
316
267
  * - "instance": does not add q5 functions or variables to the global scope
317
268
  * @param {HTMLElement} [parent] element that the canvas will be placed inside
318
269
  * @example
319
- new Q5();
320
- createCanvas(200, 100);
321
- circle(100, 50, 80);
322
- * @example
323
270
  let q = new Q5('instance');
324
271
  q.createCanvas(200, 100);
325
272
  q.circle(100, 50, 20);
@@ -372,18 +319,6 @@ q.circle(100, 50, 20);
372
319
  new(w: number, h: number, opt?: any): Q5.Image;
373
320
  }
374
321
 
375
- /** ⭐️
376
- * Creates a new Q5 instance that uses [q5's WebGPU renderer](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer).
377
- * @example
378
- let q = await Q5.WebGPU();
379
-
380
- q.draw = () => {
381
- background(0.8);
382
- circle(mouseX, 0, 80);
383
- };
384
- */
385
- static WebGPU(): Q5;
386
-
387
322
  /** ⭐️
388
323
  * ___Experimental! Might be changed.___
389
324
  *
@@ -403,7 +338,7 @@ Q5.registerAddon((Q5, proto, lifecycles) => {
403
338
  });
404
339
 
405
340
  // sketch.js
406
- createCanvas(200);
341
+ await createCanvas(200);
407
342
  */
408
343
  static registerAddon(addon: Function): void; //-
409
344
 
@@ -450,25 +385,26 @@ createCanvas(200);
450
385
  * by the user, a 200x200 canvas will be created automatically before
451
386
  * the draw loop starts.
452
387
  *
453
- * When using q5 WebGPU, create a canvas before using any other
454
- * q5 functions. The origin of a WebGPU canvas is at its center.
388
+ * You should create a canvas before using any other q5 functions
389
+ * in top level global mode.
390
+ *
391
+ * Note! The origin (0, 0) point on a WebGPU canvas is at its center!
455
392
  * @param {number} [w] width or size of the canvas
456
393
  * @param {number} [h] height of the canvas
457
394
  * @param {object} [opt] options for the canvas
458
395
  * @param {boolean} [opt.alpha] whether the canvas should have an alpha channel that allows it to be seen through, default is false
459
396
  * @param {string} [opt.colorSpace] color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
460
- * @returns {HTMLCanvasElement} created canvas element
397
+ * @returns {Promise<HTMLCanvasElement>} created canvas element
461
398
  * @example
462
- createCanvas(200, 100);
399
+ await createCanvas(200, 100);
463
400
  circle(100, 50, 80);
464
401
  * @example
465
- await Q5.WebGPU();
466
- createCanvas(200, 100);
402
+ await createCanvas(200, 100, GPU);
467
403
  circle(0, 0, 80);
468
404
  * @example
469
- createCanvas(200, 200, { alpha: true });
405
+ await createCanvas(200, 200, { alpha: true });
470
406
 
471
- function draw() {
407
+ Q5.draw = function () {
472
408
  clear();
473
409
  circle(frameCount % 200, 100, 80);
474
410
  }
@@ -478,9 +414,9 @@ function draw() {
478
414
  /** ⬜️
479
415
  * The canvas element associated with the Q5 instance.
480
416
  *
481
- * @prop {number} w
417
+ * @prop {number} w width
482
418
  * @prop {number} width
483
- * @prop {number} h
419
+ * @prop {number} h height
484
420
  * @prop {number} height
485
421
  * @prop {number} hw half the width
486
422
  * @prop {number} hh half the height
@@ -503,7 +439,7 @@ function draw() {
503
439
  * a `Color` object, grayscale value, or color component values.
504
440
  * @param {Color} color fill color
505
441
  * @example
506
- createCanvas(200);
442
+ await createCanvas(200);
507
443
  background(200);
508
444
 
509
445
  fill('red');
@@ -522,7 +458,7 @@ square(80, 80, 80);
522
458
  * a `Color` object, grayscale value, or color component values.
523
459
  * @param {Color} color stroke color
524
460
  * @example
525
- createCanvas(200);
461
+ await createCanvas(200);
526
462
  background(200);
527
463
  fill(36);
528
464
 
@@ -537,7 +473,7 @@ square(80, 80, 80);
537
473
  /** ⬜️
538
474
  * After calling this function, shapes will not be filled.
539
475
  * @example
540
- createCanvas(200);
476
+ await createCanvas(200);
541
477
  background(200);
542
478
 
543
479
  noFill();
@@ -552,7 +488,7 @@ square(80, 80, 80);
552
488
  /** ⬜️
553
489
  * After calling this function, shapes will not have a stroke (outline).
554
490
  * @example
555
- createCanvas(200);
491
+ await createCanvas(200);
556
492
  background(200);
557
493
  fill(36);
558
494
  stroke('red');
@@ -567,7 +503,7 @@ square(80, 80, 80);
567
503
  * Sets the size of the stroke used for lines and the border around shapes.
568
504
  * @param {number} weight size of the stroke in pixels
569
505
  * @example
570
- createCanvas(200);
506
+ await createCanvas(200);
571
507
  background(200);
572
508
  stroke('red');
573
509
  circle(50, 100, 80);
@@ -583,7 +519,7 @@ circle(150, 100, 80);
583
519
  * In q5 WebGPU this function only affects images.
584
520
  * @param {number} alpha opacity level, ranging from 0 to 1
585
521
  * @example
586
- createCanvas(200);
522
+ await createCanvas(200);
587
523
  background(200);
588
524
 
589
525
  opacity(1);
@@ -607,21 +543,19 @@ square(80, 80, 80);
607
543
  * Not available in q5 WebGPU.
608
544
  * @param {Color} color shadow color
609
545
  * @example
610
- createCanvas(200);
546
+ await createCanvas(200);
611
547
  background(200);
612
548
 
613
549
  noFill();
614
550
  shadow('black');
615
551
  rect(64, 60, 80, 80);
616
552
  * @example
617
- createCanvas(200);
618
- let logo = loadImage('/assets/p5play_logo.webp');
553
+ await createCanvas(200);
554
+ let logo = await load('/assets/p5play_logo.webp');
619
555
 
620
- function setup() {
621
- background(200);
622
- shadow(0);
623
- image(logo, 36, 36, 128, 128);
624
- }
556
+ background(200);
557
+ shadow(0);
558
+ image(logo, 36, 36, 128, 128);
625
559
  */
626
560
  function shadow(color: string | Color): void;
627
561
 
@@ -630,7 +564,7 @@ function setup() {
630
564
  *
631
565
  * Not available in q5 WebGPU.
632
566
  * @example
633
- createCanvas(200);
567
+ await createCanvas(200);
634
568
  background(200);
635
569
  noStroke();
636
570
  shadow('black');
@@ -652,17 +586,17 @@ rect(104, 104, 80, 80);
652
586
  * @param {number} offsetY vertical offset of the shadow, defaults to be the same as offsetX
653
587
  * @param {number} blur blur radius of the shadow, defaults to 0
654
588
  * @example
655
- createCanvas(200);
589
+ await createCanvas(200);
656
590
  noStroke();
657
591
  shadow(50);
658
592
 
659
- function draw() {
593
+ Q5.draw = function () {
660
594
  background(200);
661
595
  shadowBox(-20, mouseY, 10);
662
596
  circle(100, 100, 80, 80);
663
597
  }
664
598
  * @example
665
- createCanvas(200);
599
+ await createCanvas(200);
666
600
  background(200);
667
601
  noStroke();
668
602
 
@@ -699,7 +633,7 @@ text('q5', 60, 115);
699
633
  * @param {number} x translation along the x-axis
700
634
  * @param {number} y translation along the y-axis
701
635
  * @example
702
- function draw() {
636
+ Q5.draw = function () {
703
637
  background(200);
704
638
 
705
639
  translate(100, 100);
@@ -712,7 +646,7 @@ function draw() {
712
646
  * Rotates the drawing context.
713
647
  * @param {number} angle rotation angle in radians
714
648
  * @example
715
- function draw() {
649
+ Q5.draw = function () {
716
650
  background(200);
717
651
 
718
652
  translate(100, 100);
@@ -732,7 +666,7 @@ function draw() {
732
666
  * @param {number} x scaling factor along the x-axis
733
667
  * @param {number} [y] scaling factor along the y-axis
734
668
  * @example
735
- function draw() {
669
+ Q5.draw = function () {
736
670
  background(200);
737
671
 
738
672
  scale(4);
@@ -745,7 +679,7 @@ function draw() {
745
679
  * Shears the drawing context along the x-axis.
746
680
  * @param {number} angle shear angle in radians
747
681
  * @example
748
- function draw() {
682
+ Q5.draw = function () {
749
683
  background(200);
750
684
 
751
685
  translate(25, 60);
@@ -759,7 +693,7 @@ function draw() {
759
693
  * Shears the drawing context along the y-axis.
760
694
  * @param {number} angle shear angle in radians
761
695
  * @example
762
- function draw() {
696
+ Q5.draw = function () {
763
697
  background(200);
764
698
 
765
699
  translate(25, 60);
@@ -784,7 +718,7 @@ function draw() {
784
718
  * @param {number} e horizontal moving
785
719
  * @param {number} f vertical moving
786
720
  * @example
787
- function draw() {
721
+ Q5.draw = function () {
788
722
  background(200);
789
723
 
790
724
  applyMatrix(2, 1, 1, 1, 100, 100);
@@ -799,7 +733,7 @@ function draw() {
799
733
  * q5 runs this function before every time the `draw` function is run,
800
734
  * so that transformations don't carry over to the next frame.
801
735
  * @example
802
- createCanvas(200);
736
+ await createCanvas(200);
803
737
  background(200);
804
738
 
805
739
  translate(100, 100);
@@ -813,7 +747,7 @@ square(0, 0, 50);
813
747
  /** ⬜️
814
748
  * Saves the current transformation matrix.
815
749
  * @example
816
- createCanvas(200);
750
+ await createCanvas(200);
817
751
  background(200);
818
752
  translate(100, 100);
819
753
  pushMatrix();
@@ -827,7 +761,7 @@ ellipse(0, 0, 120, 40);
827
761
  /** ⬜️
828
762
  * Restores the previously saved transformation matrix.
829
763
  * @example
830
- createCanvas(200);
764
+ await createCanvas(200);
831
765
  background(200);
832
766
  translate(100, 100);
833
767
  pushMatrix();
@@ -845,7 +779,7 @@ ellipse(0, 0, 120, 40);
845
779
  * rect mode, ellipse mode, text size, text align, text baseline, and
846
780
  * shadow settings.
847
781
  * @example
848
- function draw() {
782
+ Q5.draw = function () {
849
783
  background(200);
850
784
 
851
785
  pushStyles();
@@ -865,7 +799,7 @@ function draw() {
865
799
  /** ⬜️
866
800
  * Saves the current drawing style settings and transformations.
867
801
  * @example
868
- createCanvas(200);
802
+ await createCanvas(200);
869
803
 
870
804
  push();
871
805
  fill('blue');
@@ -955,7 +889,7 @@ square(0, 0, 50);
955
889
  * @param {number} [c3] fourth color component (alpha)
956
890
  * @returns {Color} a new `Color` object
957
891
  * @example
958
- createCanvas(200);
892
+ await createCanvas(200);
959
893
  rect(0, 0, 100, 200);
960
894
 
961
895
  // ( r, g, b, a)
@@ -965,22 +899,22 @@ stroke(bottle);
965
899
  strokeWeight(30);
966
900
  circle(100, 100, 155);
967
901
  * @example
968
- createCanvas(200);
902
+ await createCanvas(200);
969
903
  // (gray, alpha)
970
904
  let c = color(200, 50);
971
905
 
972
- function draw() {
906
+ Q5.draw = function () {
973
907
  background(c);
974
908
  circle(mouseX, mouseY, 50);
975
909
  c.g = (c.g + 1) % 256;
976
910
  }
977
911
  * @example
978
- let q = await Q5.WebGPU();
912
+ await createCanvas(200, GPU);
979
913
 
980
914
  // (r, g, b, a)
981
915
  let c = color(0, 1, 1, 0.2);
982
916
 
983
- q.draw = () => {
917
+ Q5.draw = function () {
984
918
  fill(c);
985
919
  circle(mouseX, mouseY, 50);
986
920
  };
@@ -1001,7 +935,7 @@ q.draw = () => {
1001
935
  * @param {1 | 255} format color format (1 for float, 255 for integer)
1002
936
  * @param {'srgb' | 'display-p3'} [gamut] color gamut
1003
937
  * @example
1004
- createCanvas(200);
938
+ await createCanvas(200);
1005
939
 
1006
940
  colorMode(RGB, 1);
1007
941
  fill(1, 0, 0);
@@ -1011,7 +945,7 @@ rect(66, 0, 67, 200);
1011
945
  fill(0, 0, 1);
1012
946
  rect(133, 0, 67, 200);
1013
947
  * @example
1014
- createCanvas(200);
948
+ await createCanvas(200);
1015
949
 
1016
950
  colorMode(OKLCH);
1017
951
 
@@ -1031,7 +965,7 @@ rect(100, 0, 100, 200);
1031
965
  * rgb colors are mapped to the full P3 gamut, even when they use the
1032
966
  * legacy integer 0-255 format.
1033
967
  * @example
1034
- createCanvas(200, 100);
968
+ await createCanvas(200, 100);
1035
969
 
1036
970
  colorMode(RGB);
1037
971
 
@@ -1063,16 +997,16 @@ background(255, 0, 0);
1063
997
  * - `hue`: 0 to 360
1064
998
  * - `alpha`: 0 to 1
1065
999
  * @example
1066
- createCanvas(200, 100);
1000
+ await createCanvas(200, 100);
1067
1001
 
1068
1002
  colorMode(OKLCH);
1069
1003
 
1070
1004
  background(0.64, 0.3, 30);
1071
1005
  * @example
1072
- createCanvas(200);
1006
+ await createCanvas(200);
1073
1007
  colorMode(OKLCH);
1074
1008
 
1075
- function draw() {
1009
+ Q5.draw = function () {
1076
1010
  background(0.7, 0.16, frameCount % 360);
1077
1011
  }
1078
1012
  */
@@ -1098,13 +1032,13 @@ function draw() {
1098
1032
  * - `lightness`: 0 to 100
1099
1033
  * - `alpha`: 0 to 1
1100
1034
  * @example
1101
- createCanvas(200, 100);
1035
+ await createCanvas(200, 100);
1102
1036
 
1103
1037
  colorMode(HSL);
1104
1038
 
1105
1039
  background(0, 100, 50);
1106
1040
  * @example
1107
- createCanvas(200, 220);
1041
+ await createCanvas(200, 220);
1108
1042
  noStroke();
1109
1043
 
1110
1044
  colorMode(HSL);
@@ -1131,13 +1065,13 @@ for (let h = 0; h < 360; h += 10) {
1131
1065
  * - `brightness`: 0 to 100
1132
1066
  * - `alpha`: 0 to 1
1133
1067
  * @example
1134
- createCanvas(200, 100);
1068
+ await createCanvas(200, 100);
1135
1069
 
1136
1070
  colorMode(HSB);
1137
1071
 
1138
1072
  background(0, 100, 100);
1139
1073
  * @example
1140
- createCanvas(200, 220);
1074
+ await createCanvas(200, 220);
1141
1075
  noStroke();
1142
1076
 
1143
1077
  colorMode(HSB);
@@ -1157,7 +1091,7 @@ for (let h = 0; h < 360; h += 10) {
1157
1091
  * less saturated and darker in this example, as it would on
1158
1092
  * an SDR display.
1159
1093
  * @example
1160
- createCanvas(200, 100);
1094
+ await createCanvas(200, 100);
1161
1095
 
1162
1096
  colorMode(RGB, 255, SRGB);
1163
1097
 
@@ -1173,7 +1107,7 @@ background(255, 0, 0);
1173
1107
  * If your display is HDR capable, note that full red appears
1174
1108
  * fully saturated and bright in the following example.
1175
1109
  * @example
1176
- createCanvas(200, 100);
1110
+ await createCanvas(200, 100);
1177
1111
 
1178
1112
  colorMode(RGB, 255, DISPLAY_P3);
1179
1113
 
@@ -1229,7 +1163,7 @@ background(255, 0, 0);
1229
1163
  * - PIXELATED: pixels rendered as sharp squares
1230
1164
  * @param {number} scale can also be given as a string (for example "x2")
1231
1165
  * @example
1232
- createCanvas(50, 25);
1166
+ await createCanvas(50, 25);
1233
1167
 
1234
1168
  displayMode(CENTER, PIXELATED, 4);
1235
1169
 
@@ -1275,12 +1209,12 @@ circle(25, 12.5, 16);
1275
1209
  * CSS color string, grayscale value, and color component values.
1276
1210
  * @param {Color | Q5.Image} filler a color or image to draw
1277
1211
  * @example
1278
- createCanvas(200, 100);
1212
+ await createCanvas(200, 100);
1279
1213
  background('crimson');
1280
1214
  * @example
1281
- let q = await Q5.WebGPU();
1215
+ await createCanvas(200, GPU);
1282
1216
 
1283
- q.draw = () => {
1217
+ Q5.draw = function () {
1284
1218
  background(0.5, 0.4);
1285
1219
  circle(mouseX, mouseY, 20);
1286
1220
  };
@@ -1298,7 +1232,7 @@ q.draw = () => {
1298
1232
  * @param {number} [br] bottom-right radius
1299
1233
  * @param {number} [bl] bottom-left radius
1300
1234
  * @example
1301
- createCanvas(200);
1235
+ await createCanvas(200);
1302
1236
  background(200);
1303
1237
 
1304
1238
  rect(30, 20, 40, 60);
@@ -1317,7 +1251,7 @@ rect(130, 120, 40, 60, 30, 2, 8, 20);
1317
1251
  * @param {number} [br] bottom-right radius
1318
1252
  * @param {number} [bl] bottom-left radius
1319
1253
  * @example
1320
- createCanvas(200);
1254
+ await createCanvas(200);
1321
1255
  background(200);
1322
1256
 
1323
1257
  square(30, 30, 40);
@@ -1332,7 +1266,7 @@ square(130, 130, 40, 30, 2, 8, 20);
1332
1266
  * @param {number} y y-coordinate
1333
1267
  * @param {number} diameter diameter of the circle
1334
1268
  * @example
1335
- createCanvas(200, 100);
1269
+ await createCanvas(200, 100);
1336
1270
  circle(100, 50, 80);
1337
1271
  */
1338
1272
  function circle(x: number, y: number, diameter: number): void;
@@ -1344,7 +1278,7 @@ circle(100, 50, 80);
1344
1278
  * @param {number} width width of the ellipse
1345
1279
  * @param {number} [height] height of the ellipse
1346
1280
  * @example
1347
- createCanvas(200, 100);
1281
+ await createCanvas(200, 100);
1348
1282
  ellipse(100, 50, 160, 80);
1349
1283
  */
1350
1284
  function ellipse(x: number, y: number, width: number, height?: number): void;
@@ -1363,7 +1297,7 @@ ellipse(100, 50, 160, 80);
1363
1297
  * @param {number} stop angle to stop the arc
1364
1298
  * @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`
1365
1299
  * @example
1366
- createCanvas(200);
1300
+ await createCanvas(200);
1367
1301
  background(200);
1368
1302
 
1369
1303
  arc(40, 40, 40, 40, 0.8, -0.8);
@@ -1380,7 +1314,7 @@ arc(160, 160, 40, 40, 0.8, -0.8, CHORD);
1380
1314
  * @param {number} x2 x-coordinate of the second point
1381
1315
  * @param {number} y2 y-coordinate of the second point
1382
1316
  * @example
1383
- createCanvas(200, 100);
1317
+ await createCanvas(200, 100);
1384
1318
  stroke('lime');
1385
1319
  line(20, 20, 180, 80);
1386
1320
  */
@@ -1394,14 +1328,14 @@ line(20, 20, 180, 80);
1394
1328
  * @param {number} y2 y-coordinate of the second point
1395
1329
  * @param {number} r radius of the capsule semi-circle ends
1396
1330
  * @example
1397
- createCanvas(200, 100);
1331
+ await createCanvas(200, 100);
1398
1332
  background(200);
1399
1333
  strokeWeight(5);
1400
1334
  capsule(40, 40, 160, 60, 10);
1401
1335
  * @example
1402
- let q = await Q5.WebGPU();
1336
+ await createCanvas(200, GPU);
1403
1337
 
1404
- q.draw = () => {
1338
+ Q5.draw = function () {
1405
1339
  background(0.8);
1406
1340
  strokeWeight(10);
1407
1341
  capsule(0, 0, mouseX, mouseY, 20);
@@ -1414,7 +1348,7 @@ q.draw = () => {
1414
1348
  * @param {number} x x-coordinate
1415
1349
  * @param {number} y y-coordinate
1416
1350
  * @example
1417
- createCanvas(200, 100);
1351
+ await createCanvas(200, 100);
1418
1352
  stroke('white');
1419
1353
  point(75, 50);
1420
1354
 
@@ -1437,7 +1371,7 @@ point(125, 50);
1437
1371
  * Not available in q5 WebGPU.
1438
1372
  * @param {CanvasLineCap} val line cap style
1439
1373
  * @example
1440
- createCanvas(200);
1374
+ await createCanvas(200);
1441
1375
  background(200);
1442
1376
  strokeWeight(20);
1443
1377
 
@@ -1458,7 +1392,7 @@ line(50, 150, 150, 150);
1458
1392
  * Not available in q5 WebGPU.
1459
1393
  * @param {CanvasLineJoin} val line join style
1460
1394
  * @example
1461
- createCanvas(200);
1395
+ await createCanvas(200);
1462
1396
  background(200);
1463
1397
  strokeWeight(10);
1464
1398
 
@@ -1480,28 +1414,28 @@ triangle(50, 130, 150, 180, 50, 180);
1480
1414
  * `rect` and `square` are interpreted.
1481
1415
  * @param {string} mode
1482
1416
  * @example
1483
- createCanvas(200, 100);
1417
+ await createCanvas(200, 100);
1484
1418
  background(200);
1485
1419
  rectMode(CORNER);
1486
1420
 
1487
1421
  // ( x, y, w, h)
1488
1422
  rect(50, 25, 100, 50);
1489
1423
  * @example
1490
- createCanvas(200, 100);
1424
+ await createCanvas(200, 100);
1491
1425
  background(200);
1492
1426
  rectMode(CENTER);
1493
1427
 
1494
1428
  // ( cX, cY, w, h)
1495
1429
  rect(100, 50, 100, 50);
1496
1430
  * @example
1497
- createCanvas(200, 100);
1431
+ await createCanvas(200, 100);
1498
1432
  background(200);
1499
1433
  rectMode(RADIUS);
1500
1434
 
1501
1435
  // ( cX, cY, rX, rY)
1502
1436
  rect(100, 50, 50, 25);
1503
1437
  * @example
1504
- createCanvas(200, 100);
1438
+ await createCanvas(200, 100);
1505
1439
  background(200);
1506
1440
  rectMode(CORNERS);
1507
1441
 
@@ -1517,28 +1451,28 @@ rect(50, 25, 150, 75);
1517
1451
  * `ellipse`, `circle`, and `arc` are interpreted.
1518
1452
  * @param {string} mode
1519
1453
  * @example
1520
- createCanvas(200, 100);
1454
+ await createCanvas(200, 100);
1521
1455
  background(200);
1522
1456
  ellipseMode(CENTER);
1523
1457
 
1524
1458
  // ( x, y, w, h)
1525
1459
  ellipse(100, 50, 100, 50);
1526
1460
  * @example
1527
- createCanvas(200, 100);
1461
+ await createCanvas(200, 100);
1528
1462
  background(200);
1529
1463
  ellipseMode(RADIUS);
1530
1464
 
1531
1465
  // ( x, y, rX, rY)
1532
1466
  ellipse(100, 50, 50, 25);
1533
1467
  * @example
1534
- createCanvas(200, 100);
1468
+ await createCanvas(200, 100);
1535
1469
  background(200);
1536
1470
  ellipseMode(CORNER);
1537
1471
 
1538
1472
  // (lX, tY, w, h)
1539
1473
  ellipse(50, 25, 100, 50);
1540
1474
  * @example
1541
- createCanvas(200, 100);
1475
+ await createCanvas(200, 100);
1542
1476
  background(200);
1543
1477
  ellipseMode(CORNERS);
1544
1478
 
@@ -1717,20 +1651,20 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
1717
1651
  * @param {string} url url of the image to load
1718
1652
  * @returns {Q5.Image | Promise<Q5.Image>} image or promise
1719
1653
  * @example
1720
- createCanvas(200);
1654
+ await createCanvas(200);
1721
1655
 
1722
1656
  let logo = loadImage('/q5js_logo.avif');
1723
1657
 
1724
- function draw() {
1658
+ Q5.draw = function () {
1725
1659
  background(logo);
1726
1660
  }
1727
1661
  * @example
1728
- let q = await Q5.WebGPU();
1729
- createCanvas(200);
1662
+ await createCanvas(200, GPU);
1663
+ await createCanvas(200);
1730
1664
 
1731
1665
  let logo = loadImage('/q5js_logo.avif');
1732
1666
 
1733
- q.draw = () => {
1667
+ Q5.draw = function () {
1734
1668
  background(logo);
1735
1669
  };
1736
1670
  */
@@ -1748,19 +1682,19 @@ q.draw = () => {
1748
1682
  * @param {number} [sw] width of the subsection of the source image
1749
1683
  * @param {number} [sh] height of the subsection of the source image
1750
1684
  * @example
1751
- createCanvas(200);
1685
+ await createCanvas(200);
1752
1686
 
1753
1687
  let logo = loadImage('/q5js_logo.avif');
1754
1688
 
1755
- function draw() {
1689
+ Q5.draw = function () {
1756
1690
  image(logo, 0, 0, 200, 200);
1757
1691
  }
1758
1692
  * @example
1759
- createCanvas(200);
1693
+ await createCanvas(200);
1760
1694
 
1761
1695
  let logo = loadImage('/q5js_logo.avif');
1762
1696
 
1763
- function draw() {
1697
+ Q5.draw = function () {
1764
1698
  image(logo, 0, 0, 200, 200, 256, 256, 512, 512);
1765
1699
  }
1766
1700
  */
@@ -1772,30 +1706,30 @@ function draw() {
1772
1706
  * Changes how inputs to `image` are interpreted.
1773
1707
  * @param {string} mode
1774
1708
  * @example
1775
- createCanvas(200);
1709
+ await createCanvas(200);
1776
1710
  let logo = loadImage('/q5js_logo.avif');
1777
1711
 
1778
- function draw() {
1712
+ Q5.draw = function () {
1779
1713
  imageMode(CORNER);
1780
1714
 
1781
1715
  // ( img, x, y, w, h)
1782
1716
  image(logo, 50, 50, 100, 100);
1783
1717
  }
1784
1718
  * @example
1785
- createCanvas(200);
1719
+ await createCanvas(200);
1786
1720
  let logo = loadImage('/q5js_logo.avif');
1787
1721
 
1788
- function draw() {
1722
+ Q5.draw = function () {
1789
1723
  imageMode(CENTER);
1790
1724
 
1791
1725
  // ( img, cX, cY, w, h)
1792
1726
  image(logo, 100, 100, 100, 100);
1793
1727
  }
1794
1728
  * @example
1795
- createCanvas(200);
1729
+ await createCanvas(200);
1796
1730
  let logo = loadImage('/q5js_logo.avif');
1797
1731
 
1798
- function draw() {
1732
+ Q5.draw = function () {
1799
1733
  imageMode(CORNERS);
1800
1734
 
1801
1735
  // ( img, x1, y1, x2, y2)
@@ -1824,14 +1758,12 @@ function draw() {
1824
1758
  * @param {number} w new width
1825
1759
  * @param {number} h new height
1826
1760
  * @example
1827
- createCanvas(200);
1761
+ await createCanvas(200);
1828
1762
 
1829
- let logo = loadImage('/q5js_logo.avif');
1763
+ let logo = await load('/q5js_logo.avif');
1830
1764
 
1831
- function setup() {
1832
- logo.resize(128, 128);
1833
- image(logo, 0, 0, 200, 200);
1834
- }
1765
+ logo.resize(128, 128);
1766
+ image(logo, 0, 0, 200, 200);
1835
1767
  */
1836
1768
  function resize(w: number, h: number): void;
1837
1769
 
@@ -1846,27 +1778,21 @@ function setup() {
1846
1778
  * their actual size. This is the default setting, so running this
1847
1779
  * function only has an effect if `noSmooth` has been called.
1848
1780
  * @example
1849
- createCanvas(200);
1850
-
1851
- let icon = loadImage('/q5js_icon.png');
1852
-
1853
- function setup() {
1854
- image(icon, 0, 0, 200, 200);
1855
- }
1781
+ await createCanvas(200);
1782
+ let icon = await load('/q5js_icon.png');
1783
+ image(icon, 0, 0, 200, 200);
1856
1784
  */
1857
1785
  function smooth(): void;
1858
1786
 
1859
1787
  /** 🌆
1860
1788
  * Disables smooth image rendering for a pixelated look.
1861
1789
  * @example
1862
- createCanvas(200);
1790
+ await createCanvas(200);
1863
1791
 
1864
- let icon = loadImage('/q5js_icon.png');
1792
+ let icon = await load('/q5js_icon.png');
1865
1793
 
1866
- function setup() {
1867
- noSmooth();
1868
- image(icon, 0, 0, 200, 200);
1869
- }
1794
+ noSmooth();
1795
+ image(icon, 0, 0, 200, 200);
1870
1796
  */
1871
1797
  function noSmooth(): void;
1872
1798
 
@@ -1890,14 +1816,12 @@ function setup() {
1890
1816
  * each copy separately.
1891
1817
  * @param {string | number} color tint color
1892
1818
  * @example
1893
- createCanvas(200);
1819
+ await createCanvas(200);
1894
1820
 
1895
- let logo = loadImage('/q5js_logo.avif');
1821
+ let logo = await load('/q5js_logo.avif');
1896
1822
 
1897
- function setup() {
1898
- tint(255, 0, 0, 128);
1899
- image(logo, 0, 0, 200, 200);
1900
- }
1823
+ tint(255, 0, 0, 128);
1824
+ image(logo, 0, 0, 200, 200);
1901
1825
  */
1902
1826
  function tint(color: string | number): void;
1903
1827
 
@@ -1930,14 +1854,12 @@ function setup() {
1930
1854
  * @param {number} dw width of the destination region
1931
1855
  * @param {number} dh height of the destination region
1932
1856
  * @example
1933
- createCanvas(200);
1857
+ await createCanvas(200);
1934
1858
 
1935
- let logo = loadImage('/q5js_logo.avif');
1859
+ let logo = await load('/q5js_logo.avif');
1936
1860
 
1937
- function setup() {
1938
- logo.inset(256, 256, 512, 512, 0, 0, 256, 256);
1939
- image(logo, 0, 0, 200, 200);
1940
- }
1861
+ logo.inset(256, 256, 512, 512, 0, 0, 256, 256);
1862
+ image(logo, 0, 0, 200, 200);
1941
1863
  */
1942
1864
  function inset(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
1943
1865
 
@@ -1957,7 +1879,7 @@ function setup() {
1957
1879
  * @param {number} [h] height of the area, default is 1
1958
1880
  * @returns {Q5.Image | number[]}
1959
1881
  * @example
1960
- function draw() {
1882
+ Q5.draw = function () {
1961
1883
  background(200);
1962
1884
  noStroke();
1963
1885
  circle(100, 100, frameCount % 200);
@@ -1967,14 +1889,12 @@ function draw() {
1967
1889
  text(col, mouseX, mouseY);
1968
1890
  }
1969
1891
  * @example
1970
- createCanvas(200);
1892
+ await createCanvas(200);
1971
1893
 
1972
- let logo = loadImage('/q5js_logo.avif');
1894
+ let logo = await load('/q5js_logo.avif');
1973
1895
 
1974
- function setup() {
1975
- let cropped = logo.get(256, 256, 512, 512);
1976
- image(cropped, 0, 0, 200, 200);
1977
- }
1896
+ let cropped = logo.get(256, 256, 512, 512);
1897
+ image(cropped, 0, 0, 200, 200);
1978
1898
  */
1979
1899
  function get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
1980
1900
 
@@ -1989,10 +1909,10 @@ function setup() {
1989
1909
  * @param {number} y
1990
1910
  * @param {any} val color, canvas, or image
1991
1911
  * @example
1992
- createCanvas(200);
1912
+ await createCanvas(200);
1993
1913
  let c = color('lime');
1994
1914
 
1995
- function draw() {
1915
+ Q5.draw = function () {
1996
1916
  set(random(200), random(200), c);
1997
1917
  updatePixels();
1998
1918
  }
@@ -2022,7 +1942,7 @@ function draw() {
2022
1942
  frameRate(5);
2023
1943
  let icon = loadImage('/q5js_icon.png');
2024
1944
 
2025
- function draw() {
1945
+ Q5.draw = function () {
2026
1946
  icon.loadPixels();
2027
1947
  for (let i = 0; i < icon.pixels.length; i += 16) {
2028
1948
  icon.pixels[i + 1] = random(255);
@@ -2036,7 +1956,7 @@ function draw() {
2036
1956
  /** 🌆
2037
1957
  * Applies changes in the `pixels` array to the canvas or image.
2038
1958
  * @example
2039
- createCanvas(200);
1959
+ await createCanvas(200);
2040
1960
 
2041
1961
  for (let x = 0; x < 200; x += 5) {
2042
1962
  for (let y = 0; y < 200; y += 5) {
@@ -2057,13 +1977,10 @@ updatePixels();
2057
1977
  * @param {string} type filter type or a CSS filter string
2058
1978
  * @param {number} [value] optional value, depends on filter type
2059
1979
  * @example
2060
- createCanvas(200);
2061
- let logo = loadImage('/q5js_logo.avif');
2062
-
2063
- function setup() {
2064
- logo.filter(INVERT);
2065
- image(logo, 0, 0, 200, 200);
2066
- }
1980
+ await createCanvas(200);
1981
+ let logo = await load('/q5js_logo.avif');
1982
+ logo.filter(INVERT);
1983
+ image(logo, 0, 0, 200, 200);
2067
1984
  */
2068
1985
  function filter(type: string, value?: number): void;
2069
1986
 
@@ -2127,13 +2044,13 @@ function setup() {
2127
2044
  * @param {number} [wrapWidth] maximum line width in characters
2128
2045
  * @param {number} [lineLimit] maximum number of lines
2129
2046
  * @example
2130
- createCanvas(200, 100);
2047
+ await createCanvas(200, 100);
2131
2048
  background('silver');
2132
2049
 
2133
2050
  textSize(32);
2134
2051
  text('Hello, world!', 12, 60);
2135
2052
  * @example
2136
- createCanvas(200);
2053
+ await createCanvas(200);
2137
2054
  background(200);
2138
2055
  textSize(20);
2139
2056
 
@@ -2168,7 +2085,7 @@ text(info, 12, 30, 20, 6);
2168
2085
  * @param {string} url URL of the font to load
2169
2086
  * @returns {FontFace | Promise<FontFace>} font or promise
2170
2087
  * @example
2171
- createCanvas(200, 56);
2088
+ await createCanvas(200, 56);
2172
2089
 
2173
2090
  loadFont('/assets/Robotica.ttf');
2174
2091
 
@@ -2178,7 +2095,7 @@ function setup() {
2178
2095
  text('Hello!', 2, 54);
2179
2096
  }
2180
2097
  * @example
2181
- createCanvas(200, 74);
2098
+ await createCanvas(200, 74);
2182
2099
 
2183
2100
  loadFont(
2184
2101
  'fonts.googleapis.com/css2?family=Pacifico'
@@ -2199,7 +2116,7 @@ function setup() {
2199
2116
  * "sans-serif" or the last font loaded.
2200
2117
  * @param {string} fontName name of the font family or a FontFace object
2201
2118
  * @example
2202
- createCanvas(200, 160);
2119
+ await createCanvas(200, 160);
2203
2120
  background(200);
2204
2121
 
2205
2122
  textFont('serif');
@@ -2207,13 +2124,13 @@ textFont('serif');
2207
2124
  textSize(32);
2208
2125
  text('Hello, world!', 15, 90);
2209
2126
  * @example
2210
- let q = await Q5.WebGPU();
2211
- createCanvas(200);
2127
+ await createCanvas(200, GPU);
2128
+ await createCanvas(200);
2212
2129
  background(0.8);
2213
2130
 
2214
2131
  textFont('monospace');
2215
2132
 
2216
- q.setup = () => {
2133
+ Q5.setup = function () {
2217
2134
  text('Hello, world!', -65, 0);
2218
2135
  }
2219
2136
  */
@@ -2224,7 +2141,7 @@ q.setup = () => {
2224
2141
  * @param {number} [size] size of the font in pixels
2225
2142
  * @returns {number | void} current font size when no argument is provided
2226
2143
  * @example
2227
- function draw() {
2144
+ Q5.draw = function () {
2228
2145
  background(200);
2229
2146
 
2230
2147
  textSize(abs(mouseX));
@@ -2238,7 +2155,7 @@ function draw() {
2238
2155
  * @param {number} [leading] line height in pixels
2239
2156
  * @returns {number | void} current line height when no argument is provided
2240
2157
  * @example
2241
- function draw() {
2158
+ Q5.draw = function () {
2242
2159
  background(200);
2243
2160
 
2244
2161
  textSize(abs(mouseX));
@@ -2252,7 +2169,7 @@ function draw() {
2252
2169
  * Sets the current text style.
2253
2170
  * @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
2254
2171
  * @example
2255
- createCanvas(200);
2172
+ await createCanvas(200);
2256
2173
  background(200);
2257
2174
 
2258
2175
  textStyle(ITALIC);
@@ -2267,7 +2184,7 @@ text('Hello, world!', 12, 106);
2267
2184
  * @param {'left' | 'center' | 'right'} horiz horizontal alignment
2268
2185
  * @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
2269
2186
  * @example
2270
- createCanvas(200);
2187
+ await createCanvas(200);
2271
2188
  background(200);
2272
2189
  textSize(32);
2273
2190
 
@@ -2290,7 +2207,7 @@ text('Hello, world!', 100, 100);
2290
2207
  * - 900: black/heavy
2291
2208
  * @param {number | string} weight font weight
2292
2209
  * @example
2293
- createCanvas(200);
2210
+ await createCanvas(200);
2294
2211
  background(200);
2295
2212
  textSize(32);
2296
2213
  textAlign(CENTER, MIDDLE);
@@ -2305,7 +2222,7 @@ text('Hello, world!', 100, 100);
2305
2222
  * @param {string} str string to measure
2306
2223
  * @returns {number} width of the text in pixels
2307
2224
  * @example
2308
- function draw() {
2225
+ Q5.draw = function () {
2309
2226
  background(200);
2310
2227
 
2311
2228
  textSize(abs(mouseX));
@@ -2320,7 +2237,7 @@ function draw() {
2320
2237
  * @param {string} str string to measure
2321
2238
  * @returns {number} ascent of the text in pixels
2322
2239
  * @example
2323
- function draw() {
2240
+ Q5.draw = function () {
2324
2241
  background(200);
2325
2242
 
2326
2243
  textSize(abs(mouseX));
@@ -2335,7 +2252,7 @@ function draw() {
2335
2252
  * @param {string} str string to measure
2336
2253
  * @returns {number} descent of the text in pixels
2337
2254
  * @example
2338
- createCanvas(200);
2255
+ await createCanvas(200);
2339
2256
  background(200);
2340
2257
  textSize(64);
2341
2258
 
@@ -2351,13 +2268,13 @@ createCanvas(200);
2351
2268
  * @param {number} [lineLimit] maximum number of lines
2352
2269
  * @returns {Q5.Image} an image object representing the rendered text
2353
2270
  * @example
2354
- createCanvas(200);
2271
+ await createCanvas(200);
2355
2272
  textSize(96);
2356
2273
 
2357
2274
  let img = createTextImage('🐶');
2358
2275
  img.filter(INVERT);
2359
2276
 
2360
- function draw() {
2277
+ Q5.draw = function () {
2361
2278
  image(img, 55, 10);
2362
2279
  }
2363
2280
  */
@@ -2380,20 +2297,18 @@ function draw() {
2380
2297
  * @param {number} x x-coordinate where the image should be placed
2381
2298
  * @param {number} y y-coordinate where the image should be placed
2382
2299
  * @example
2383
- let q = await Q5.WebGPU();
2384
- createCanvas(200);
2300
+ await createCanvas(200, GPU);
2385
2301
  background(0.8);
2386
2302
  textSize(96);
2387
2303
  textAlign(CENTER, CENTER);
2388
2304
 
2389
2305
  textImage('🐶', 0, 0);
2390
2306
  * @example
2391
- let q = await Q5.WebGPU();
2392
- createCanvas(200);
2307
+ await createCanvas(200, GPU);
2393
2308
 
2394
2309
  loadFont('/assets/Robotica.ttf');
2395
2310
 
2396
- q.setup = () => {
2311
+ Q5.setup = function () {
2397
2312
  background(0.8);
2398
2313
  textSize(66);
2399
2314
  textImage('Hello!', -100, 100);
@@ -2410,7 +2325,7 @@ q.setup = () => {
2410
2325
  * @param {number} r number of digits to appear after the decimal point
2411
2326
  * @returns {string} a string representation of the number, formatted accordingly
2412
2327
  * @example
2413
- createCanvas(200, 100);
2328
+ await createCanvas(200, 100);
2414
2329
  background(200);
2415
2330
 
2416
2331
  textSize(32);
@@ -2483,7 +2398,7 @@ text(nf(PI, 4, 5), 10, 60);
2483
2398
  /** 🖲️
2484
2399
  * Current X position of the mouse.
2485
2400
  * @example
2486
- function draw() {
2401
+ Q5.draw = function () {
2487
2402
  background(200);
2488
2403
  textSize(64);
2489
2404
  text(round(mouseX), 50, 120);
@@ -2494,7 +2409,7 @@ function draw() {
2494
2409
  /** 🖲️
2495
2410
  * Current Y position of the mouse.
2496
2411
  * @example
2497
- function draw() {
2412
+ Q5.draw = function () {
2498
2413
  background(200);
2499
2414
  circle(100, mouseY, 100);
2500
2415
  }
@@ -2516,7 +2431,7 @@ function draw() {
2516
2431
  *
2517
2432
  * The default value is an empty string.
2518
2433
  * @example
2519
- function draw() {
2434
+ Q5.draw = function () {
2520
2435
  background(200);
2521
2436
  textSize(64);
2522
2437
  text(mouseButton, 20, 120);
@@ -2527,7 +2442,7 @@ function draw() {
2527
2442
  /** 🖲️
2528
2443
  * True if the mouse is currently pressed, false otherwise.
2529
2444
  * @example
2530
- function draw() {
2445
+ Q5.draw = function () {
2531
2446
  if (mouseIsPressed) background(100);
2532
2447
  else background(200);
2533
2448
  }
@@ -2537,10 +2452,10 @@ function draw() {
2537
2452
  /** 🖲️
2538
2453
  * Define this function to respond to mouse down events.
2539
2454
  * @example
2540
- createCanvas(200);
2455
+ await createCanvas(200);
2541
2456
  let gray = 95;
2542
2457
 
2543
- function mousePressed() {
2458
+ Q5.mousePressed = function () {
2544
2459
  background(gray % 256);
2545
2460
  gray += 40;
2546
2461
  }
@@ -2550,7 +2465,7 @@ function mousePressed() {
2550
2465
  /** 🖲️
2551
2466
  * Define this function to respond to mouse up events.
2552
2467
  * @example
2553
- createCanvas(200);
2468
+ await createCanvas(200);
2554
2469
  let gray = 95;
2555
2470
 
2556
2471
  function mouseReleased() {
@@ -2566,7 +2481,7 @@ function mouseReleased() {
2566
2481
  * On touchscreen devices this function is not called
2567
2482
  * when the user drags their finger on the screen.
2568
2483
  * @example
2569
- createCanvas(200);
2484
+ await createCanvas(200);
2570
2485
  let gray = 95;
2571
2486
 
2572
2487
  function mouseMoved() {
@@ -2582,7 +2497,7 @@ function mouseMoved() {
2582
2497
  * Dragging the mouse is defined as moving the mouse
2583
2498
  * while a mouse button is pressed.
2584
2499
  * @example
2585
- createCanvas(200);
2500
+ await createCanvas(200);
2586
2501
  let gray = 95;
2587
2502
 
2588
2503
  function mouseDragged() {
@@ -2595,7 +2510,7 @@ function mouseDragged() {
2595
2510
  /** 🖲️
2596
2511
  * Define this function to respond to mouse double click events.
2597
2512
  * @example
2598
- createCanvas(200);
2513
+ await createCanvas(200);
2599
2514
  let gray = 95;
2600
2515
 
2601
2516
  function doubleClicked() {
@@ -2608,7 +2523,7 @@ function doubleClicked() {
2608
2523
  /** 🖲️
2609
2524
  * The name of the last key pressed.
2610
2525
  * @example
2611
- function draw() {
2526
+ Q5.draw = function () {
2612
2527
  background(200);
2613
2528
  textSize(64);
2614
2529
  text(key, 20, 120);
@@ -2619,7 +2534,7 @@ function draw() {
2619
2534
  /** 🖲️
2620
2535
  * True if a key is currently pressed, false otherwise.
2621
2536
  * @example
2622
- function draw() {
2537
+ Q5.draw = function () {
2623
2538
  if (keyIsPressed) background(100);
2624
2539
  else background(200);
2625
2540
  }
@@ -2632,7 +2547,7 @@ function draw() {
2632
2547
  * @param {string} key key to check
2633
2548
  * @returns {boolean} true if the key is pressed, false otherwise
2634
2549
  * @example
2635
- function draw() {
2550
+ Q5.draw = function () {
2636
2551
  background(200);
2637
2552
 
2638
2553
  if (keyIsDown('f') && keyIsDown('j')) {
@@ -2645,7 +2560,7 @@ function draw() {
2645
2560
  /** 🖲️
2646
2561
  * Define this function to respond to key down events.
2647
2562
  * @example
2648
- createCanvas(200);
2563
+ await createCanvas(200);
2649
2564
 
2650
2565
  let gray = 95;
2651
2566
  function keyPressed() {
@@ -2658,7 +2573,7 @@ function keyPressed() {
2658
2573
  /** 🖲️
2659
2574
  * Define this function to respond to key up events.
2660
2575
  * @example
2661
- createCanvas(200);
2576
+ await createCanvas(200);
2662
2577
 
2663
2578
  let gray = 95;
2664
2579
  function keyReleased() {
@@ -2673,7 +2588,7 @@ function keyReleased() {
2673
2588
  * browser window. Each touch being an object with
2674
2589
  * `id`, `x`, and `y` properties.
2675
2590
  * @example
2676
- function draw() {
2591
+ Q5.draw = function () {
2677
2592
  background(200);
2678
2593
  for (let touch of touches) {
2679
2594
  circle(touch.x, touch.y, 100);
@@ -2689,7 +2604,7 @@ function draw() {
2689
2604
  * Return true to enable touch gestures like pinch-to-zoom
2690
2605
  * and scroll, which q5 disables on the canvas by default.
2691
2606
  * @example
2692
- createCanvas(200);
2607
+ await createCanvas(200);
2693
2608
 
2694
2609
  let gray = 95;
2695
2610
  function touchStarted() {
@@ -2706,7 +2621,7 @@ function touchStarted() {
2706
2621
  * Return true to enable touch gestures like pinch-to-zoom
2707
2622
  * and scroll, which q5 disables on the canvas by default.
2708
2623
  * @example
2709
- createCanvas(200);
2624
+ await createCanvas(200);
2710
2625
 
2711
2626
  let gray = 95;
2712
2627
  function touchEnded() {
@@ -2723,7 +2638,7 @@ function touchEnded() {
2723
2638
  * Return true to enable touch gestures like pinch-to-zoom
2724
2639
  * and scroll, which q5 disables on the canvas by default.
2725
2640
  * @example
2726
- createCanvas(200);
2641
+ await createCanvas(200);
2727
2642
  let gray = 95;
2728
2643
 
2729
2644
  function touchMoved() {
@@ -2744,7 +2659,7 @@ function touchMoved() {
2744
2659
  * The `event` property contains the original
2745
2660
  * [PointerEvent](https://developer.mozilla.org/docs/Web/API/PointerEvent).
2746
2661
  * @example
2747
- function draw() {
2662
+ Q5.draw = function () {
2748
2663
  background(200);
2749
2664
  for (let pointerID in pointers) {
2750
2665
  let pointer = pointers[pointerID];
@@ -2762,7 +2677,7 @@ function draw() {
2762
2677
  * @param {number} [x] x-coordinate of the cursor's point
2763
2678
  * @param {number} [y] y-coordinate of the cursor's point
2764
2679
  * @example
2765
- createCanvas(200, 100);
2680
+ await createCanvas(200, 100);
2766
2681
  cursor('pointer');
2767
2682
  */
2768
2683
  function cursor(name: string, x?: number, y?: number): void;
@@ -2770,7 +2685,7 @@ cursor('pointer');
2770
2685
  /** 🖲️
2771
2686
  * Hides the cursor within the bounds of the canvas.
2772
2687
  * @example
2773
- createCanvas(200, 100);
2688
+ await createCanvas(200, 100);
2774
2689
  noCursor();
2775
2690
  */
2776
2691
  function noCursor(): void;
@@ -2784,7 +2699,7 @@ noCursor();
2784
2699
  * Return true to allow the default behavior of scrolling the page.
2785
2700
  * @example
2786
2701
  let x = y = 100;
2787
- function draw() {
2702
+ Q5.draw = function () {
2788
2703
  circle(x, y, 10);
2789
2704
  }
2790
2705
  function mouseWheel(e) {
@@ -2805,7 +2720,7 @@ function mouseWheel(e) {
2805
2720
  *
2806
2721
  * @param {boolean} unadjustedMovement set to true to disable OS-level mouse acceleration and access raw mouse input
2807
2722
  * @example
2808
- function draw() {
2723
+ Q5.draw = function () {
2809
2724
  circle(mouseX / 10, mouseY / 10, 10);
2810
2725
  }
2811
2726
 
@@ -2832,15 +2747,15 @@ function doubleClicked() {
2832
2747
  * @param {number} [high] upper bound (exclusive)
2833
2748
  * @returns {number | any} a random number or element
2834
2749
  * @example
2835
- createCanvas(200);
2750
+ await createCanvas(200);
2836
2751
  background(200);
2837
2752
  frameRate(5);
2838
2753
 
2839
- function draw() {
2754
+ Q5.draw = function () {
2840
2755
  circle(100, 100, random(20, 200));
2841
2756
  }
2842
2757
  * @example
2843
- function draw() {
2758
+ Q5.draw = function () {
2844
2759
  circle(random(200), random(200), 10);
2845
2760
  }
2846
2761
  */
@@ -2855,14 +2770,13 @@ function draw() {
2855
2770
  * @param {number} amount absolute maximum amount of jitter, default is 1
2856
2771
  * @returns {number} random number between -val and val
2857
2772
  * @example
2858
- function draw() {
2773
+ Q5.draw = function () {
2859
2774
  circle(mouseX + jit(3), mouseY + jit(3), 5);
2860
2775
  }
2861
2776
  * @example
2862
- let q = await Q5.WebGPU();
2863
- createCanvas(200, 100);
2777
+ await createCanvas(200, GPU);
2864
2778
 
2865
- q.draw = () => {
2779
+ Q5.draw = function () {
2866
2780
  circle(jit(50), 0, random(50));
2867
2781
  };
2868
2782
  */
@@ -2877,13 +2791,13 @@ q.draw = () => {
2877
2791
  * @param {number} [z] z-coordinate input
2878
2792
  * @returns {number} a noise value
2879
2793
  * @example
2880
- function draw() {
2794
+ Q5.draw = function () {
2881
2795
  background(200);
2882
2796
  let n = noise(frameCount * 0.01);
2883
2797
  circle(100, 100, n * 200);
2884
2798
  }
2885
2799
  * @example
2886
- function draw() {
2800
+ Q5.draw = function () {
2887
2801
  background(200);
2888
2802
  let t = (frameCount + mouseX) * 0.02;
2889
2803
  for (let x = -5; x < 220; x += 10) {
@@ -2892,9 +2806,9 @@ function draw() {
2892
2806
  }
2893
2807
  }
2894
2808
  * @example
2895
- let q = await Q5.WebGPU();
2809
+ await createCanvas(200);
2896
2810
 
2897
- q.draw = () => {
2811
+ Q5.draw = () => {
2898
2812
  noStroke();
2899
2813
  let t = millis() * 0.002;
2900
2814
  for (let x = -100; x < 100; x += 5) {
@@ -2917,7 +2831,7 @@ q.draw = () => {
2917
2831
  * @param {number} y2 y-coordinate of the second point
2918
2832
  * @returns {number} distance between the points
2919
2833
  * @example
2920
- function draw() {
2834
+ Q5.draw = function () {
2921
2835
  background(200);
2922
2836
  circle(100, 100, 20);
2923
2837
  circle(mouseX, mouseY, 20);
@@ -3006,7 +2920,7 @@ function draw() {
3006
2920
  * @param {number} [d] number of decimal places to round to
3007
2921
  * @returns {number} rounded number
3008
2922
  * @example
3009
- createCanvas(200, 100);
2923
+ await createCanvas(200, 100);
3010
2924
  background(200);
3011
2925
  textSize(32);
3012
2926
  text(round(PI, 5), 10, 60);
@@ -3018,7 +2932,7 @@ text(round(PI, 5), 10, 60);
3018
2932
  * @param {number} n a number
3019
2933
  * @returns {number} rounded number
3020
2934
  * @example
3021
- createCanvas(200, 100);
2935
+ await createCanvas(200, 100);
3022
2936
  background(200);
3023
2937
  textSize(32);
3024
2938
  text(ceil(PI), 10, 60);
@@ -3030,7 +2944,7 @@ text(ceil(PI), 10, 60);
3030
2944
  * @param {number} n a number
3031
2945
  * @returns {number} rounded number
3032
2946
  * @example
3033
- createCanvas(200, 100);
2947
+ await createCanvas(200, 100);
3034
2948
  background(200);
3035
2949
  textSize(32);
3036
2950
  text(floor(-PI), 10, 60);
@@ -3042,7 +2956,7 @@ text(floor(-PI), 10, 60);
3042
2956
  * @param {...number} args numbers to compare
3043
2957
  * @returns {number} minimum
3044
2958
  * @example
3045
- function draw() {
2959
+ Q5.draw = function () {
3046
2960
  background(min(mouseX, 100));
3047
2961
  }
3048
2962
  */
@@ -3053,7 +2967,7 @@ function draw() {
3053
2967
  * @param {...number} args numbers to compare
3054
2968
  * @returns {number} maximum
3055
2969
  * @example
3056
- function draw() {
2970
+ Q5.draw = function () {
3057
2971
  background(max(mouseX, 100));
3058
2972
  }
3059
2973
  */
@@ -3210,12 +3124,12 @@ function draw() {
3210
3124
  * @param {string} url sound file
3211
3125
  * @returns {Sound | Promise<Sound>} a new `Sound` object or promise
3212
3126
  * @example
3213
- createCanvas(200);
3127
+ await createCanvas(200);
3214
3128
 
3215
3129
  let sound = loadSound('/assets/jump.wav');
3216
3130
  sound.volume = 0.3;
3217
3131
 
3218
- function mousePressed() {
3132
+ Q5.mousePressed = function () {
3219
3133
  sound.play();
3220
3134
  }
3221
3135
  */
@@ -3234,12 +3148,12 @@ function mousePressed() {
3234
3148
  * @param url audio file
3235
3149
  * @returns {HTMLAudioElement | Promise<HTMLAudioElement>} an HTMLAudioElement or promise
3236
3150
  * @example
3237
- createCanvas(200);
3151
+ await createCanvas(200);
3238
3152
 
3239
3153
  let audio = loadAudio('/assets/retro.flac');
3240
3154
  audio.volume = 0.4;
3241
3155
 
3242
- function mousePressed() {
3156
+ Q5.mousePressed = function () {
3243
3157
  audio.play();
3244
3158
  }
3245
3159
  */
@@ -3348,7 +3262,7 @@ function mousePressed() {
3348
3262
  * @param {string} [content] content of the element
3349
3263
  * @returns {HTMLElement} element
3350
3264
  * @example
3351
- createCanvas(200);
3265
+ await createCanvas(200);
3352
3266
 
3353
3267
  let el = createEl('div', '*');
3354
3268
  el.position(50, 50);
@@ -3366,7 +3280,7 @@ el.style.color = 'white';
3366
3280
  * @param {string} [text] text content
3367
3281
  * @param {boolean} [newTab] whether to open the link in a new tab
3368
3282
  * @example
3369
- createCanvas(200);
3283
+ await createCanvas(200);
3370
3284
 
3371
3285
  let link = createA('https://q5js.org', 'q5.js');
3372
3286
  link.position(16, 42);
@@ -3382,7 +3296,7 @@ link.addEventListener('mouseover', () => {
3382
3296
  * Creates a button element.
3383
3297
  * @param {string} [content] text content
3384
3298
  * @example
3385
- createCanvas(200, 100);
3299
+ await createCanvas(200, 100);
3386
3300
 
3387
3301
  let btn = createButton('Click me!');
3388
3302
 
@@ -3401,7 +3315,7 @@ btn.addEventListener('click', () => {
3401
3315
  * @param {string} [label] text label placed next to the checkbox
3402
3316
  * @param {boolean} [checked] initial state
3403
3317
  * @example
3404
- createCanvas(200, 100);
3318
+ await createCanvas(200, 100);
3405
3319
 
3406
3320
  let box = createCheckbox('Check me!');
3407
3321
  box.label.style.color = 'lime';
@@ -3419,12 +3333,12 @@ box.addEventListener('input', () => {
3419
3333
  * Use the `value` property to get or set the color value.
3420
3334
  * @param {string} [value] initial color value
3421
3335
  * @example
3422
- createCanvas(200, 100);
3336
+ await createCanvas(200, 100);
3423
3337
 
3424
3338
  let picker = createColorPicker();
3425
3339
  picker.value = '#fd7575';
3426
3340
 
3427
- function draw() {
3341
+ Q5.draw = function () {
3428
3342
  background(picker.value);
3429
3343
  }
3430
3344
  */
@@ -3434,7 +3348,7 @@ function draw() {
3434
3348
  * Creates an image element.
3435
3349
  * @param {string} src url of the image
3436
3350
  * @example
3437
- createCanvas(200, 100);
3351
+ await createCanvas(200, 100);
3438
3352
 
3439
3353
  let img = createImg('/assets/p5play_logo.webp')
3440
3354
  .position(0, 0)
@@ -3454,7 +3368,7 @@ let img = createImg('/assets/p5play_logo.webp')
3454
3368
  * @param {string} [value] initial value
3455
3369
  * @param {string} [type] text input type, can be 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
3456
3370
  * @example
3457
- createCanvas(200, 100);
3371
+ await createCanvas(200, 100);
3458
3372
  textSize(64);
3459
3373
 
3460
3374
  let input = createInput();
@@ -3472,7 +3386,7 @@ input.addEventListener('input', () => {
3472
3386
  * Creates a paragraph element.
3473
3387
  * @param {string} [content] text content
3474
3388
  * @example
3475
- createCanvas(200, 50);
3389
+ await createCanvas(200, 50);
3476
3390
  background('coral');
3477
3391
 
3478
3392
  let p = createP('Hello, world!');
@@ -3489,13 +3403,13 @@ p.style.color = 'pink';
3489
3403
  * Use the `value` property to get or set the value of the selected radio button.
3490
3404
  * @param {string} [groupName]
3491
3405
  * @example
3492
- createCanvas(200, 100);
3406
+ await createCanvas(200, 100);
3493
3407
 
3494
3408
  let radio = createRadio()
3495
3409
  .option('square', '1')
3496
3410
  .option('circle', '2');
3497
3411
 
3498
- function draw() {
3412
+ Q5.draw = function () {
3499
3413
  background(200);
3500
3414
  if (radio.value == '1') square(75, 25, 50);
3501
3415
  if (radio.value == '2') circle(100, 50, 50);
@@ -3518,7 +3432,7 @@ function draw() {
3518
3432
  * string or an array of strings.
3519
3433
  * @param {string} [placeholder] optional placeholder text that appears before an option is selected
3520
3434
  * @example
3521
- createCanvas(200, 100);
3435
+ await createCanvas(200, 100);
3522
3436
 
3523
3437
  let sel = createSelect('Select a color')
3524
3438
  .option('Red', '#f55')
@@ -3541,13 +3455,13 @@ sel.addEventListener('change', () => {
3541
3455
  * @param {number} [value] initial value
3542
3456
  * @param {number} [step] step size
3543
3457
  * @example
3544
- createCanvas(200);
3458
+ await createCanvas(200);
3545
3459
 
3546
3460
  let slider = createSlider(0, 255)
3547
3461
  .position(10, 10)
3548
3462
  .size(180);
3549
3463
 
3550
- function draw() {
3464
+ Q5.draw = function () {
3551
3465
  background(slider.val());
3552
3466
  }
3553
3467
  */
@@ -3567,7 +3481,7 @@ function draw() {
3567
3481
  * @param {string} src url of the video
3568
3482
  * @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
3569
3483
  * @example
3570
- createCanvas(0);
3484
+ await createCanvas(0);
3571
3485
 
3572
3486
  let vid = createVideo('/assets/apollo4.mp4');
3573
3487
  vid.size(200, 150);
@@ -3575,15 +3489,15 @@ vid.autoplay = vid.muted = vid.loop = true;
3575
3489
  vid.controls = true;
3576
3490
 
3577
3491
  * @example
3578
- createCanvas(200, 150);
3492
+ await createCanvas(200, 150);
3579
3493
  let vid = createVideo('/assets/apollo4.mp4');
3580
3494
  vid.hide();
3581
3495
 
3582
- function mousePressed() {
3496
+ Q5.mousePressed = function () {
3583
3497
  vid.currentTime = 0;
3584
3498
  vid.play();
3585
3499
  }
3586
- function draw() {
3500
+ Q5.draw = function () {
3587
3501
  image(vid, 0, 0, 200, 150);
3588
3502
  filter(HUE_ROTATE, 90);
3589
3503
  }
@@ -3610,30 +3524,30 @@ function draw() {
3610
3524
  * @param {boolean} [flipped] whether to mirror the video vertically, true by default
3611
3525
  * @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
3612
3526
  * @example
3613
- createCanvas(200);
3527
+ await createCanvas(200);
3614
3528
 
3615
- function mousePressed() {
3529
+ Q5.mousePressed = function () {
3616
3530
  let cap = createCapture(VIDEO);
3617
3531
  cap.size(200, 112.5);
3618
3532
  canvas.remove();
3619
3533
  }
3620
3534
  * @example
3621
- createCanvas(200);
3535
+ await createCanvas(200);
3622
3536
 
3623
3537
  let cap;
3624
- function mousePressed() {
3538
+ Q5.mousePressed = function () {
3625
3539
  cap = createCapture(VIDEO);
3626
3540
  cap.hide();
3627
3541
  }
3628
3542
 
3629
- function draw() {
3543
+ Q5.draw = function () {
3630
3544
  let y = frameCount % height;
3631
3545
  image(cap, 0, y, 200, 200);
3632
3546
  }
3633
3547
  * @example
3634
- createCanvas(200);
3548
+ await createCanvas(200);
3635
3549
 
3636
- function mousePressed() {
3550
+ Q5.mousePressed = function () {
3637
3551
  let cap = createCapture({
3638
3552
  video: { width: 640, height: 480 }
3639
3553
  });
@@ -3680,12 +3594,12 @@ function mousePressed() {
3680
3594
  *
3681
3595
  * @returns {HTMLElement} a recorder, q5 DOM element
3682
3596
  * @example
3683
- createCanvas(200);
3597
+ await createCanvas(200);
3684
3598
 
3685
3599
  let rec = createRecorder();
3686
3600
  rec.bitrate = 10;
3687
3601
 
3688
- function draw() {
3602
+ Q5.draw = function () {
3689
3603
  circle(mouseX, random(height), 10);
3690
3604
  }
3691
3605
  */
@@ -3712,11 +3626,11 @@ function draw() {
3712
3626
  * Saves the current recording as a video file.
3713
3627
  * @param {string} fileName
3714
3628
  * @example
3715
- function draw() {
3629
+ Q5.draw = function () {
3716
3630
  square(mouseX, random(200), 10);
3717
3631
  }
3718
3632
 
3719
- function mousePressed() {
3633
+ Q5.mousePressed = function () {
3720
3634
  if (!recording) record();
3721
3635
  else saveRecording('squares');
3722
3636
  }
@@ -3741,17 +3655,15 @@ function mousePressed() {
3741
3655
  * @param {...string} urls
3742
3656
  * @returns {Promise<any[]>} a promise that resolves with objects
3743
3657
  * @example
3744
- let logo;
3658
+ await createCanvas(200);
3745
3659
 
3746
- async function setup() {
3747
- logo = await load('/q5js_logo.avif');
3748
- }
3660
+ let logo = await load('/q5js_logo.avif');
3749
3661
 
3750
- function draw() {
3662
+ Q5.draw = function () {
3751
3663
  image(logo, 0, 0, 200, 200);
3752
3664
  }
3753
3665
  * @example
3754
- createCanvas(200);
3666
+ await createCanvas(200);
3755
3667
 
3756
3668
  // use with top level await in a module
3757
3669
  await load('/assets/Robotica.ttf');
@@ -3760,16 +3672,26 @@ background(255);
3760
3672
  textSize(24);
3761
3673
  text('Hello, world!', 16, 100);
3762
3674
  * @example
3763
- let q = await Q5.WebGPU();
3764
- createCanvas(200);
3675
+ await createCanvas(200);
3765
3676
 
3766
3677
  let [jump, retro] = await load(
3767
3678
  '/assets/jump.wav', '/assets/retro.flac'
3768
3679
  );
3769
3680
 
3770
- q.mousePressed = () => {
3681
+ Q5.mousePressed = () => {
3771
3682
  mouseButton == 'left' ? jump.play() : retro.play();
3772
3683
  };
3684
+ * @example
3685
+ await createCanvas(200);
3686
+ background(200);
3687
+ textSize(32);
3688
+
3689
+ let myXML = await load('/assets/animals.xml');
3690
+ let mammals = myXML.getElementsByTagName('mammal');
3691
+ let y = 64;
3692
+ for (let mammal of mammals) {
3693
+ text(mammal.textContent, 20, (y += 32));
3694
+ }
3773
3695
  */
3774
3696
  function load(...urls: string[]): Promise<any[]>;
3775
3697
 
@@ -3783,21 +3705,21 @@ q.mousePressed = () => {
3783
3705
  * @param {object} [data] canvas, image, or JS object
3784
3706
  * @param {string} [fileName] filename to save as
3785
3707
  * @example
3786
- createCanvas(200);
3708
+ await createCanvas(200);
3787
3709
  background(200);
3788
3710
  circle(100, 100, 50);
3789
3711
 
3790
- function mousePressed() {
3712
+ Q5.mousePressed = function () {
3791
3713
  save('circle.png');
3792
3714
  }
3793
3715
  * @example
3794
- createCanvas(200);
3716
+ await createCanvas(200);
3795
3717
 
3796
3718
  textSize(180);
3797
3719
  let bolt = createTextImage('⚡️');
3798
3720
  image(bolt, 16, -56);
3799
3721
 
3800
- function mousePressed() {
3722
+ Q5.mousePressed = function () {
3801
3723
  save(bolt, 'bolt.png');
3802
3724
  }
3803
3725
  */
@@ -3840,20 +3762,6 @@ function mousePressed() {
3840
3762
  *
3841
3763
  * @param {string} url xml file
3842
3764
  * @returns {Element | Promise<Element>} an object containing the loaded XML in a property called `obj.DOM` or a promise
3843
- * @example
3844
- async function setup() {
3845
- createCanvas(200);
3846
- background(200);
3847
- textSize(32);
3848
-
3849
- let myXML = await loadXML('/assets/animals.xml');
3850
-
3851
- let mammals = myXML.getElementsByTagName('mammal');
3852
- let y = 64;
3853
- for (let mammal of mammals) {
3854
- text(mammal.textContent, 20, (y += 32));
3855
- }
3856
- }
3857
3765
  */
3858
3766
  function loadXML(url: string): object | Promise<Element>;
3859
3767
 
@@ -4120,7 +4028,7 @@ async function setup() {
4120
4028
  * @param {string} code WGSL shader code excerpt
4121
4029
  * @returns {GPUShaderModule} a shader program
4122
4030
  * @example
4123
- let q = await Q5.WebGPU();
4031
+ await createCanvas(200, GPU);
4124
4032
 
4125
4033
  let wobble = createShader(`
4126
4034
  @vertex
@@ -4136,13 +4044,13 @@ fn vertexMain(v: VertexParams) -> FragParams {
4136
4044
  return f;
4137
4045
  }`);
4138
4046
 
4139
- q.draw = () => {
4047
+ Q5.draw = function () {
4140
4048
  clear();
4141
4049
  shader(wobble);
4142
4050
  plane(0, 0, 100);
4143
4051
  };
4144
4052
  * @example
4145
- let q = await Q5.WebGPU();
4053
+ await createCanvas(200, GPU);
4146
4054
 
4147
4055
  let stripes = createShader(`
4148
4056
  @fragment
@@ -4151,7 +4059,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
4151
4059
  return vec4(r, 0.0, 1, 1);
4152
4060
  }`);
4153
4061
 
4154
- q.draw = () => {
4062
+ Q5.draw = function () {
4155
4063
  shader(stripes);
4156
4064
  triangle(-50, -50, 0, 50, 50, -50);
4157
4065
  };
@@ -4165,8 +4073,7 @@ q.draw = () => {
4165
4073
  * @param {number} w width or side length
4166
4074
  * @param {number} [h] height
4167
4075
  * @example
4168
- let q = await Q5.WebGPU();
4169
- createCanvas(200);
4076
+ await createCanvas(200, GPU);
4170
4077
  plane(0, 0, 100);
4171
4078
  */
4172
4079
  function plane(x: number, y: number, w: number, h?: number): void;
@@ -4180,7 +4087,7 @@ plane(0, 0, 100);
4180
4087
  /** ⚡️
4181
4088
  * Make q5 use the default shapes shader.
4182
4089
  * @example
4183
- let q = await Q5.WebGPU();
4090
+ await createCanvas(200, GPU);
4184
4091
 
4185
4092
  let stripes = createShader(`
4186
4093
  @fragment
@@ -4189,7 +4096,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
4189
4096
  return vec4(1, g, 0, 1);
4190
4097
  }`);
4191
4098
 
4192
- q.draw = () => {
4099
+ Q5.draw = function () {
4193
4100
  shader(stripes);
4194
4101
  background(0);
4195
4102
 
@@ -4232,8 +4139,7 @@ q.draw = () => {
4232
4139
  * Use this function to customize a copy of the
4233
4140
  * [default frame shader](https://github.com/q5js/q5.js/blob/main/src/shaders/frame.wgsl).
4234
4141
  * @example
4235
- let q = await Q5.WebGPU();
4236
- createCanvas(200);
4142
+ await createCanvas(200, GPU);
4237
4143
 
4238
4144
  let boxy = createFrameShader(`
4239
4145
  @fragment
@@ -4244,7 +4150,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
4244
4150
  return textureSample(tex, samp, uv);
4245
4151
  }`);
4246
4152
 
4247
- q.draw = () => {
4153
+ Q5.draw = function () {
4248
4154
  stroke(1);
4249
4155
  strokeWeight(8);
4250
4156
  line(mouseX, mouseY, pmouseX, pmouseY);
@@ -4261,7 +4167,7 @@ q.draw = () => {
4261
4167
  * @param {string} code WGSL shader code excerpt
4262
4168
  * @returns {GPUShaderModule} a shader program
4263
4169
  * @example
4264
- let q = await Q5.WebGPU();
4170
+ await createCanvas(200, GPU);
4265
4171
  imageMode(CENTER);
4266
4172
 
4267
4173
  let logo = loadImage('/q5js_logo.avif');
@@ -4274,7 +4180,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
4274
4180
  return texColor;
4275
4181
  }`);
4276
4182
 
4277
- q.draw = () => {
4183
+ Q5.draw = function () {
4278
4184
  background(0.7);
4279
4185
  shader(grate);
4280
4186
  image(logo, 0, 0, 180, 180);
@@ -4290,8 +4196,7 @@ q.draw = () => {
4290
4196
  * @param {string} code WGSL shader code excerpt
4291
4197
  * @returns {GPUShaderModule} a shader program
4292
4198
  * @example
4293
- let q = await Q5.WebGPU();
4294
- createCanvas(200, 600);
4199
+ await createCanvas(200, 600, GPU);
4295
4200
 
4296
4201
  let vid = createVideo('/assets/apollo4.mp4');
4297
4202
  vid.hide();
@@ -4319,7 +4224,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
4319
4224
  return texColor;
4320
4225
  }`);
4321
4226
 
4322
- q.draw = () => {
4227
+ Q5.draw = function () {
4323
4228
  clear();
4324
4229
  if (mouseIsPressed) vid.play();
4325
4230
  shader(flipper);
@@ -4336,7 +4241,7 @@ q.draw = () => {
4336
4241
  * @param {string} code WGSL shader code excerpt
4337
4242
  * @returns {GPUShaderModule} a shader program
4338
4243
  * @example
4339
- let q = await Q5.WebGPU();
4244
+ await createCanvas(200, GPU);
4340
4245
  textAlign(CENTER, CENTER);
4341
4246
 
4342
4247
  let spin = createTextShader(`
@@ -4362,7 +4267,7 @@ fn vertexMain(v : VertexParams) -> FragParams {
4362
4267
  return f;
4363
4268
  }`);
4364
4269
 
4365
- q.draw = () => {
4270
+ Q5.draw = function () {
4366
4271
  clear();
4367
4272
  shader(spin);
4368
4273
  fill(1, 0, 1);