q5 2.16.4 → 2.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/deno.json +1 -1
  2. package/package.json +2 -2
  3. package/q5.d.ts +567 -182
  4. package/q5.js +607 -4
  5. package/q5.min.js +2 -2
package/q5.d.ts CHANGED
@@ -7,6 +7,20 @@
7
7
  declare global {
8
8
  // ⭐️ core
9
9
 
10
+ /** ⭐️
11
+ * Welcome to q5's documentation! ☺️
12
+ *
13
+ * First time coding? Check out the [q5 Beginner's Guide to JavaScript](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Guide-to-JavaScript).
14
+ *
15
+ * On these Learn pages you'll find concise descriptions for
16
+ * q5's functions and variables. Scroll through entire topics without
17
+ * needing to click between separate pages.
18
+ *
19
+ * Experiment with editing the code in the interactive mini examples,
20
+ * which are often only 8 lines of code or less. They automatically
21
+ * update as you type, so you can see results right away.
22
+ */
23
+
10
24
  /** ⭐️
11
25
  * The draw function is run 60 times per second by default.
12
26
  * @example
@@ -80,7 +94,7 @@ function draw() {
80
94
  * it calls the draw function once.
81
95
  * @param {number} [n] number of times to redraw the canvas, default is 1
82
96
  * @example
83
- createCanvas(200, 200);
97
+ createCanvas(200);
84
98
  noLoop();
85
99
 
86
100
  function draw() {
@@ -95,7 +109,7 @@ function mousePressed() {
95
109
  /** ⭐️
96
110
  * Starts the draw loop again if it was stopped.
97
111
  * @example
98
- createCanvas(200, 200);
112
+ createCanvas(200);
99
113
  noLoop();
100
114
 
101
115
  function draw() {
@@ -257,7 +271,7 @@ function draw() {
257
271
  * favor of having load* functions, such as `loadImage`,
258
272
  * return promises.
259
273
  *
260
- * In q5 the `load` function can be used to load a file or
274
+ * In q5 the [`load`](https://q5js.org/learn/#load) function can be used to load a file or
261
275
  * multiple files, and it returns a promise that resolves
262
276
  * when the file(s) are loaded.
263
277
  *
@@ -281,7 +295,7 @@ function draw() {
281
295
  *
282
296
  * Running `new Q5()` enables the use of q5 functions and variables
283
297
  * anywhere in your code. You can also start Q5 in global mode by
284
- * running [`createCanvas`](https://q5js.org/learn/#canvas-createCanvas).
298
+ * running [`createCanvas`](https://q5js.org/learn/#createCanvas).
285
299
  *
286
300
  * By default q5 uses the CanvasRenderingContext2D based c2d renderer.
287
301
  *
@@ -332,10 +346,11 @@ circle(100, 50, 80);
332
346
  * Start using q5 by running this function!
333
347
  *
334
348
  * 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
349
+ * created automatically before the draw loop starts.
350
+ *
351
+ * In q5 WebGPU, this function must be run before running other q5 functions.
352
+ * @param {number} [w] width or size of the canvas
353
+ * @param {number} [h] height of the canvas
339
354
  * @param {Object} [opt] options for the canvas
340
355
  * @param {boolean} [opt.alpha] whether the canvas should have an alpha channel that allows it to be seen through, default is false
341
356
  * @param {string} [opt.colorSpace] color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
@@ -356,96 +371,88 @@ function draw() {
356
371
  /** ⬜️
357
372
  * The canvas element associated with the Q5 instance.
358
373
  *
359
- * @prop {Number} w
360
- * @prop {Number} width
361
- * @prop {Number} h
362
- * @prop {Number} height
363
- * @prop {Number} hw half the width
364
- * @prop {Number} hh half the height
365
- * @prop {String} renderer either "c2d" (Canvas2D) or "webgpu"
374
+ * @prop {number} w
375
+ * @prop {number} width
376
+ * @prop {number} h
377
+ * @prop {number} height
378
+ * @prop {number} hw half the width
379
+ * @prop {number} hh half the height
380
+ * @prop {string} renderer either "c2d" (Canvas2D) or "webgpu"
366
381
  */
367
382
  var canvas: HTMLCanvasElement;
368
383
 
369
- /** ⬜️
370
- * The width of the canvas.
371
- */
372
- var width: number;
373
-
374
- /** ⬜️
375
- * The height of the canvas.
376
- */
377
- var height: number;
378
-
379
384
  /** ⬜️
380
385
  * Clears the canvas, making every pixel completely transparent.
381
386
  *
382
- * The canvas can only be seen through if it has an alpha channel though.
387
+ * Note that the canvas can only be seen through if it has an alpha channel.
383
388
  */
384
389
  function clear(): void;
385
390
 
386
391
  /** ⬜️
387
392
  * Sets the fill color for shapes. The default is white.
388
393
  *
389
- * 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.
390
- * @param {string | Color} color fill color
394
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
395
+ * can accept colors in a wide range of formats: as a CSS color string,
396
+ * a `Color` object, grayscale value, or color component values.
397
+ * @param {Color} color fill color
391
398
  * @example
392
- function draw() {
393
- background(200);
399
+ createCanvas(200);
400
+ background(200);
394
401
 
395
- fill('red');
396
- circle(80, 80, 80);
402
+ fill('red');
403
+ circle(80, 80, 80);
397
404
 
398
- fill('lime');
399
- square(80, 80, 80);
400
- }
405
+ fill('lime');
406
+ square(80, 80, 80);
401
407
  */
402
- function fill(color: string | Color): void;
408
+ function fill(color: Color): void;
403
409
 
404
410
  /** ⬜️
405
411
  * Sets the stroke (outline) color for shapes. The default is black.
406
412
  *
407
- * 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.
408
- * @param {string | Color} color stroke color
413
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
414
+ * can accept colors in a wide range of formats: as a CSS color string,
415
+ * a `Color` object, grayscale value, or color component values.
416
+ * @param {Color} color stroke color
409
417
  * @example
410
- function draw() {
411
- background(200);
412
- fill(36);
418
+ createCanvas(200);
419
+ background(200);
420
+ fill(36);
413
421
 
414
- stroke('red');
415
- circle(80, 80, 80);
416
- stroke('lime');
417
- square(80, 80, 80);
418
- }
422
+ stroke('red');
423
+ circle(80, 80, 80);
424
+
425
+ stroke('lime');
426
+ square(80, 80, 80);
419
427
  */
420
- function stroke(color: string | Color): void;
428
+ function stroke(color: Color): void;
421
429
 
422
430
  /** ⬜️
423
431
  * After calling this function, shapes will not be filled.
424
432
  * @example
425
- function draw() {
426
- background(200);
433
+ createCanvas(200);
434
+ background(200);
427
435
 
428
- noFill();
429
- stroke('red');
430
- circle(80, 80, 80);
431
- stroke('lime');
432
- square(80, 80, 80);
433
- }
436
+ noFill();
437
+
438
+ stroke('red');
439
+ circle(80, 80, 80);
440
+ stroke('lime');
441
+ square(80, 80, 80);
434
442
  */
435
443
  function noFill(): void;
436
444
 
437
445
  /** ⬜️
438
446
  * After calling this function, shapes will not have a stroke (outline).
439
447
  * @example
440
- function draw() {
441
- background(200);
442
- fill(36);
443
- stroke('red');
444
- circle(80, 80, 80);
448
+ createCanvas(200);
449
+ background(200);
450
+ fill(36);
451
+ stroke('red');
452
+ circle(80, 80, 80);
445
453
 
446
- noStroke();
447
- square(80, 80, 80);
448
- }
454
+ noStroke();
455
+ square(80, 80, 80);
449
456
  */
450
457
  function noStroke(): void;
451
458
 
@@ -453,15 +460,13 @@ function draw() {
453
460
  * Sets the size of the stroke used for lines and the border around shapes.
454
461
  * @param {number} weight size of the stroke in pixels
455
462
  * @example
456
- function setup() {
457
- createCanvas(200, 200);
458
- background(200);
459
- stroke('red');
460
- circle(50, 100, 80);
463
+ createCanvas(200);
464
+ background(200);
465
+ stroke('red');
466
+ circle(50, 100, 80);
461
467
 
462
- strokeWeight(20);
463
- circle(150, 100, 80)
464
- }
468
+ strokeWeight(20);
469
+ circle(150, 100, 80);
465
470
  */
466
471
  function strokeWeight(weight: number): void;
467
472
 
@@ -469,15 +474,14 @@ function setup() {
469
474
  * Sets the global opacity, which affects all subsequent drawing operations, except `background`. Default is 1, fully opaque.
470
475
  * @param {number} alpha opacity level, ranging from 0 to 1
471
476
  * @example
472
- function draw() {
473
- background(200);
474
-
475
- opacity(1);
476
- circle(80, 80, 80);
477
+ createCanvas(200);
478
+ background(200);
477
479
 
478
- opacity(0.2);
479
- square(80, 80, 80);
480
- }
480
+ opacity(1);
481
+ circle(80, 80, 80);
482
+
483
+ opacity(0.2);
484
+ square(80, 80, 80);
481
485
  */
482
486
  function opacity(alpha: number): void;
483
487
 
@@ -487,19 +491,22 @@ function draw() {
487
491
  * Shadows apply to anything drawn to the canvas, including filled
488
492
  * shapes, strokes, text, and images.
489
493
  *
490
- * 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.
491
- * @param {string | Color} color shadow color
494
+ * Like the [`color`](https://q5js.org/learn/#color) function, this function
495
+ * can accept colors in a wide range of formats: as a CSS color string,
496
+ * a `Color` object, grayscale value, or color component values.
497
+ *
498
+ * Not available in q5 WebGPU.
499
+ * @param {Color} color shadow color
492
500
  * @example
493
- function draw() {
494
- background(200);
495
-
496
- noFill();
497
- shadow('black');
498
- rect(64, 60, 80, 80);
499
- text('q5', 100, 100);
500
- }
501
+ createCanvas(200);
502
+ background(200);
503
+
504
+ noFill();
505
+ shadow('black');
506
+ rect(64, 60, 80, 80);
507
+ text('q5', 100, 100);
501
508
  * @example
502
- createCanvas(200, 200);
509
+ createCanvas(200);
503
510
  let logo = loadImage('/assets/p5play_logo.webp');
504
511
 
505
512
  function setup() {
@@ -513,15 +520,14 @@ function setup() {
513
520
  /** ⬜️
514
521
  * Disables the shadow effect.
515
522
  * @example
516
- function draw() {
517
- background(200);
518
- noStroke();
519
- shadow('black');
520
- rect(14, 14, 80, 80);
523
+ createCanvas(200);
524
+ background(200);
525
+ noStroke();
526
+ shadow('black');
527
+ rect(14, 14, 80, 80);
521
528
 
522
- noShadow();
523
- rect(104, 104, 80, 80);
524
- }
529
+ noShadow();
530
+ rect(104, 104, 80, 80);
525
531
  */
526
532
  function noShadow(): void;
527
533
 
@@ -533,27 +539,38 @@ function draw() {
533
539
  * @param {number} offsetY vertical offset of the shadow, defaults to be the same as offsetX
534
540
  * @param {number} blur blur radius of the shadow, defaults to 0
535
541
  * @example
536
- function draw() {
537
- background(200);
538
- noStroke();
539
- shadow('red');
542
+ createCanvas(200);
543
+ noStroke();
544
+ shadow(50);
540
545
 
541
- shadowBox(-20, -8, 50);
546
+ function draw() {
547
+ background(200);
548
+ shadowBox(-20, mouseY, 10);
542
549
  circle(100, 100, 80, 80);
543
550
  }
544
551
  * @example
545
- function draw() {
546
- background(200);
547
- noStroke();
548
- shadow('aqua');
549
- shadowBox(20);
550
- rect(50, 50, 100, 100);
551
- textSize(64);
552
- text('q5', 60, 115);
553
- }
552
+ createCanvas(200);
553
+ background(200);
554
+ noStroke();
555
+
556
+ shadow('aqua');
557
+ shadowBox(20);
558
+ rect(50, 50, 100, 100);
559
+ textSize(64);
560
+ text('q5', 60, 115);
554
561
  */
555
562
  function shadowBox(offsetX: number, offsetY: number, blur: number): void;
556
563
 
564
+ /** ⬜️
565
+ * The width of the canvas.
566
+ */
567
+ var width: number;
568
+
569
+ /** ⬜️
570
+ * The height of the canvas.
571
+ */
572
+ var height: number;
573
+
557
574
  /** ⬜️
558
575
  * Translates the origin of the drawing context.
559
576
  * @param {number} x translation along the x-axis
@@ -655,35 +672,42 @@ function draw() {
655
672
  * q5 runs this function before every time the `draw` function is run,
656
673
  * so that transformations don't carry over to the next frame.
657
674
  * @example
658
- function draw() {
659
- background(200);
675
+ createCanvas(200);
676
+ background(200);
660
677
 
661
- translate(100, 100);
662
- circle(0, 0, 80);
678
+ translate(100, 100);
679
+ circle(0, 0, 80);
663
680
 
664
- resetMatrix();
665
- square(0, 0, 50);
666
- }
681
+ resetMatrix();
682
+ square(0, 0, 50);
667
683
  */
668
684
  function resetMatrix(): void;
669
685
 
670
686
  /** ⬜️
671
687
  * Saves the current transformation matrix.
672
688
  * @example
673
- function draw() {
674
- background(200);
675
- translate(100, 100);
676
- pushMatrix();
677
- rotate(QUARTER_PI);
678
- ellipse(0, 0, 120, 40);
679
- popMatrix();
680
- ellipse(0, 0, 120, 40);
681
- }
689
+ createCanvas(200);
690
+ background(200);
691
+ translate(100, 100);
692
+ pushMatrix();
693
+ rotate(QUARTER_PI);
694
+ ellipse(0, 0, 120, 40);
695
+ popMatrix();
696
+ ellipse(0, 0, 120, 40);
682
697
  */
683
698
  function pushMatrix(): void;
684
699
 
685
700
  /** ⬜️
686
701
  * Restores the previously saved transformation matrix.
702
+ * @example
703
+ createCanvas(200);
704
+ background(200);
705
+ translate(100, 100);
706
+ pushMatrix();
707
+ rotate(QUARTER_PI);
708
+ ellipse(0, 0, 120, 40);
709
+ popMatrix();
710
+ ellipse(0, 0, 120, 40);
687
711
  */
688
712
  function popMatrix(): void;
689
713
 
@@ -714,7 +738,7 @@ function draw() {
714
738
  /** ⬜️
715
739
  * Saves the current drawing style settings and transformations.
716
740
  * @example
717
- createCanvas(200, 200);
741
+ createCanvas(200);
718
742
 
719
743
  push();
720
744
  fill('blue');
@@ -761,9 +785,11 @@ square(0, 0, 50);
761
785
  /** ⬜️
762
786
  * Any position coordinates or dimensions you use will be scaled based
763
787
  * on the unit provided to this function.
788
+ *
789
+ * Not available in q5 WebGPU.
764
790
  * @param {number} unit unit to scale by
765
791
  * @example
766
- createCanvas(200, 200);
792
+ createCanvas(200);
767
793
  flexibleCanvas(100);
768
794
  // rect will appear in the middle of the canvas
769
795
  rect(20, 20, 60, 60);
@@ -772,6 +798,8 @@ rect(20, 20, 60, 60);
772
798
 
773
799
  /** ⬜️
774
800
  * Creates a graphics buffer.
801
+ *
802
+ * Not available in q5 WebGPU.
775
803
  * @param {number} w width
776
804
  * @param {number} h height
777
805
  * @param {Object} [opt] options
@@ -780,7 +808,8 @@ rect(20, 20, 60, 60);
780
808
  function createGraphics(w: number, h: number, opt?: any): Q5;
781
809
 
782
810
  /** ⬜️
783
- * The 2D rendering context for the canvas.
811
+ * The 2D rendering context for the canvas, if using the Canvas2D
812
+ * renderer.
784
813
  */
785
814
  var ctx: CanvasRenderingContext2D;
786
815
 
@@ -792,7 +821,7 @@ rect(20, 20, 60, 60);
792
821
  // 💻 display
793
822
 
794
823
  /** 💻
795
- * The `displayMode` function lets you customize how your canvas is presented.
824
+ * Customize how your canvas is presented.
796
825
  * @param {string} mode
797
826
  * - "normal": (default) no styling to canvas or its parent element
798
827
  * - "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
@@ -814,17 +843,21 @@ circle(25, 12.5, 16);
814
843
 
815
844
  /** 🧑‍🎨
816
845
  * Draws over the entire canvas with a color or image.
817
- * @param {string | number} color color or image to draw
846
+ *
847
+ * Like the [`color`](https://q5js.org/learn/#color) function,
848
+ * this function can accept colors in a wide range of formats:
849
+ * CSS color string, grayscale value, and color component values.
850
+ * @param {Color | Image} filler a color or image to draw
818
851
  * @example
819
852
  createCanvas(200, 100);
820
853
  background('crimson');
821
854
  * @example
822
855
  function draw() {
823
- background(128, 20);
856
+ background(128, 100);
824
857
  circle(mouseX, mouseY, 20);
825
858
  }
826
859
  */
827
- function background(color: string | number): void;
860
+ function background(filler: Color | Image): void;
828
861
 
829
862
  /** 🧑‍🎨
830
863
  * Draws a rectangle or a rounded rectangle.
@@ -837,7 +870,7 @@ function draw() {
837
870
  * @param {number} [br] bottom-right radius
838
871
  * @param {number} [bl] bottom-left radius
839
872
  * @example
840
- createCanvas(200, 200);
873
+ createCanvas(200);
841
874
  background(200);
842
875
 
843
876
  rect(30, 20, 40, 60);
@@ -856,7 +889,7 @@ rect(130, 120, 40, 60, 30, 2, 8, 20);
856
889
  * @param {number} [br] bottom-right radius
857
890
  * @param {number} [bl] bottom-left radius
858
891
  * @example
859
- createCanvas(200, 200);
892
+ createCanvas(200);
860
893
  background(200);
861
894
 
862
895
  square(30, 30, 40);
@@ -900,7 +933,7 @@ ellipse(100, 50, 160, 80);
900
933
  * @param {number} stop angle to stop the arc
901
934
  * @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`
902
935
  * @example
903
- createCanvas(200, 200);
936
+ createCanvas(200);
904
937
  background(200);
905
938
 
906
939
  arc(40, 40, 40, 40, 0.8, -0.8);
@@ -1096,6 +1129,263 @@ point(125, 50);
1096
1129
  */
1097
1130
  function inStroke(x: number, y: number): boolean;
1098
1131
 
1132
+ // 📑 dom
1133
+
1134
+ /** 📑
1135
+ * Creates a new HTML element and adds it to the page. `createEl` is
1136
+ * an alias.
1137
+ *
1138
+ * The element is part of the DOM (Document Object Model), an interface for
1139
+ * creating and editing web pages with JavaScript.
1140
+ *
1141
+ * Modify the element's CSS [`style`](https://developer.mozilla.org/docs/Web/API/HTMLElement/style) to change its appearance.
1142
+ *
1143
+ * Use [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) to respond to events such as:
1144
+ * - "click": when the element is clicked
1145
+ * - "mouseover": when the mouse hovers over the element
1146
+ * - "mouseout": when the mouse stops hovering over the element
1147
+ * - "input": when a form element's value changes
1148
+ *
1149
+ * q5 adds some extra functionality to the elements it creates:
1150
+ *
1151
+ * - the `position` function makes it easy to place the element
1152
+ * relative to the canvas
1153
+ * - the `size` function sets the width and height of the element
1154
+ * - alternatively, use the element's `x`, `y`, `width`, and `height` properties
1155
+ * @param {string} tag tag name of the element
1156
+ * @param {string} [content] content of the element
1157
+ * @returns {HTMLElement} element
1158
+ * @example
1159
+ createCanvas(200);
1160
+
1161
+ let el = createEl('div', '*');
1162
+ el.position(50, 50);
1163
+ el.size(100, 100);
1164
+ el.style.fontSize = '136px';
1165
+ el.style.textAlign = 'center';
1166
+ el.style.backgroundColor = 'blue';
1167
+ el.style.color = 'white';
1168
+ */
1169
+ function createElement(tag: string, content?: string): HTMLElement;
1170
+
1171
+ /** 📑
1172
+ * Creates a link element.
1173
+ * @param {string} href url
1174
+ * @param {string} [text] text content
1175
+ * @param {boolean} [newTab] whether to open the link in a new tab
1176
+ * @example
1177
+ createCanvas(200);
1178
+
1179
+ let link = createA('https://q5js.org', 'q5.js');
1180
+ link.position(16, 42);
1181
+ link.style.fontSize = '80px';
1182
+
1183
+ link.addEventListener('mouseover', () => {
1184
+ background('blue');
1185
+ });
1186
+ */
1187
+ function createA(href: string, text?: string): HTMLAnchorElement;
1188
+
1189
+ /** 📑
1190
+ * Creates a button element.
1191
+ * @param {string} [content] text content
1192
+ * @example
1193
+ createCanvas(200, 100);
1194
+
1195
+ let btn = createButton('Click me!');
1196
+
1197
+ btn.addEventListener('click', () => {
1198
+ background(random(100, 255));
1199
+ });
1200
+ */
1201
+ function createButton(content?: string): HTMLButtonElement;
1202
+
1203
+ /** 📑
1204
+ * Creates a checkbox element.
1205
+ *
1206
+ * Use the `checked` property to get or set the checkbox's state.
1207
+ *
1208
+ * The `label` property is the text label element next to the checkbox.
1209
+ * @param {string} [label] text label placed next to the checkbox
1210
+ * @param {boolean} [checked] initial state
1211
+ * @example
1212
+ createCanvas(200, 100);
1213
+
1214
+ let box = createCheckbox('Check me!');
1215
+ box.label.style.color = 'lime';
1216
+
1217
+ box.addEventListener('input', () => {
1218
+ if (box.checked) background('lime');
1219
+ else background('black');
1220
+ });
1221
+ */
1222
+ function createCheckbox(label?: string, checked?: boolean): HTMLInputElement;
1223
+
1224
+ /** 📑
1225
+ * Creates a color input element.
1226
+ *
1227
+ * Use the `value` property to get or set the color value.
1228
+ * @param {string} [value] initial color value
1229
+ * @example
1230
+ createCanvas(200, 100);
1231
+
1232
+ let picker = createColorPicker();
1233
+ picker.value = '#fd7575';
1234
+
1235
+ function draw() {
1236
+ background(picker.value);
1237
+ }
1238
+ */
1239
+ function createColorPicker(value?: string): HTMLInputElement;
1240
+
1241
+ /** 📑
1242
+ * Creates an image element.
1243
+ * @param {string} src url of the image
1244
+ * @example
1245
+ createCanvas(200, 100);
1246
+
1247
+ let img = createImg('/assets/p5play_logo.webp')
1248
+ .position(0, 0)
1249
+ .size(100, 100);
1250
+ */
1251
+ function createImg(src: string): HTMLImageElement;
1252
+
1253
+ /** 📑
1254
+ * Creates an input element.
1255
+ *
1256
+ * Use the `value` property to get or set the input's value.
1257
+ *
1258
+ * See MDN's [input documentation](https://developer.mozilla.org/docs/Web/HTML/Element/input#input_types) for the full list of input types.
1259
+ * @param {string} [value] initial value
1260
+ * @param {string} [type] text input type, can be 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
1261
+ * @example
1262
+ createCanvas(200, 100);
1263
+ textSize(64);
1264
+
1265
+ let input = createInput();
1266
+ input.placeholder = 'Type here!';
1267
+ input.size(200, 32);
1268
+
1269
+ input.addEventListener('input', () => {
1270
+ background('orange');
1271
+ text(input.value, 10, 70);
1272
+ });
1273
+ */
1274
+ function createInput(value?: string, type?: string): HTMLInputElement;
1275
+
1276
+ /** 📑
1277
+ * Creates a paragraph element.
1278
+ * @param {string} [content] text content
1279
+ * @example
1280
+ createCanvas(200, 50);
1281
+ background('coral');
1282
+
1283
+ let p = createP('Hello, world!');
1284
+ p.style.color = 'pink';
1285
+ */
1286
+ function createP(content?: string): HTMLParagraphElement;
1287
+
1288
+ /** 📑
1289
+ * Creates a radio button group.
1290
+ *
1291
+ * Use the `option(label, value)` function to add new radio buttons
1292
+ * to the group.
1293
+ *
1294
+ * Use the `value` property to get or set the value of the selected radio button.
1295
+ * @param {string} [groupName]
1296
+ * @example
1297
+ createCanvas(200, 100);
1298
+
1299
+ let radio = createRadio()
1300
+ .option('square', '1')
1301
+ .option('circle', '2');
1302
+ radio.style.color = 'aqua';
1303
+
1304
+ function draw() {
1305
+ background(200);
1306
+ if (radio.value == '1') square(75, 25, 50);
1307
+ if (radio.value == '2') circle(100, 50, 50);
1308
+ }
1309
+ */
1310
+ function createRadio(groupName): HTMLDivElement;
1311
+
1312
+ /** 📑
1313
+ * Creates a select element.
1314
+ *
1315
+ * Use the `option(label, value)` function to add new options to
1316
+ * the select element.
1317
+ *
1318
+ * Set `multiple` to `true` to allow multiple options to be selected.
1319
+ *
1320
+ * Use the `value` property to get or set the selected option value.
1321
+ *
1322
+ * Use the `selected` property get the labels of the selected
1323
+ * options or set the selected options by label. Can be a single
1324
+ * string or an array of strings.
1325
+ * @param {string} [placeholder] optional placeholder text that appears before an option is selected
1326
+ * @example
1327
+ createCanvas(200, 100);
1328
+
1329
+ let sel = createSelect('Select a color')
1330
+ .option('Red', '#f55')
1331
+ .option('Green', '#5f5');
1332
+
1333
+ sel.addEventListener('change', () => {
1334
+ background(sel.value);
1335
+ });
1336
+ */
1337
+ function createSelect(placeholder): HTMLSelectElement;
1338
+
1339
+ /** 📑
1340
+ * Creates a slider element.
1341
+ *
1342
+ * Use the `value` property to get or set the slider's value.
1343
+ *
1344
+ * Use the `val` function to get the slider's value as a number.
1345
+ * @param {number} min minimum value
1346
+ * @param {number} max maximum value
1347
+ * @param {number} [value] initial value
1348
+ * @param {number} [step] step size
1349
+ * @example
1350
+ createCanvas(200);
1351
+
1352
+ let slider = createSlider(0, 255)
1353
+ .position(10, 10)
1354
+ .size(180);
1355
+
1356
+ function draw() {
1357
+ background(slider.val());
1358
+ }
1359
+ */
1360
+ function createSlider(min: number, max: number, value?: number, step?: number): HTMLInputElement;
1361
+
1362
+ /** 📑
1363
+ * Creates a video element.
1364
+ * @param {string} src url of the video
1365
+ * @example
1366
+ createCanvas(200, 100);
1367
+
1368
+ // example coming soon
1369
+ // let vid = createVideo('/assets/q5js_video.mp4');
1370
+ // vid.controls = true;
1371
+ // vid.loop = true;
1372
+ */
1373
+ function createVideo(src: string): HTMLVideoElement;
1374
+
1375
+ /** 📑
1376
+ * Finds the first element in the DOM that matches the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
1377
+ * @param {string} selector
1378
+ * @returns {HTMLElement} element
1379
+ */
1380
+ function findElement(selector: string): HTMLElement;
1381
+
1382
+ /** 📑
1383
+ * Finds all elements in the DOM that match the given [CSS selector](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors).
1384
+ * @param {string} selector
1385
+ * @returns {HTMLElement[]} elements
1386
+ */
1387
+ function findElements(selector: string): HTMLElement[];
1388
+
1099
1389
  // 🌆 image
1100
1390
 
1101
1391
  /** 🌆
@@ -1104,7 +1394,7 @@ point(125, 50);
1104
1394
  * @param {(img: any) => void} [cb] callback function after the image is loaded
1105
1395
  * @param {any} [opt] optional parameters for loading the image
1106
1396
  * @example
1107
- createCanvas(200, 200);
1397
+ createCanvas(200);
1108
1398
 
1109
1399
  let logo = loadImage('/q5js_logo.webp');
1110
1400
 
@@ -1126,7 +1416,7 @@ function draw() {
1126
1416
  * @param {number} [sw] width of the subsection of the source image
1127
1417
  * @param {number} [sh] height of the subsection of the source image
1128
1418
  * @example
1129
- createCanvas(200, 200);
1419
+ createCanvas(200);
1130
1420
 
1131
1421
  let logo = loadImage('/q5js_logo.webp');
1132
1422
 
@@ -1143,7 +1433,7 @@ function draw() {
1143
1433
  * `CENTER`: images will be drawn centered at (dx, dy)
1144
1434
  * @param {string} mode
1145
1435
  * @example
1146
- createCanvas(200, 200);
1436
+ createCanvas(200);
1147
1437
 
1148
1438
  let logo = loadImage('/q5js_logo.webp');
1149
1439
 
@@ -1174,7 +1464,7 @@ function draw() {
1174
1464
  * @param {number} w new width
1175
1465
  * @param {number} h new height
1176
1466
  * @example
1177
- createCanvas(200, 200);
1467
+ createCanvas(200);
1178
1468
 
1179
1469
  let logo = loadImage('/q5js_logo.webp');
1180
1470
 
@@ -1196,7 +1486,7 @@ function setup() {
1196
1486
  * their actual size. This is the default setting, so running this
1197
1487
  * function only has an effect if `noSmooth` has been called.
1198
1488
  * @example
1199
- createCanvas(200, 200);
1489
+ createCanvas(200);
1200
1490
 
1201
1491
  let icon = loadImage('/q5js_icon.png');
1202
1492
 
@@ -1209,7 +1499,7 @@ function setup() {
1209
1499
  /** 🌆
1210
1500
  * Disables smooth image rendering for a pixelated look.
1211
1501
  * @example
1212
- createCanvas(200, 200);
1502
+ createCanvas(200);
1213
1503
 
1214
1504
  let icon = loadImage('/q5js_icon.png');
1215
1505
 
@@ -1240,7 +1530,7 @@ function setup() {
1240
1530
  * each copy separately.
1241
1531
  * @param {string | number} color tint color
1242
1532
  * @example
1243
- createCanvas(200, 200);
1533
+ createCanvas(200);
1244
1534
 
1245
1535
  let logo = loadImage('/q5js_logo.webp');
1246
1536
 
@@ -1279,7 +1569,7 @@ function setup() {
1279
1569
  * @param {number} [h] height of the area
1280
1570
  * @returns {Image | number[]}
1281
1571
  * @example
1282
- createCanvas(200, 200);
1572
+ createCanvas(200);
1283
1573
 
1284
1574
  let logo = loadImage('/q5js_logo.webp');
1285
1575
 
@@ -1301,7 +1591,7 @@ function setup() {
1301
1591
  * @param {number} y
1302
1592
  * @param {any} c color, canvas, or image
1303
1593
  * @example
1304
- createCanvas(200, 200);
1594
+ createCanvas(200);
1305
1595
  let c = color('lime');
1306
1596
 
1307
1597
  function draw() {
@@ -1329,7 +1619,7 @@ function draw() {
1329
1619
  * @param {number} dw width of the destination region
1330
1620
  * @param {number} dh height of the destination region
1331
1621
  * @example
1332
- createCanvas(200, 200);
1622
+ createCanvas(200);
1333
1623
 
1334
1624
  let logo = loadImage('/q5js_logo.webp');
1335
1625
 
@@ -1348,7 +1638,7 @@ function setup() {
1348
1638
  /** 🌆
1349
1639
  * Loads pixel data into the canvas' or image's `pixels` array.
1350
1640
  * @example
1351
- createCanvas(200, 200);
1641
+ createCanvas(200);
1352
1642
  let icon = loadImage('/q5js_icon.png');
1353
1643
 
1354
1644
  function setup() {
@@ -1363,7 +1653,7 @@ function setup() {
1363
1653
  /** 🌆
1364
1654
  * Applies changes in the `pixels` array to the canvas or image.
1365
1655
  * @example
1366
- createCanvas(200, 200);
1656
+ createCanvas(200);
1367
1657
  function setup() {
1368
1658
  for (let x = 0; x < 200; x += 5) {
1369
1659
  for (let y = 0; y < 200; y += 5) {
@@ -1391,7 +1681,7 @@ function setup() {
1391
1681
  * @param {string} type filter type or a CSS filter string
1392
1682
  * @param {number} [value] optional value, depends on filter type
1393
1683
  * @example
1394
- createCanvas(200, 200);
1684
+ createCanvas(200);
1395
1685
  let logo = loadImage('/q5js_logo.webp');
1396
1686
 
1397
1687
  function setup() {
@@ -1443,8 +1733,8 @@ function setup() {
1443
1733
 
1444
1734
  /** 🌆
1445
1735
  * Creates a new image.
1446
- * @param {number} [w] character limit per line
1447
- * @param {number} [h] line limit
1736
+ * @param {number} w width
1737
+ * @param {number} h height
1448
1738
  * @param {any} [opt] optional settings for the image
1449
1739
  * @returns {Image}
1450
1740
  */
@@ -1461,19 +1751,20 @@ function setup() {
1461
1751
  * @param {number} [wrapWidth] maximum line width in characters
1462
1752
  * @param {number} [lineLimit] maximum number of lines
1463
1753
  * @example
1464
- createCanvas(200, 200);
1754
+ createCanvas(200);
1465
1755
  background('silver');
1466
1756
 
1467
1757
  textSize(32);
1468
1758
  text('Hello, world!', 12, 106);
1469
1759
  * @example
1470
- createCanvas(200, 200);
1760
+ createCanvas(200);
1471
1761
  background(200);
1472
1762
  textSize(20);
1473
1763
 
1474
1764
  let info = "q5.js is a JavaScript library for creative coding. It's a sequel to p5.js that's optimized for interactive art.";
1475
1765
 
1476
1766
  text(info, 12, 30, 20, 6);
1767
+ //
1477
1768
  //
1478
1769
  */
1479
1770
  function text(str: string, x: number, y: number, wrapWidth?: number, lineLimit?: number): void;
@@ -1497,7 +1788,7 @@ text(info, 12, 30, 20, 6);
1497
1788
  * @param {(font: FontFace) => void} [cb] optional callback function that receives the font name as an argument once the font is loaded
1498
1789
  * @returns {FontFace} font
1499
1790
  * @example
1500
- createCanvas(200, 200);
1791
+ createCanvas(200);
1501
1792
 
1502
1793
  loadFont('/assets/Robotica.ttf');
1503
1794
 
@@ -1520,7 +1811,7 @@ function setup() {
1520
1811
  * https://developer.mozilla.org/docs/Web/CSS/font-family
1521
1812
  * @param {string} fontName name of the font family or a FontFace object
1522
1813
  * @example
1523
- createCanvas(200, 200);
1814
+ createCanvas(200);
1524
1815
  background(200);
1525
1816
 
1526
1817
  textFont('serif');
@@ -1563,7 +1854,7 @@ function draw() {
1563
1854
  * Sets the current text style.
1564
1855
  * @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
1565
1856
  * @example
1566
- createCanvas(200, 200);
1857
+ createCanvas(200);
1567
1858
  background(200);
1568
1859
 
1569
1860
  textStyle(ITALIC);
@@ -1578,7 +1869,7 @@ text('Hello, world!', 12, 106);
1578
1869
  * @param {'left' | 'center' | 'right'} horiz horizontal alignment
1579
1870
  * @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
1580
1871
  * @example
1581
- createCanvas(200, 200);
1872
+ createCanvas(200);
1582
1873
  background(200);
1583
1874
 
1584
1875
  textAlign(CENTER, MIDDLE);
@@ -1623,7 +1914,7 @@ function draw() {
1623
1914
  * @param {string} str string to measure
1624
1915
  * @returns {number} descent of the text in pixels
1625
1916
  * @example
1626
- createCanvas(200, 200);
1917
+ createCanvas(200);
1627
1918
  background(200);
1628
1919
  textSize(64);
1629
1920
 
@@ -1723,30 +2014,54 @@ createCanvas(200, 200);
1723
2014
  // 🎨 color
1724
2015
 
1725
2016
  /** 🎨
1726
- * Creates a new `Color` object. This function can parse different
1727
- * color representations depending on the current color mode.
2017
+ * Creates a new `Color` object, which is primarily useful for storing
2018
+ * a color that your sketch will reuse or modify later.
1728
2019
  *
1729
- * RGB colors have components `r`/`red`, `g`/`green`, `b`/`blue`,
1730
- * and `a`/`alpha`.
2020
+ * With the default RGB color mode, colors have these components:
1731
2021
  *
1732
- * When only one numeric input is provided, it'll be interpreted
1733
- * as a grayscale value. If only two numeric inputs are provided,
1734
- * they will be used as grayscale and alpha values.
2022
+ * `r`/`red`, `g`/`green`, `b`/`blue`, and `a`/`alpha`.
1735
2023
  *
1736
- * [`fill`](https://q5js.org/learn/#fill), [`stroke`](https://q5js.org/learn/#stroke), and [`background`](https://q5js.org/learn/#background) functions can accept the same
1737
- * wide range of inputs as this function.
1738
- * @param {string | number | Color | number[]} c0 first color component, a CSS color string, a `Color` object (to make copy), or an array of components
2024
+ * The default color format is integer, so set color components
2025
+ * to values between 0 and 255.
2026
+ *
2027
+ * In q5 WebGPU, the default color mode is RGB in float format, so
2028
+ * set color components to values between 0 and 1.
2029
+ *
2030
+ * The [`fill`](https://q5js.org/learn/#fill), [`stroke`](https://q5js.org/learn/#stroke), and [`background`](https://q5js.org/learn/#background) functions
2031
+ * accept the same wide range of color representations as this function.
2032
+ *
2033
+ * Here are some examples of valid use:
2034
+ *
2035
+ * - `color(255)` (grayscale)
2036
+ * - `color(255, 200)` (grayscale, alpha)
2037
+ * - `color(255, 0, 0)` (r, g, b)
2038
+ * - `color(255, 0, 0, 10)` (r, g, b, a)
2039
+ * - `color('red')` (colorName)
2040
+ * - `color('#ff0000')` (hexColor)
2041
+ * - `color([255, 0, 0])` (colorComponents)
2042
+ * @param {string | number | Color | number[]} c0 color or first color component
1739
2043
  * @param {number} [c1] second color component
1740
2044
  * @param {number} [c2] third color component
1741
2045
  * @param {number} [c3] fourth color component (alpha)
1742
2046
  * @returns {Color} a new `Color` object
1743
2047
  * @example
1744
- createCanvas(200, 200);
2048
+ createCanvas(200);
2049
+ rect(0, 0, 100, 200);
1745
2050
 
1746
- let c = color('gray');
2051
+ // ( r, g, b, a)
2052
+ let bottle = color(90, 100, 255, 100);
2053
+ fill(bottle);
2054
+ stroke(bottle);
2055
+ strokeWeight(30);
2056
+ circle(100, 100, 155);
2057
+ * @example
2058
+ createCanvas(200);
2059
+ // (gray, alpha)
2060
+ let c = color(200, 50);
1747
2061
 
1748
2062
  function draw() {
1749
2063
  background(c);
2064
+ circle(mouseX, mouseY, 50);
1750
2065
  c.g = (c.g + 1) % 255;
1751
2066
  }
1752
2067
  */
@@ -1763,7 +2078,7 @@ function draw() {
1763
2078
  * @param {'rgb' | 'srgb' | 'oklch'} mode color mode
1764
2079
  * @param {1 | 255} format color format (1 for float, 255 for integer)
1765
2080
  * @example
1766
- createCanvas(200, 200);
2081
+ createCanvas(200);
1767
2082
 
1768
2083
  colorMode(RGB, 1);
1769
2084
  fill(1, 0, 0);
@@ -1773,12 +2088,13 @@ rect(66, 0, 67, 200);
1773
2088
  fill(0, 0, 1);
1774
2089
  rect(133, 0, 67, 200);
1775
2090
  * @example
1776
- createCanvas(200, 200);
2091
+ createCanvas(200);
1777
2092
 
1778
2093
  colorMode(OKLCH);
1779
2094
 
1780
2095
  fill(0.25, 0.15, 0);
1781
2096
  rect(0, 0, 100, 200);
2097
+
1782
2098
  fill(0.75, 0.15, 0)
1783
2099
  rect(100, 0, 100, 200);
1784
2100
  */
@@ -1794,7 +2110,7 @@ rect(100, 0, 100, 200);
1794
2110
  * rgb colors are mapped to the full P3 gamut, even when they use the
1795
2111
  * legacy integer format.
1796
2112
  * @example
1797
- createCanvas(200, 200);
2113
+ createCanvas(200);
1798
2114
 
1799
2115
  function setup() {
1800
2116
  background(255, 0, 0);
@@ -1809,7 +2125,7 @@ function setup() {
1809
2125
  * example, note that full red appears less saturated, as it would
1810
2126
  * on an SDR display.
1811
2127
  * @example
1812
- createCanvas(200, 200);
2128
+ createCanvas(200);
1813
2129
 
1814
2130
  colorMode(SRGB, 255);
1815
2131
 
@@ -1843,7 +2159,7 @@ function setup() {
1843
2159
  *
1844
2160
  * Note how seamless the hue transitions are in the following example.
1845
2161
  * @example
1846
- createCanvas(200, 200);
2162
+ createCanvas(200);
1847
2163
  colorMode(OKLCH);
1848
2164
 
1849
2165
  function draw() {
@@ -1963,7 +2279,7 @@ function draw() {
1963
2279
  /** 🖲️
1964
2280
  * Hides the cursor within the bounds of the canvas.
1965
2281
  * @example
1966
- createCanvas(200, 200);
2282
+ createCanvas(200);
1967
2283
  noCursor();
1968
2284
  */
1969
2285
  function noCursor(): void;
@@ -2147,6 +2463,75 @@ noCursor();
2147
2463
  */
2148
2464
  const TAU: number;
2149
2465
 
2466
+ // 🎞️ record
2467
+
2468
+ /** 🎞️
2469
+ * Creates a recorder. Simply hit record to start recording!
2470
+ *
2471
+ * Recording large canvases is an intensive process, so your
2472
+ * computer may not be able to do it in real time. That's okay,
2473
+ * the resulting video will playback at your sketch's target
2474
+ * frame rate.
2475
+ *
2476
+ * In cases where real time interaction is a priority, consider
2477
+ * reducing the canvas' size, frame rate, and/or recording
2478
+ * quality.
2479
+ *
2480
+ * `format` and `quality` properties are set
2481
+ * automatically based on the height of the canvas. They can be
2482
+ * changed via the UI or programmatically.
2483
+ *
2484
+ * The recorder uses the [`MediaRecorder`](https://developer.mozilla.org/docs/Web/API/MediaRecorder/MediaRecorder) API, which
2485
+ * unfortunately can't encode HDR video.
2486
+ * @returns {HTMLElement} a recorder, q5 DOM element
2487
+ * @example
2488
+ createCanvas(200);
2489
+
2490
+ createRecorder();
2491
+
2492
+ function draw() {
2493
+ circle(mouseX, random(canvas.h), 10);
2494
+ }
2495
+ */
2496
+ function createRecorder(): HTMLElement;
2497
+
2498
+ /** 🎞️
2499
+ * Starts recording the canvas or resumes recording if it was paused.
2500
+ *
2501
+ * If no recorder exists, one is created but not displayed.
2502
+ */
2503
+ function record(): void;
2504
+
2505
+ /** 🎞️
2506
+ * Pauses the canvas recording, if one is in progress.
2507
+ */
2508
+ function pauseRecording(): void;
2509
+
2510
+ /** 🎞️
2511
+ * Discards the current recording.
2512
+ */
2513
+ function deleteRecording(): void;
2514
+
2515
+ /** 🎞️
2516
+ * Saves the current recording as a video file.
2517
+ * @param {string} fileName
2518
+ * @example
2519
+ function draw() {
2520
+ square(mouseX, random(canvas.h), 10);
2521
+ }
2522
+
2523
+ function mousePressed() {
2524
+ if (!recording) record();
2525
+ else saveRecording('squares');
2526
+ }
2527
+ */
2528
+ function saveRecording(fileName): void;
2529
+
2530
+ /** 🎞️
2531
+ * True if the canvas is currently being recorded.
2532
+ */
2533
+ var recording: boolean;
2534
+
2150
2535
  // 🔊 sound
2151
2536
 
2152
2537
  /** 🔊
@@ -2169,7 +2554,7 @@ noCursor();
2169
2554
  * @param {string} url sound file
2170
2555
  * @returns {Sound} a new `Sound` object
2171
2556
  * @example
2172
- createCanvas(200, 200);
2557
+ createCanvas(200);
2173
2558
 
2174
2559
  let sound = loadSound('/assets/jump.wav');
2175
2560
  sound.volume = 0.3;
@@ -2190,7 +2575,7 @@ function mousePressed() {
2190
2575
  * @param url audio file
2191
2576
  * @returns {HTMLAudioElement} an HTMLAudioElement
2192
2577
  * @example
2193
- createCanvas(200, 200);
2578
+ createCanvas(200);
2194
2579
 
2195
2580
  let audio = loadAudio('/assets/retro.flac');
2196
2581
  audio.volume = 0.4;
@@ -2299,7 +2684,7 @@ function draw() {
2299
2684
  }
2300
2685
  * @example
2301
2686
  new Q5();
2302
- createCanvas(200, 200);
2687
+ createCanvas(200);
2303
2688
 
2304
2689
  // use with top level await in a module
2305
2690
  await load('/assets/Robotica.ttf');
@@ -2308,7 +2693,7 @@ background(255);
2308
2693
  text('Hello, world!', 20, 100);
2309
2694
  * @example
2310
2695
  let q = new Q5();
2311
- createCanvas(200, 200);
2696
+ createCanvas(200);
2312
2697
 
2313
2698
  let [jump, retro] = await load(
2314
2699
  '/assets/jump.wav', '/assets/retro.flac'