q5 3.4.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/package.json +3 -3
- package/q5.d.ts +431 -384
- package/q5.js +163 -89
- package/q5.min.js +2 -2
package/q5.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* q5.d.ts
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* TypeScript definitions for q5.js to use with IDEs like VSCode
|
|
5
5
|
* for autocompletion, hover over documentation, and type checking.
|
|
6
6
|
*/
|
|
@@ -9,27 +9,76 @@ declare global {
|
|
|
9
9
|
|
|
10
10
|
/** ⭐️
|
|
11
11
|
* Welcome to q5's documentation! 🤩
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* First time coding? Check out the [q5 Beginner's Brief](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Brief).
|
|
14
|
-
*
|
|
15
|
-
* On these Learn pages, you can experiment with editing the
|
|
14
|
+
*
|
|
15
|
+
* On these Learn pages, you can experiment with editing the
|
|
16
16
|
* interactive mini examples. Have fun! 😎
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/** ⭐️
|
|
20
20
|
* The draw function is run 60 times per second by default.
|
|
21
21
|
* @example
|
|
22
|
-
|
|
22
|
+
function draw() {
|
|
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
|
+
|
|
29
78
|
/** ⭐️
|
|
30
79
|
* The number of frames that have been displayed since the program started.
|
|
31
80
|
* @example
|
|
32
|
-
|
|
81
|
+
function draw() {
|
|
33
82
|
background(200);
|
|
34
83
|
textSize(64);
|
|
35
84
|
text(frameCount, 8, 120);
|
|
@@ -40,7 +89,7 @@ Q5.draw = function () {
|
|
|
40
89
|
/** ⭐️
|
|
41
90
|
* Stops the draw loop.
|
|
42
91
|
* @example
|
|
43
|
-
|
|
92
|
+
function draw() {
|
|
44
93
|
circle(frameCount * 5, 100, 80);
|
|
45
94
|
noLoop();
|
|
46
95
|
}
|
|
@@ -54,13 +103,13 @@ Q5.draw = function () {
|
|
|
54
103
|
* This is an async function.
|
|
55
104
|
* @param {number} [n] number of times to redraw the canvas, default is 1
|
|
56
105
|
* @example
|
|
57
|
-
|
|
106
|
+
createCanvas(200);
|
|
58
107
|
noLoop();
|
|
59
108
|
|
|
60
|
-
|
|
109
|
+
function draw() {
|
|
61
110
|
circle(frameCount * 5, 100, 80);
|
|
62
111
|
}
|
|
63
|
-
|
|
112
|
+
function mousePressed() {
|
|
64
113
|
redraw(10);
|
|
65
114
|
}
|
|
66
115
|
*/
|
|
@@ -69,13 +118,13 @@ Q5.mousePressed = function () {
|
|
|
69
118
|
/** ⭐️
|
|
70
119
|
* Starts the draw loop again if it was stopped.
|
|
71
120
|
* @example
|
|
72
|
-
|
|
121
|
+
createCanvas(200);
|
|
73
122
|
noLoop();
|
|
74
123
|
|
|
75
|
-
|
|
124
|
+
function draw() {
|
|
76
125
|
circle(frameCount * 5, 100, 80);
|
|
77
126
|
}
|
|
78
|
-
|
|
127
|
+
function mousePressed() {
|
|
79
128
|
loop();
|
|
80
129
|
}
|
|
81
130
|
*/
|
|
@@ -91,7 +140,7 @@ Q5.mousePressed = function () {
|
|
|
91
140
|
* @param {number} [hertz] target frame rate, default is 60
|
|
92
141
|
* @returns {number} current frame rate
|
|
93
142
|
* @example
|
|
94
|
-
|
|
143
|
+
function draw() {
|
|
95
144
|
background(200);
|
|
96
145
|
|
|
97
146
|
if (mouseIsPressed) frameRate(10);
|
|
@@ -100,7 +149,7 @@ Q5.draw = function () {
|
|
|
100
149
|
circle(frameCount % 200, 100, 80);
|
|
101
150
|
}
|
|
102
151
|
* @example
|
|
103
|
-
|
|
152
|
+
function draw() {
|
|
104
153
|
background(200);
|
|
105
154
|
textSize(64);
|
|
106
155
|
text(round(frameRate()), 65, 120);
|
|
@@ -112,7 +161,7 @@ Q5.draw = function () {
|
|
|
112
161
|
* The desired frame rate of the sketch.
|
|
113
162
|
* @returns {number} target frame rate
|
|
114
163
|
* @example
|
|
115
|
-
|
|
164
|
+
function draw() {
|
|
116
165
|
background(200);
|
|
117
166
|
textSize(64);
|
|
118
167
|
|
|
@@ -129,7 +178,7 @@ Q5.draw = function () {
|
|
|
129
178
|
* performance analysis.
|
|
130
179
|
* @returns {number} frames per second
|
|
131
180
|
* @example
|
|
132
|
-
|
|
181
|
+
function draw() {
|
|
133
182
|
background(200);
|
|
134
183
|
frameRate(1);
|
|
135
184
|
textSize(64);
|
|
@@ -142,8 +191,8 @@ Q5.draw = function () {
|
|
|
142
191
|
/** ⭐️
|
|
143
192
|
* Logs a message to the JavaScript console. Alias for the standard
|
|
144
193
|
* [`console.log`](https://developer.mozilla.org/docs/Web/API/console/log_static) function.
|
|
145
|
-
*
|
|
146
|
-
* You can open web developer tools in most browsers by using the
|
|
194
|
+
*
|
|
195
|
+
* You can open web developer tools in most browsers by using the
|
|
147
196
|
* keyboard shortcut `Ctrl + Shift + i` or `command + option + i`,
|
|
148
197
|
* then click the "Console" tab.
|
|
149
198
|
* @param {*} message message to log
|
|
@@ -158,12 +207,12 @@ Q5.draw = function () {
|
|
|
158
207
|
* addons like p5play that auto-draw to the canvas after the `draw`
|
|
159
208
|
* function is run.
|
|
160
209
|
* @example
|
|
161
|
-
|
|
210
|
+
function draw() {
|
|
162
211
|
background(200);
|
|
163
212
|
circle(frameCount % 200, 100, 80);
|
|
164
213
|
}
|
|
165
214
|
|
|
166
|
-
|
|
215
|
+
function postProcess() {
|
|
167
216
|
filter(INVERT);
|
|
168
217
|
}
|
|
169
218
|
*/
|
|
@@ -172,7 +221,7 @@ Q5.postProcess = function () {
|
|
|
172
221
|
/** ⭐️
|
|
173
222
|
* The width of the window.
|
|
174
223
|
* @example
|
|
175
|
-
|
|
224
|
+
function draw() {
|
|
176
225
|
background(200);
|
|
177
226
|
textSize(64);
|
|
178
227
|
textAlign(CENTER, CENTER);
|
|
@@ -184,7 +233,7 @@ Q5.draw = function () {
|
|
|
184
233
|
/** ⭐️
|
|
185
234
|
* The height of the window.
|
|
186
235
|
* @example
|
|
187
|
-
|
|
236
|
+
function draw() {
|
|
188
237
|
background(200);
|
|
189
238
|
textSize(64);
|
|
190
239
|
textAlign(CENTER, CENTER);
|
|
@@ -204,13 +253,13 @@ Q5.draw = function () {
|
|
|
204
253
|
* rates are consistently low, consider reducing the target frame
|
|
205
254
|
* rate instead.
|
|
206
255
|
* @example
|
|
207
|
-
|
|
256
|
+
function draw() {
|
|
208
257
|
background(200);
|
|
209
258
|
text(deltaTime, 60, 106);
|
|
210
259
|
}
|
|
211
260
|
* @example
|
|
212
261
|
let x = 0;
|
|
213
|
-
|
|
262
|
+
function draw() {
|
|
214
263
|
background(200);
|
|
215
264
|
// simulate frame rate drops
|
|
216
265
|
frameRate(random(30, 60));
|
|
@@ -238,7 +287,7 @@ Q5.draw = function () {
|
|
|
238
287
|
*
|
|
239
288
|
* @param {boolean} [val] Whether load* functions should return promises or not. If this parameter is undefined the value is set to true.
|
|
240
289
|
* @example
|
|
241
|
-
|
|
290
|
+
createCanvas(200);
|
|
242
291
|
|
|
243
292
|
usePromiseLoading();
|
|
244
293
|
|
|
@@ -316,8 +365,20 @@ q.circle(100, 50, 20);
|
|
|
316
365
|
static modules: {};
|
|
317
366
|
|
|
318
367
|
static Image: {
|
|
319
|
-
new(w: number, h: number, opt?: any): Q5.Image;
|
|
320
|
-
}
|
|
368
|
+
new (w: number, h: number, opt?: any): Q5.Image;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
/** ⭐️
|
|
372
|
+
* Creates a new Q5 instance that uses [q5's WebGPU renderer](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer).
|
|
373
|
+
* @example
|
|
374
|
+
let q = await Q5.WebGPU('instance');
|
|
375
|
+
|
|
376
|
+
q.draw = () => {
|
|
377
|
+
q.background(0.8);
|
|
378
|
+
q.circle(q.mouseX, 0, 80);
|
|
379
|
+
}
|
|
380
|
+
*/
|
|
381
|
+
static WebGPU(): Q5;
|
|
321
382
|
|
|
322
383
|
/** ⭐️
|
|
323
384
|
* ___Experimental! Might be changed.___
|
|
@@ -338,7 +399,7 @@ Q5.registerAddon((Q5, proto, lifecycles) => {
|
|
|
338
399
|
});
|
|
339
400
|
|
|
340
401
|
// sketch.js
|
|
341
|
-
|
|
402
|
+
createCanvas(200);
|
|
342
403
|
*/
|
|
343
404
|
static registerAddon(addon: Function): void; //-
|
|
344
405
|
|
|
@@ -355,14 +416,14 @@ await createCanvas(200);
|
|
|
355
416
|
/** ⭐️
|
|
356
417
|
* Load assets in the preload function to ensure that they'll be
|
|
357
418
|
* ready to use in the setup and draw functions.
|
|
358
|
-
*
|
|
419
|
+
*
|
|
359
420
|
* q5's preload system can also be used without a preload function
|
|
360
421
|
* if you create a canvas first.
|
|
361
422
|
*/
|
|
362
423
|
preload(): void; //-
|
|
363
424
|
|
|
364
425
|
/** ⭐️
|
|
365
|
-
* The number of frames that have been displayed since the program
|
|
426
|
+
* The number of frames that have been displayed since the program
|
|
366
427
|
* started.
|
|
367
428
|
*/
|
|
368
429
|
postProcess(): void; //-
|
|
@@ -385,26 +446,21 @@ await createCanvas(200);
|
|
|
385
446
|
* by the user, a 200x200 canvas will be created automatically before
|
|
386
447
|
* the draw loop starts.
|
|
387
448
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* Note! The origin (0, 0) point on a WebGPU canvas is at its center!
|
|
449
|
+
* When using q5 WebGPU, create a canvas before using any other
|
|
450
|
+
* q5 functions. The origin of a WebGPU canvas is at its center.
|
|
392
451
|
* @param {number} [w] width or size of the canvas
|
|
393
452
|
* @param {number} [h] height of the canvas
|
|
394
453
|
* @param {object} [opt] options for the canvas
|
|
395
454
|
* @param {boolean} [opt.alpha] whether the canvas should have an alpha channel that allows it to be seen through, default is false
|
|
396
455
|
* @param {string} [opt.colorSpace] color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
|
|
397
|
-
* @returns {
|
|
456
|
+
* @returns {HTMLCanvasElement} created canvas element
|
|
398
457
|
* @example
|
|
399
|
-
|
|
458
|
+
createCanvas(200, 100);
|
|
400
459
|
circle(100, 50, 80);
|
|
401
460
|
* @example
|
|
402
|
-
|
|
403
|
-
circle(0, 0, 80);
|
|
404
|
-
* @example
|
|
405
|
-
await createCanvas(200, 200, { alpha: true });
|
|
461
|
+
createCanvas(200, 200, { alpha: true });
|
|
406
462
|
|
|
407
|
-
|
|
463
|
+
function draw() {
|
|
408
464
|
clear();
|
|
409
465
|
circle(frameCount % 200, 100, 80);
|
|
410
466
|
}
|
|
@@ -413,10 +469,10 @@ Q5.draw = function () {
|
|
|
413
469
|
|
|
414
470
|
/** ⬜️
|
|
415
471
|
* The canvas element associated with the Q5 instance.
|
|
416
|
-
*
|
|
417
|
-
* @prop {number} w
|
|
472
|
+
*
|
|
473
|
+
* @prop {number} w
|
|
418
474
|
* @prop {number} width
|
|
419
|
-
* @prop {number} h
|
|
475
|
+
* @prop {number} h
|
|
420
476
|
* @prop {number} height
|
|
421
477
|
* @prop {number} hw half the width
|
|
422
478
|
* @prop {number} hh half the height
|
|
@@ -439,7 +495,7 @@ Q5.draw = function () {
|
|
|
439
495
|
* a `Color` object, grayscale value, or color component values.
|
|
440
496
|
* @param {Color} color fill color
|
|
441
497
|
* @example
|
|
442
|
-
|
|
498
|
+
createCanvas(200);
|
|
443
499
|
background(200);
|
|
444
500
|
|
|
445
501
|
fill('red');
|
|
@@ -458,7 +514,7 @@ square(80, 80, 80);
|
|
|
458
514
|
* a `Color` object, grayscale value, or color component values.
|
|
459
515
|
* @param {Color} color stroke color
|
|
460
516
|
* @example
|
|
461
|
-
|
|
517
|
+
createCanvas(200);
|
|
462
518
|
background(200);
|
|
463
519
|
fill(36);
|
|
464
520
|
|
|
@@ -473,7 +529,7 @@ square(80, 80, 80);
|
|
|
473
529
|
/** ⬜️
|
|
474
530
|
* After calling this function, shapes will not be filled.
|
|
475
531
|
* @example
|
|
476
|
-
|
|
532
|
+
createCanvas(200);
|
|
477
533
|
background(200);
|
|
478
534
|
|
|
479
535
|
noFill();
|
|
@@ -488,7 +544,7 @@ square(80, 80, 80);
|
|
|
488
544
|
/** ⬜️
|
|
489
545
|
* After calling this function, shapes will not have a stroke (outline).
|
|
490
546
|
* @example
|
|
491
|
-
|
|
547
|
+
createCanvas(200);
|
|
492
548
|
background(200);
|
|
493
549
|
fill(36);
|
|
494
550
|
stroke('red');
|
|
@@ -503,7 +559,7 @@ square(80, 80, 80);
|
|
|
503
559
|
* Sets the size of the stroke used for lines and the border around shapes.
|
|
504
560
|
* @param {number} weight size of the stroke in pixels
|
|
505
561
|
* @example
|
|
506
|
-
|
|
562
|
+
createCanvas(200);
|
|
507
563
|
background(200);
|
|
508
564
|
stroke('red');
|
|
509
565
|
circle(50, 100, 80);
|
|
@@ -519,7 +575,7 @@ circle(150, 100, 80);
|
|
|
519
575
|
* In q5 WebGPU this function only affects images.
|
|
520
576
|
* @param {number} alpha opacity level, ranging from 0 to 1
|
|
521
577
|
* @example
|
|
522
|
-
|
|
578
|
+
createCanvas(200);
|
|
523
579
|
background(200);
|
|
524
580
|
|
|
525
581
|
opacity(1);
|
|
@@ -543,19 +599,21 @@ square(80, 80, 80);
|
|
|
543
599
|
* Not available in q5 WebGPU.
|
|
544
600
|
* @param {Color} color shadow color
|
|
545
601
|
* @example
|
|
546
|
-
|
|
602
|
+
createCanvas(200);
|
|
547
603
|
background(200);
|
|
548
604
|
|
|
549
605
|
noFill();
|
|
550
606
|
shadow('black');
|
|
551
607
|
rect(64, 60, 80, 80);
|
|
552
608
|
* @example
|
|
553
|
-
|
|
554
|
-
let logo =
|
|
609
|
+
createCanvas(200);
|
|
610
|
+
let logo = loadImage('/assets/p5play_logo.webp');
|
|
555
611
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
612
|
+
function setup() {
|
|
613
|
+
background(200);
|
|
614
|
+
shadow(0);
|
|
615
|
+
image(logo, 36, 36, 128, 128);
|
|
616
|
+
}
|
|
559
617
|
*/
|
|
560
618
|
function shadow(color: string | Color): void;
|
|
561
619
|
|
|
@@ -564,7 +622,7 @@ image(logo, 36, 36, 128, 128);
|
|
|
564
622
|
*
|
|
565
623
|
* Not available in q5 WebGPU.
|
|
566
624
|
* @example
|
|
567
|
-
|
|
625
|
+
createCanvas(200);
|
|
568
626
|
background(200);
|
|
569
627
|
noStroke();
|
|
570
628
|
shadow('black');
|
|
@@ -586,17 +644,17 @@ rect(104, 104, 80, 80);
|
|
|
586
644
|
* @param {number} offsetY vertical offset of the shadow, defaults to be the same as offsetX
|
|
587
645
|
* @param {number} blur blur radius of the shadow, defaults to 0
|
|
588
646
|
* @example
|
|
589
|
-
|
|
647
|
+
createCanvas(200);
|
|
590
648
|
noStroke();
|
|
591
649
|
shadow(50);
|
|
592
650
|
|
|
593
|
-
|
|
651
|
+
function draw() {
|
|
594
652
|
background(200);
|
|
595
653
|
shadowBox(-20, mouseY, 10);
|
|
596
654
|
circle(100, 100, 80, 80);
|
|
597
655
|
}
|
|
598
656
|
* @example
|
|
599
|
-
|
|
657
|
+
createCanvas(200);
|
|
600
658
|
background(200);
|
|
601
659
|
noStroke();
|
|
602
660
|
|
|
@@ -633,7 +691,7 @@ text('q5', 60, 115);
|
|
|
633
691
|
* @param {number} x translation along the x-axis
|
|
634
692
|
* @param {number} y translation along the y-axis
|
|
635
693
|
* @example
|
|
636
|
-
|
|
694
|
+
function draw() {
|
|
637
695
|
background(200);
|
|
638
696
|
|
|
639
697
|
translate(100, 100);
|
|
@@ -646,7 +704,7 @@ Q5.draw = function () {
|
|
|
646
704
|
* Rotates the drawing context.
|
|
647
705
|
* @param {number} angle rotation angle in radians
|
|
648
706
|
* @example
|
|
649
|
-
|
|
707
|
+
function draw() {
|
|
650
708
|
background(200);
|
|
651
709
|
|
|
652
710
|
translate(100, 100);
|
|
@@ -666,7 +724,7 @@ Q5.draw = function () {
|
|
|
666
724
|
* @param {number} x scaling factor along the x-axis
|
|
667
725
|
* @param {number} [y] scaling factor along the y-axis
|
|
668
726
|
* @example
|
|
669
|
-
|
|
727
|
+
function draw() {
|
|
670
728
|
background(200);
|
|
671
729
|
|
|
672
730
|
scale(4);
|
|
@@ -679,7 +737,7 @@ Q5.draw = function () {
|
|
|
679
737
|
* Shears the drawing context along the x-axis.
|
|
680
738
|
* @param {number} angle shear angle in radians
|
|
681
739
|
* @example
|
|
682
|
-
|
|
740
|
+
function draw() {
|
|
683
741
|
background(200);
|
|
684
742
|
|
|
685
743
|
translate(25, 60);
|
|
@@ -693,7 +751,7 @@ Q5.draw = function () {
|
|
|
693
751
|
* Shears the drawing context along the y-axis.
|
|
694
752
|
* @param {number} angle shear angle in radians
|
|
695
753
|
* @example
|
|
696
|
-
|
|
754
|
+
function draw() {
|
|
697
755
|
background(200);
|
|
698
756
|
|
|
699
757
|
translate(25, 60);
|
|
@@ -718,7 +776,7 @@ Q5.draw = function () {
|
|
|
718
776
|
* @param {number} e horizontal moving
|
|
719
777
|
* @param {number} f vertical moving
|
|
720
778
|
* @example
|
|
721
|
-
|
|
779
|
+
function draw() {
|
|
722
780
|
background(200);
|
|
723
781
|
|
|
724
782
|
applyMatrix(2, 1, 1, 1, 100, 100);
|
|
@@ -733,7 +791,7 @@ Q5.draw = function () {
|
|
|
733
791
|
* q5 runs this function before every time the `draw` function is run,
|
|
734
792
|
* so that transformations don't carry over to the next frame.
|
|
735
793
|
* @example
|
|
736
|
-
|
|
794
|
+
createCanvas(200);
|
|
737
795
|
background(200);
|
|
738
796
|
|
|
739
797
|
translate(100, 100);
|
|
@@ -747,7 +805,7 @@ square(0, 0, 50);
|
|
|
747
805
|
/** ⬜️
|
|
748
806
|
* Saves the current transformation matrix.
|
|
749
807
|
* @example
|
|
750
|
-
|
|
808
|
+
createCanvas(200);
|
|
751
809
|
background(200);
|
|
752
810
|
translate(100, 100);
|
|
753
811
|
pushMatrix();
|
|
@@ -761,7 +819,7 @@ ellipse(0, 0, 120, 40);
|
|
|
761
819
|
/** ⬜️
|
|
762
820
|
* Restores the previously saved transformation matrix.
|
|
763
821
|
* @example
|
|
764
|
-
|
|
822
|
+
createCanvas(200);
|
|
765
823
|
background(200);
|
|
766
824
|
translate(100, 100);
|
|
767
825
|
pushMatrix();
|
|
@@ -779,7 +837,7 @@ ellipse(0, 0, 120, 40);
|
|
|
779
837
|
* rect mode, ellipse mode, text size, text align, text baseline, and
|
|
780
838
|
* shadow settings.
|
|
781
839
|
* @example
|
|
782
|
-
|
|
840
|
+
function draw() {
|
|
783
841
|
background(200);
|
|
784
842
|
|
|
785
843
|
pushStyles();
|
|
@@ -799,7 +857,7 @@ Q5.draw = function () {
|
|
|
799
857
|
/** ⬜️
|
|
800
858
|
* Saves the current drawing style settings and transformations.
|
|
801
859
|
* @example
|
|
802
|
-
|
|
860
|
+
createCanvas(200);
|
|
803
861
|
|
|
804
862
|
push();
|
|
805
863
|
fill('blue');
|
|
@@ -838,7 +896,7 @@ square(0, 0, 50);
|
|
|
838
896
|
|
|
839
897
|
/** ⬜️
|
|
840
898
|
* Creates a graphics buffer.
|
|
841
|
-
*
|
|
899
|
+
*
|
|
842
900
|
* Disabled by default in q5 WebGPU.
|
|
843
901
|
* See issue [#104](https://github.com/q5js/q5.js/issues/104) for details.
|
|
844
902
|
* @param {number} w width
|
|
@@ -889,7 +947,7 @@ square(0, 0, 50);
|
|
|
889
947
|
* @param {number} [c3] fourth color component (alpha)
|
|
890
948
|
* @returns {Color} a new `Color` object
|
|
891
949
|
* @example
|
|
892
|
-
|
|
950
|
+
createCanvas(200);
|
|
893
951
|
rect(0, 0, 100, 200);
|
|
894
952
|
|
|
895
953
|
// ( r, g, b, a)
|
|
@@ -899,25 +957,25 @@ stroke(bottle);
|
|
|
899
957
|
strokeWeight(30);
|
|
900
958
|
circle(100, 100, 155);
|
|
901
959
|
* @example
|
|
902
|
-
|
|
960
|
+
createCanvas(200);
|
|
903
961
|
// (gray, alpha)
|
|
904
962
|
let c = color(200, 50);
|
|
905
963
|
|
|
906
|
-
|
|
964
|
+
function draw() {
|
|
907
965
|
background(c);
|
|
908
966
|
circle(mouseX, mouseY, 50);
|
|
909
967
|
c.g = (c.g + 1) % 256;
|
|
910
968
|
}
|
|
911
969
|
* @example
|
|
912
|
-
|
|
970
|
+
createCanvas(200);
|
|
913
971
|
|
|
914
|
-
// (r,
|
|
915
|
-
let c = color(0,
|
|
972
|
+
// (r, g, b, a)
|
|
973
|
+
let c = color(0, 255, 255, 50);
|
|
916
974
|
|
|
917
|
-
|
|
975
|
+
function draw() {
|
|
918
976
|
fill(c);
|
|
919
977
|
circle(mouseX, mouseY, 50);
|
|
920
|
-
}
|
|
978
|
+
}
|
|
921
979
|
*/
|
|
922
980
|
function color(c0: string | number | Color | number[], c1?: number, c2?: number, c3?: number): Color;
|
|
923
981
|
|
|
@@ -935,7 +993,7 @@ Q5.draw = function () {
|
|
|
935
993
|
* @param {1 | 255} format color format (1 for float, 255 for integer)
|
|
936
994
|
* @param {'srgb' | 'display-p3'} [gamut] color gamut
|
|
937
995
|
* @example
|
|
938
|
-
|
|
996
|
+
createCanvas(200);
|
|
939
997
|
|
|
940
998
|
colorMode(RGB, 1);
|
|
941
999
|
fill(1, 0, 0);
|
|
@@ -945,7 +1003,7 @@ rect(66, 0, 67, 200);
|
|
|
945
1003
|
fill(0, 0, 1);
|
|
946
1004
|
rect(133, 0, 67, 200);
|
|
947
1005
|
* @example
|
|
948
|
-
|
|
1006
|
+
createCanvas(200);
|
|
949
1007
|
|
|
950
1008
|
colorMode(OKLCH);
|
|
951
1009
|
|
|
@@ -965,7 +1023,7 @@ rect(100, 0, 100, 200);
|
|
|
965
1023
|
* rgb colors are mapped to the full P3 gamut, even when they use the
|
|
966
1024
|
* legacy integer 0-255 format.
|
|
967
1025
|
* @example
|
|
968
|
-
|
|
1026
|
+
createCanvas(200, 100);
|
|
969
1027
|
|
|
970
1028
|
colorMode(RGB);
|
|
971
1029
|
|
|
@@ -997,16 +1055,16 @@ background(255, 0, 0);
|
|
|
997
1055
|
* - `hue`: 0 to 360
|
|
998
1056
|
* - `alpha`: 0 to 1
|
|
999
1057
|
* @example
|
|
1000
|
-
|
|
1058
|
+
createCanvas(200, 100);
|
|
1001
1059
|
|
|
1002
1060
|
colorMode(OKLCH);
|
|
1003
1061
|
|
|
1004
1062
|
background(0.64, 0.3, 30);
|
|
1005
1063
|
* @example
|
|
1006
|
-
|
|
1064
|
+
createCanvas(200);
|
|
1007
1065
|
colorMode(OKLCH);
|
|
1008
1066
|
|
|
1009
|
-
|
|
1067
|
+
function draw() {
|
|
1010
1068
|
background(0.7, 0.16, frameCount % 360);
|
|
1011
1069
|
}
|
|
1012
1070
|
*/
|
|
@@ -1032,13 +1090,13 @@ Q5.draw = function () {
|
|
|
1032
1090
|
* - `lightness`: 0 to 100
|
|
1033
1091
|
* - `alpha`: 0 to 1
|
|
1034
1092
|
* @example
|
|
1035
|
-
|
|
1093
|
+
createCanvas(200, 100);
|
|
1036
1094
|
|
|
1037
1095
|
colorMode(HSL);
|
|
1038
1096
|
|
|
1039
1097
|
background(0, 100, 50);
|
|
1040
1098
|
* @example
|
|
1041
|
-
|
|
1099
|
+
createCanvas(200, 220);
|
|
1042
1100
|
noStroke();
|
|
1043
1101
|
|
|
1044
1102
|
colorMode(HSL);
|
|
@@ -1065,13 +1123,13 @@ for (let h = 0; h < 360; h += 10) {
|
|
|
1065
1123
|
* - `brightness`: 0 to 100
|
|
1066
1124
|
* - `alpha`: 0 to 1
|
|
1067
1125
|
* @example
|
|
1068
|
-
|
|
1126
|
+
createCanvas(200, 100);
|
|
1069
1127
|
|
|
1070
1128
|
colorMode(HSB);
|
|
1071
1129
|
|
|
1072
1130
|
background(0, 100, 100);
|
|
1073
1131
|
* @example
|
|
1074
|
-
|
|
1132
|
+
createCanvas(200, 220);
|
|
1075
1133
|
noStroke();
|
|
1076
1134
|
|
|
1077
1135
|
colorMode(HSB);
|
|
@@ -1091,7 +1149,7 @@ for (let h = 0; h < 360; h += 10) {
|
|
|
1091
1149
|
* less saturated and darker in this example, as it would on
|
|
1092
1150
|
* an SDR display.
|
|
1093
1151
|
* @example
|
|
1094
|
-
|
|
1152
|
+
createCanvas(200, 100);
|
|
1095
1153
|
|
|
1096
1154
|
colorMode(RGB, 255, SRGB);
|
|
1097
1155
|
|
|
@@ -1107,7 +1165,7 @@ background(255, 0, 0);
|
|
|
1107
1165
|
* If your display is HDR capable, note that full red appears
|
|
1108
1166
|
* fully saturated and bright in the following example.
|
|
1109
1167
|
* @example
|
|
1110
|
-
|
|
1168
|
+
createCanvas(200, 100);
|
|
1111
1169
|
|
|
1112
1170
|
colorMode(RGB, 255, DISPLAY_P3);
|
|
1113
1171
|
|
|
@@ -1117,12 +1175,12 @@ background(255, 0, 0);
|
|
|
1117
1175
|
|
|
1118
1176
|
class Color {
|
|
1119
1177
|
/** 🎨
|
|
1120
|
-
* This constructor strictly accepts 4 numbers, which are the color
|
|
1178
|
+
* This constructor strictly accepts 4 numbers, which are the color
|
|
1121
1179
|
* components.
|
|
1122
|
-
*
|
|
1180
|
+
*
|
|
1123
1181
|
* Use the `color` function for greater flexibility, it runs
|
|
1124
1182
|
* this constructor internally.
|
|
1125
|
-
*
|
|
1183
|
+
*
|
|
1126
1184
|
* `Color` is not actually a class itself, it's a reference to a
|
|
1127
1185
|
* Q5 color class based on the color mode, format, and gamut.
|
|
1128
1186
|
*/
|
|
@@ -1163,7 +1221,7 @@ background(255, 0, 0);
|
|
|
1163
1221
|
* - PIXELATED: pixels rendered as sharp squares
|
|
1164
1222
|
* @param {number} scale can also be given as a string (for example "x2")
|
|
1165
1223
|
* @example
|
|
1166
|
-
|
|
1224
|
+
createCanvas(50, 25);
|
|
1167
1225
|
|
|
1168
1226
|
displayMode(CENTER, PIXELATED, 4);
|
|
1169
1227
|
|
|
@@ -1179,7 +1237,7 @@ circle(25, 12.5, 16);
|
|
|
1179
1237
|
|
|
1180
1238
|
/** 💻
|
|
1181
1239
|
* A `displayMode` setting.
|
|
1182
|
-
*
|
|
1240
|
+
*
|
|
1183
1241
|
* The canvas will be scaled to fill the parent element,
|
|
1184
1242
|
* with letterboxing if necessary to preserve its aspect ratio.
|
|
1185
1243
|
*/
|
|
@@ -1187,14 +1245,14 @@ circle(25, 12.5, 16);
|
|
|
1187
1245
|
|
|
1188
1246
|
/** 💻
|
|
1189
1247
|
* A `displayMode` render quality.
|
|
1190
|
-
*
|
|
1248
|
+
*
|
|
1191
1249
|
* Smooth upscaling is used if the canvas is scaled.
|
|
1192
1250
|
*/
|
|
1193
1251
|
const SMOOTH: 'smooth';
|
|
1194
1252
|
|
|
1195
1253
|
/** 💻
|
|
1196
1254
|
* A `displayMode` render quality.
|
|
1197
|
-
*
|
|
1255
|
+
*
|
|
1198
1256
|
* Pixels are rendered as sharp squares if the canvas is scaled.
|
|
1199
1257
|
*/
|
|
1200
1258
|
const PIXELATED: 'pixelated';
|
|
@@ -1209,15 +1267,13 @@ circle(25, 12.5, 16);
|
|
|
1209
1267
|
* CSS color string, grayscale value, and color component values.
|
|
1210
1268
|
* @param {Color | Q5.Image} filler a color or image to draw
|
|
1211
1269
|
* @example
|
|
1212
|
-
|
|
1270
|
+
createCanvas(200, 100);
|
|
1213
1271
|
background('crimson');
|
|
1214
1272
|
* @example
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
Q5.draw = function () {
|
|
1218
|
-
background(0.5, 0.4);
|
|
1273
|
+
function draw() {
|
|
1274
|
+
background(128, 110);
|
|
1219
1275
|
circle(mouseX, mouseY, 20);
|
|
1220
|
-
}
|
|
1276
|
+
}
|
|
1221
1277
|
*/
|
|
1222
1278
|
function background(filler: Color | Q5.Image): void;
|
|
1223
1279
|
|
|
@@ -1232,7 +1288,7 @@ Q5.draw = function () {
|
|
|
1232
1288
|
* @param {number} [br] bottom-right radius
|
|
1233
1289
|
* @param {number} [bl] bottom-left radius
|
|
1234
1290
|
* @example
|
|
1235
|
-
|
|
1291
|
+
createCanvas(200);
|
|
1236
1292
|
background(200);
|
|
1237
1293
|
|
|
1238
1294
|
rect(30, 20, 40, 60);
|
|
@@ -1251,7 +1307,7 @@ rect(130, 120, 40, 60, 30, 2, 8, 20);
|
|
|
1251
1307
|
* @param {number} [br] bottom-right radius
|
|
1252
1308
|
* @param {number} [bl] bottom-left radius
|
|
1253
1309
|
* @example
|
|
1254
|
-
|
|
1310
|
+
createCanvas(200);
|
|
1255
1311
|
background(200);
|
|
1256
1312
|
|
|
1257
1313
|
square(30, 30, 40);
|
|
@@ -1266,7 +1322,7 @@ square(130, 130, 40, 30, 2, 8, 20);
|
|
|
1266
1322
|
* @param {number} y y-coordinate
|
|
1267
1323
|
* @param {number} diameter diameter of the circle
|
|
1268
1324
|
* @example
|
|
1269
|
-
|
|
1325
|
+
createCanvas(200, 100);
|
|
1270
1326
|
circle(100, 50, 80);
|
|
1271
1327
|
*/
|
|
1272
1328
|
function circle(x: number, y: number, diameter: number): void;
|
|
@@ -1278,7 +1334,7 @@ circle(100, 50, 80);
|
|
|
1278
1334
|
* @param {number} width width of the ellipse
|
|
1279
1335
|
* @param {number} [height] height of the ellipse
|
|
1280
1336
|
* @example
|
|
1281
|
-
|
|
1337
|
+
createCanvas(200, 100);
|
|
1282
1338
|
ellipse(100, 50, 160, 80);
|
|
1283
1339
|
*/
|
|
1284
1340
|
function ellipse(x: number, y: number, width: number, height?: number): void;
|
|
@@ -1297,7 +1353,7 @@ ellipse(100, 50, 160, 80);
|
|
|
1297
1353
|
* @param {number} stop angle to stop the arc
|
|
1298
1354
|
* @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`
|
|
1299
1355
|
* @example
|
|
1300
|
-
|
|
1356
|
+
createCanvas(200);
|
|
1301
1357
|
background(200);
|
|
1302
1358
|
|
|
1303
1359
|
arc(40, 40, 40, 40, 0.8, -0.8);
|
|
@@ -1314,7 +1370,7 @@ arc(160, 160, 40, 40, 0.8, -0.8, CHORD);
|
|
|
1314
1370
|
* @param {number} x2 x-coordinate of the second point
|
|
1315
1371
|
* @param {number} y2 y-coordinate of the second point
|
|
1316
1372
|
* @example
|
|
1317
|
-
|
|
1373
|
+
createCanvas(200, 100);
|
|
1318
1374
|
stroke('lime');
|
|
1319
1375
|
line(20, 20, 180, 80);
|
|
1320
1376
|
*/
|
|
@@ -1328,17 +1384,15 @@ line(20, 20, 180, 80);
|
|
|
1328
1384
|
* @param {number} y2 y-coordinate of the second point
|
|
1329
1385
|
* @param {number} r radius of the capsule semi-circle ends
|
|
1330
1386
|
* @example
|
|
1331
|
-
|
|
1387
|
+
createCanvas(200, 100);
|
|
1332
1388
|
background(200);
|
|
1333
1389
|
strokeWeight(5);
|
|
1334
1390
|
capsule(40, 40, 160, 60, 10);
|
|
1335
1391
|
* @example
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
Q5.draw = function () {
|
|
1339
|
-
background(0.8);
|
|
1392
|
+
function draw() {
|
|
1393
|
+
background(200);
|
|
1340
1394
|
strokeWeight(10);
|
|
1341
|
-
capsule(
|
|
1395
|
+
capsule(100, 100, mouseX, mouseY, 20);
|
|
1342
1396
|
}
|
|
1343
1397
|
*/
|
|
1344
1398
|
function capsule(x1: number, y1: number, x2: number, y2: number, r: number): void;
|
|
@@ -1348,7 +1402,7 @@ Q5.draw = function () {
|
|
|
1348
1402
|
* @param {number} x x-coordinate
|
|
1349
1403
|
* @param {number} y y-coordinate
|
|
1350
1404
|
* @example
|
|
1351
|
-
|
|
1405
|
+
createCanvas(200, 100);
|
|
1352
1406
|
stroke('white');
|
|
1353
1407
|
point(75, 50);
|
|
1354
1408
|
|
|
@@ -1359,7 +1413,7 @@ point(125, 50);
|
|
|
1359
1413
|
|
|
1360
1414
|
/** 🧑🎨
|
|
1361
1415
|
* Set the global composite operation for the canvas context.
|
|
1362
|
-
*
|
|
1416
|
+
*
|
|
1363
1417
|
* Not available in q5 WebGPU.
|
|
1364
1418
|
* @param {string} val composite operation
|
|
1365
1419
|
*/
|
|
@@ -1371,7 +1425,7 @@ point(125, 50);
|
|
|
1371
1425
|
* Not available in q5 WebGPU.
|
|
1372
1426
|
* @param {CanvasLineCap} val line cap style
|
|
1373
1427
|
* @example
|
|
1374
|
-
|
|
1428
|
+
createCanvas(200);
|
|
1375
1429
|
background(200);
|
|
1376
1430
|
strokeWeight(20);
|
|
1377
1431
|
|
|
@@ -1392,7 +1446,7 @@ line(50, 150, 150, 150);
|
|
|
1392
1446
|
* Not available in q5 WebGPU.
|
|
1393
1447
|
* @param {CanvasLineJoin} val line join style
|
|
1394
1448
|
* @example
|
|
1395
|
-
|
|
1449
|
+
createCanvas(200);
|
|
1396
1450
|
background(200);
|
|
1397
1451
|
strokeWeight(10);
|
|
1398
1452
|
|
|
@@ -1414,28 +1468,28 @@ triangle(50, 130, 150, 180, 50, 180);
|
|
|
1414
1468
|
* `rect` and `square` are interpreted.
|
|
1415
1469
|
* @param {string} mode
|
|
1416
1470
|
* @example
|
|
1417
|
-
|
|
1471
|
+
createCanvas(200, 100);
|
|
1418
1472
|
background(200);
|
|
1419
1473
|
rectMode(CORNER);
|
|
1420
1474
|
|
|
1421
1475
|
// ( x, y, w, h)
|
|
1422
1476
|
rect(50, 25, 100, 50);
|
|
1423
1477
|
* @example
|
|
1424
|
-
|
|
1478
|
+
createCanvas(200, 100);
|
|
1425
1479
|
background(200);
|
|
1426
1480
|
rectMode(CENTER);
|
|
1427
1481
|
|
|
1428
1482
|
// ( cX, cY, w, h)
|
|
1429
1483
|
rect(100, 50, 100, 50);
|
|
1430
1484
|
* @example
|
|
1431
|
-
|
|
1485
|
+
createCanvas(200, 100);
|
|
1432
1486
|
background(200);
|
|
1433
1487
|
rectMode(RADIUS);
|
|
1434
1488
|
|
|
1435
1489
|
// ( cX, cY, rX, rY)
|
|
1436
1490
|
rect(100, 50, 50, 25);
|
|
1437
1491
|
* @example
|
|
1438
|
-
|
|
1492
|
+
createCanvas(200, 100);
|
|
1439
1493
|
background(200);
|
|
1440
1494
|
rectMode(CORNERS);
|
|
1441
1495
|
|
|
@@ -1444,35 +1498,35 @@ rect(50, 25, 150, 75);
|
|
|
1444
1498
|
*/
|
|
1445
1499
|
function rectMode(mode: string): void;
|
|
1446
1500
|
|
|
1447
|
-
|
|
1501
|
+
/** 🧑🎨
|
|
1448
1502
|
* Set to `CENTER` (default), `RADIUS`, `CORNER`, or `CORNERS`.
|
|
1449
1503
|
*
|
|
1450
1504
|
* Changes how the first four inputs to
|
|
1451
1505
|
* `ellipse`, `circle`, and `arc` are interpreted.
|
|
1452
1506
|
* @param {string} mode
|
|
1453
1507
|
* @example
|
|
1454
|
-
|
|
1508
|
+
createCanvas(200, 100);
|
|
1455
1509
|
background(200);
|
|
1456
1510
|
ellipseMode(CENTER);
|
|
1457
1511
|
|
|
1458
1512
|
// ( x, y, w, h)
|
|
1459
1513
|
ellipse(100, 50, 100, 50);
|
|
1460
1514
|
* @example
|
|
1461
|
-
|
|
1515
|
+
createCanvas(200, 100);
|
|
1462
1516
|
background(200);
|
|
1463
1517
|
ellipseMode(RADIUS);
|
|
1464
1518
|
|
|
1465
1519
|
// ( x, y, rX, rY)
|
|
1466
1520
|
ellipse(100, 50, 50, 25);
|
|
1467
1521
|
* @example
|
|
1468
|
-
|
|
1522
|
+
createCanvas(200, 100);
|
|
1469
1523
|
background(200);
|
|
1470
1524
|
ellipseMode(CORNER);
|
|
1471
1525
|
|
|
1472
1526
|
// (lX, tY, w, h)
|
|
1473
1527
|
ellipse(50, 25, 100, 50);
|
|
1474
1528
|
* @example
|
|
1475
|
-
|
|
1529
|
+
createCanvas(200, 100);
|
|
1476
1530
|
background(200);
|
|
1477
1531
|
ellipseMode(CORNERS);
|
|
1478
1532
|
|
|
@@ -1481,26 +1535,16 @@ ellipse(50, 25, 150, 75);
|
|
|
1481
1535
|
*/
|
|
1482
1536
|
function ellipseMode(mode: string): void;
|
|
1483
1537
|
|
|
1484
|
-
|
|
1485
1538
|
/** 🧑🎨
|
|
1486
1539
|
* Draws a curve.
|
|
1487
1540
|
*/
|
|
1488
|
-
function curve(
|
|
1541
|
+
function curve(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
1489
1542
|
|
|
1490
1543
|
/** 🧑🎨
|
|
1491
1544
|
* Sets the amount of straight line segments used to make a curve.
|
|
1492
1545
|
*
|
|
1493
1546
|
* Only takes effect in q5 WebGPU.
|
|
1494
1547
|
* @param {number} val curve detail level, default is 20
|
|
1495
|
-
* @example
|
|
1496
|
-
await Q5.WebGPU();
|
|
1497
|
-
|
|
1498
|
-
curveDetail(4);
|
|
1499
|
-
|
|
1500
|
-
strokeWeight(10);
|
|
1501
|
-
stroke(0, 1, 1);
|
|
1502
|
-
noFill();
|
|
1503
|
-
curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
1504
1548
|
*/
|
|
1505
1549
|
function curveDetail(val: number): void;
|
|
1506
1550
|
|
|
@@ -1516,14 +1560,14 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1516
1560
|
|
|
1517
1561
|
/** 🧑🎨
|
|
1518
1562
|
* Starts storing vertices for a contour.
|
|
1519
|
-
*
|
|
1563
|
+
*
|
|
1520
1564
|
* Not available in q5 WebGPU.
|
|
1521
1565
|
*/
|
|
1522
1566
|
function beginContour(): void;
|
|
1523
1567
|
|
|
1524
1568
|
/** 🧑🎨
|
|
1525
1569
|
* Ends storing vertices for a contour.
|
|
1526
|
-
*
|
|
1570
|
+
*
|
|
1527
1571
|
* Not available in q5 WebGPU.
|
|
1528
1572
|
*/
|
|
1529
1573
|
function endContour(): void;
|
|
@@ -1593,9 +1637,9 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1593
1637
|
function quad(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
1594
1638
|
|
|
1595
1639
|
/** 🧑🎨
|
|
1596
|
-
* Sets the canvas to erase mode, where shapes will erase what's
|
|
1640
|
+
* Sets the canvas to erase mode, where shapes will erase what's
|
|
1597
1641
|
* underneath them instead of drawing over it.
|
|
1598
|
-
*
|
|
1642
|
+
*
|
|
1599
1643
|
* Not available in q5 WebGPU.
|
|
1600
1644
|
* @param {number} [fillAlpha] opacity level of the fill color
|
|
1601
1645
|
* @param {number} [strokeAlpha] opacity level of the stroke color
|
|
@@ -1604,14 +1648,14 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1604
1648
|
|
|
1605
1649
|
/** 🧑🎨
|
|
1606
1650
|
* Resets the canvas from erase mode to normal drawing mode.
|
|
1607
|
-
*
|
|
1651
|
+
*
|
|
1608
1652
|
* Not available in q5 WebGPU.
|
|
1609
1653
|
*/
|
|
1610
1654
|
function noErase(): void;
|
|
1611
1655
|
|
|
1612
1656
|
/** 🧑🎨
|
|
1613
1657
|
* Checks if a given point is within the current path's fill area.
|
|
1614
|
-
*
|
|
1658
|
+
*
|
|
1615
1659
|
* Not available in q5 WebGPU.
|
|
1616
1660
|
* @param {number} x x-coordinate of the point
|
|
1617
1661
|
* @param {number} y y-coordinate of the point
|
|
@@ -1621,7 +1665,7 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1621
1665
|
|
|
1622
1666
|
/** 🧑🎨
|
|
1623
1667
|
* Checks if a given point is within the current path's stroke.
|
|
1624
|
-
*
|
|
1668
|
+
*
|
|
1625
1669
|
* Not available in q5 WebGPU.
|
|
1626
1670
|
* @param {number} x x-coordinate of the point
|
|
1627
1671
|
* @param {number} y y-coordinate of the point
|
|
@@ -1651,22 +1695,13 @@ curve(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
|
1651
1695
|
* @param {string} url url of the image to load
|
|
1652
1696
|
* @returns {Q5.Image | Promise<Q5.Image>} image or promise
|
|
1653
1697
|
* @example
|
|
1654
|
-
|
|
1698
|
+
createCanvas(200);
|
|
1655
1699
|
|
|
1656
1700
|
let logo = loadImage('/q5js_logo.avif');
|
|
1657
1701
|
|
|
1658
|
-
|
|
1702
|
+
function draw() {
|
|
1659
1703
|
background(logo);
|
|
1660
1704
|
}
|
|
1661
|
-
* @example
|
|
1662
|
-
await createCanvas(200, GPU);
|
|
1663
|
-
await createCanvas(200);
|
|
1664
|
-
|
|
1665
|
-
let logo = loadImage('/q5js_logo.avif');
|
|
1666
|
-
|
|
1667
|
-
Q5.draw = function () {
|
|
1668
|
-
background(logo);
|
|
1669
|
-
};
|
|
1670
1705
|
*/
|
|
1671
1706
|
function loadImage(url: string): Q5.Image | Promise<Q5.Image>;
|
|
1672
1707
|
|
|
@@ -1682,23 +1717,33 @@ Q5.draw = function () {
|
|
|
1682
1717
|
* @param {number} [sw] width of the subsection of the source image
|
|
1683
1718
|
* @param {number} [sh] height of the subsection of the source image
|
|
1684
1719
|
* @example
|
|
1685
|
-
|
|
1720
|
+
createCanvas(200);
|
|
1686
1721
|
|
|
1687
1722
|
let logo = loadImage('/q5js_logo.avif');
|
|
1688
1723
|
|
|
1689
|
-
|
|
1724
|
+
function draw() {
|
|
1690
1725
|
image(logo, 0, 0, 200, 200);
|
|
1691
1726
|
}
|
|
1692
1727
|
* @example
|
|
1693
|
-
|
|
1728
|
+
createCanvas(200);
|
|
1694
1729
|
|
|
1695
1730
|
let logo = loadImage('/q5js_logo.avif');
|
|
1696
1731
|
|
|
1697
|
-
|
|
1732
|
+
function draw() {
|
|
1698
1733
|
image(logo, 0, 0, 200, 200, 256, 256, 512, 512);
|
|
1699
1734
|
}
|
|
1700
1735
|
*/
|
|
1701
|
-
function image(
|
|
1736
|
+
function image(
|
|
1737
|
+
img: Q5.Image | HTMLVideoElement,
|
|
1738
|
+
dx: number,
|
|
1739
|
+
dy: number,
|
|
1740
|
+
dw?: number,
|
|
1741
|
+
dh?: number,
|
|
1742
|
+
sx?: number,
|
|
1743
|
+
sy?: number,
|
|
1744
|
+
sw?: number,
|
|
1745
|
+
sh?: number
|
|
1746
|
+
): void;
|
|
1702
1747
|
|
|
1703
1748
|
/** 🌆
|
|
1704
1749
|
* Set to `CORNER` (default), `CORNERS`, or `CENTER`.
|
|
@@ -1706,30 +1751,30 @@ Q5.draw = function () {
|
|
|
1706
1751
|
* Changes how inputs to `image` are interpreted.
|
|
1707
1752
|
* @param {string} mode
|
|
1708
1753
|
* @example
|
|
1709
|
-
|
|
1754
|
+
createCanvas(200);
|
|
1710
1755
|
let logo = loadImage('/q5js_logo.avif');
|
|
1711
1756
|
|
|
1712
|
-
|
|
1757
|
+
function draw() {
|
|
1713
1758
|
imageMode(CORNER);
|
|
1714
1759
|
|
|
1715
1760
|
// ( img, x, y, w, h)
|
|
1716
1761
|
image(logo, 50, 50, 100, 100);
|
|
1717
1762
|
}
|
|
1718
1763
|
* @example
|
|
1719
|
-
|
|
1764
|
+
createCanvas(200);
|
|
1720
1765
|
let logo = loadImage('/q5js_logo.avif');
|
|
1721
1766
|
|
|
1722
|
-
|
|
1767
|
+
function draw() {
|
|
1723
1768
|
imageMode(CENTER);
|
|
1724
1769
|
|
|
1725
1770
|
// ( img, cX, cY, w, h)
|
|
1726
1771
|
image(logo, 100, 100, 100, 100);
|
|
1727
1772
|
}
|
|
1728
1773
|
* @example
|
|
1729
|
-
|
|
1774
|
+
createCanvas(200);
|
|
1730
1775
|
let logo = loadImage('/q5js_logo.avif');
|
|
1731
1776
|
|
|
1732
|
-
|
|
1777
|
+
function draw() {
|
|
1733
1778
|
imageMode(CORNERS);
|
|
1734
1779
|
|
|
1735
1780
|
// ( img, x1, y1, x2, y2)
|
|
@@ -1741,11 +1786,11 @@ Q5.draw = function () {
|
|
|
1741
1786
|
/** 🌆
|
|
1742
1787
|
* Sets the default image scale, which is applied to images when
|
|
1743
1788
|
* they are drawn without a specified width or height.
|
|
1744
|
-
*
|
|
1789
|
+
*
|
|
1745
1790
|
* By default it is 0.5 so images appear at their actual size
|
|
1746
1791
|
* when pixel density is 2. Images will be drawn at a consistent
|
|
1747
1792
|
* default size relative to the canvas regardless of pixel density.
|
|
1748
|
-
*
|
|
1793
|
+
*
|
|
1749
1794
|
* This function must be called before images are loaded to
|
|
1750
1795
|
* have an effect.
|
|
1751
1796
|
* @param {number} scale
|
|
@@ -1758,12 +1803,14 @@ Q5.draw = function () {
|
|
|
1758
1803
|
* @param {number} w new width
|
|
1759
1804
|
* @param {number} h new height
|
|
1760
1805
|
* @example
|
|
1761
|
-
|
|
1806
|
+
createCanvas(200);
|
|
1762
1807
|
|
|
1763
|
-
let logo =
|
|
1808
|
+
let logo = loadImage('/q5js_logo.avif');
|
|
1764
1809
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1810
|
+
function setup() {
|
|
1811
|
+
logo.resize(128, 128);
|
|
1812
|
+
image(logo, 0, 0, 200, 200);
|
|
1813
|
+
}
|
|
1767
1814
|
*/
|
|
1768
1815
|
function resize(w: number, h: number): void;
|
|
1769
1816
|
|
|
@@ -1778,21 +1825,27 @@ image(logo, 0, 0, 200, 200);
|
|
|
1778
1825
|
* their actual size. This is the default setting, so running this
|
|
1779
1826
|
* function only has an effect if `noSmooth` has been called.
|
|
1780
1827
|
* @example
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1828
|
+
createCanvas(200);
|
|
1829
|
+
|
|
1830
|
+
let icon = loadImage('/q5js_icon.png');
|
|
1831
|
+
|
|
1832
|
+
function setup() {
|
|
1833
|
+
image(icon, 0, 0, 200, 200);
|
|
1834
|
+
}
|
|
1784
1835
|
*/
|
|
1785
1836
|
function smooth(): void;
|
|
1786
1837
|
|
|
1787
1838
|
/** 🌆
|
|
1788
1839
|
* Disables smooth image rendering for a pixelated look.
|
|
1789
1840
|
* @example
|
|
1790
|
-
|
|
1841
|
+
createCanvas(200);
|
|
1791
1842
|
|
|
1792
|
-
let icon =
|
|
1843
|
+
let icon = loadImage('/q5js_icon.png');
|
|
1793
1844
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1845
|
+
function setup() {
|
|
1846
|
+
noSmooth();
|
|
1847
|
+
image(icon, 0, 0, 200, 200);
|
|
1848
|
+
}
|
|
1796
1849
|
*/
|
|
1797
1850
|
function noSmooth(): void;
|
|
1798
1851
|
|
|
@@ -1816,12 +1869,14 @@ image(icon, 0, 0, 200, 200);
|
|
|
1816
1869
|
* each copy separately.
|
|
1817
1870
|
* @param {string | number} color tint color
|
|
1818
1871
|
* @example
|
|
1819
|
-
|
|
1872
|
+
createCanvas(200);
|
|
1820
1873
|
|
|
1821
|
-
let logo =
|
|
1874
|
+
let logo = loadImage('/q5js_logo.avif');
|
|
1822
1875
|
|
|
1823
|
-
|
|
1824
|
-
|
|
1876
|
+
function setup() {
|
|
1877
|
+
tint(255, 0, 0, 128);
|
|
1878
|
+
image(logo, 0, 0, 200, 200);
|
|
1879
|
+
}
|
|
1825
1880
|
*/
|
|
1826
1881
|
function tint(color: string | number): void;
|
|
1827
1882
|
|
|
@@ -1854,12 +1909,14 @@ image(logo, 0, 0, 200, 200);
|
|
|
1854
1909
|
* @param {number} dw width of the destination region
|
|
1855
1910
|
* @param {number} dh height of the destination region
|
|
1856
1911
|
* @example
|
|
1857
|
-
|
|
1912
|
+
createCanvas(200);
|
|
1858
1913
|
|
|
1859
|
-
let logo =
|
|
1914
|
+
let logo = loadImage('/q5js_logo.avif');
|
|
1860
1915
|
|
|
1861
|
-
|
|
1862
|
-
|
|
1916
|
+
function setup() {
|
|
1917
|
+
logo.inset(256, 256, 512, 512, 0, 0, 256, 256);
|
|
1918
|
+
image(logo, 0, 0, 200, 200);
|
|
1919
|
+
}
|
|
1863
1920
|
*/
|
|
1864
1921
|
function inset(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
1865
1922
|
|
|
@@ -1879,7 +1936,7 @@ image(logo, 0, 0, 200, 200);
|
|
|
1879
1936
|
* @param {number} [h] height of the area, default is 1
|
|
1880
1937
|
* @returns {Q5.Image | number[]}
|
|
1881
1938
|
* @example
|
|
1882
|
-
|
|
1939
|
+
function draw() {
|
|
1883
1940
|
background(200);
|
|
1884
1941
|
noStroke();
|
|
1885
1942
|
circle(100, 100, frameCount % 200);
|
|
@@ -1889,12 +1946,14 @@ Q5.draw = function () {
|
|
|
1889
1946
|
text(col, mouseX, mouseY);
|
|
1890
1947
|
}
|
|
1891
1948
|
* @example
|
|
1892
|
-
|
|
1949
|
+
createCanvas(200);
|
|
1893
1950
|
|
|
1894
|
-
let logo =
|
|
1951
|
+
let logo = loadImage('/q5js_logo.avif');
|
|
1895
1952
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1953
|
+
function setup() {
|
|
1954
|
+
let cropped = logo.get(256, 256, 512, 512);
|
|
1955
|
+
image(cropped, 0, 0, 200, 200);
|
|
1956
|
+
}
|
|
1898
1957
|
*/
|
|
1899
1958
|
function get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
|
|
1900
1959
|
|
|
@@ -1909,10 +1968,10 @@ image(cropped, 0, 0, 200, 200);
|
|
|
1909
1968
|
* @param {number} y
|
|
1910
1969
|
* @param {any} val color, canvas, or image
|
|
1911
1970
|
* @example
|
|
1912
|
-
|
|
1971
|
+
createCanvas(200);
|
|
1913
1972
|
let c = color('lime');
|
|
1914
1973
|
|
|
1915
|
-
|
|
1974
|
+
function draw() {
|
|
1916
1975
|
set(random(200), random(200), c);
|
|
1917
1976
|
updatePixels();
|
|
1918
1977
|
}
|
|
@@ -1921,14 +1980,14 @@ Q5.draw = function () {
|
|
|
1921
1980
|
|
|
1922
1981
|
/** 🌆
|
|
1923
1982
|
* Array of pixel color data from a canvas or image.
|
|
1924
|
-
*
|
|
1983
|
+
*
|
|
1925
1984
|
* Each pixel is represented by four consecutive values in the array,
|
|
1926
1985
|
* corresponding to its red, green, blue, and alpha channels.
|
|
1927
|
-
*
|
|
1986
|
+
*
|
|
1928
1987
|
* The top left pixel's data is at the beginning of the array
|
|
1929
1988
|
* and the bottom right pixel's data is at the end, going from
|
|
1930
1989
|
* left to right and top to bottom.
|
|
1931
|
-
*
|
|
1990
|
+
*
|
|
1932
1991
|
* Use `loadPixels` to load current pixel data from a canvas or image.
|
|
1933
1992
|
*/
|
|
1934
1993
|
var pixels: number[];
|
|
@@ -1942,7 +2001,7 @@ Q5.draw = function () {
|
|
|
1942
2001
|
frameRate(5);
|
|
1943
2002
|
let icon = loadImage('/q5js_icon.png');
|
|
1944
2003
|
|
|
1945
|
-
|
|
2004
|
+
function draw() {
|
|
1946
2005
|
icon.loadPixels();
|
|
1947
2006
|
for (let i = 0; i < icon.pixels.length; i += 16) {
|
|
1948
2007
|
icon.pixels[i + 1] = random(255);
|
|
@@ -1956,7 +2015,7 @@ Q5.draw = function () {
|
|
|
1956
2015
|
/** 🌆
|
|
1957
2016
|
* Applies changes in the `pixels` array to the canvas or image.
|
|
1958
2017
|
* @example
|
|
1959
|
-
|
|
2018
|
+
createCanvas(200);
|
|
1960
2019
|
|
|
1961
2020
|
for (let x = 0; x < 200; x += 5) {
|
|
1962
2021
|
for (let y = 0; y < 200; y += 5) {
|
|
@@ -1977,10 +2036,13 @@ updatePixels();
|
|
|
1977
2036
|
* @param {string} type filter type or a CSS filter string
|
|
1978
2037
|
* @param {number} [value] optional value, depends on filter type
|
|
1979
2038
|
* @example
|
|
1980
|
-
|
|
1981
|
-
let logo =
|
|
1982
|
-
|
|
1983
|
-
|
|
2039
|
+
createCanvas(200);
|
|
2040
|
+
let logo = loadImage('/q5js_logo.avif');
|
|
2041
|
+
|
|
2042
|
+
function setup() {
|
|
2043
|
+
logo.filter(INVERT);
|
|
2044
|
+
image(logo, 0, 0, 200, 200);
|
|
2045
|
+
}
|
|
1984
2046
|
*/
|
|
1985
2047
|
function filter(type: string, value?: number): void;
|
|
1986
2048
|
|
|
@@ -2044,13 +2106,13 @@ image(logo, 0, 0, 200, 200);
|
|
|
2044
2106
|
* @param {number} [wrapWidth] maximum line width in characters
|
|
2045
2107
|
* @param {number} [lineLimit] maximum number of lines
|
|
2046
2108
|
* @example
|
|
2047
|
-
|
|
2109
|
+
createCanvas(200, 100);
|
|
2048
2110
|
background('silver');
|
|
2049
2111
|
|
|
2050
2112
|
textSize(32);
|
|
2051
2113
|
text('Hello, world!', 12, 60);
|
|
2052
2114
|
* @example
|
|
2053
|
-
|
|
2115
|
+
createCanvas(200);
|
|
2054
2116
|
background(200);
|
|
2055
2117
|
textSize(20);
|
|
2056
2118
|
|
|
@@ -2085,7 +2147,7 @@ text(info, 12, 30, 20, 6);
|
|
|
2085
2147
|
* @param {string} url URL of the font to load
|
|
2086
2148
|
* @returns {FontFace | Promise<FontFace>} font or promise
|
|
2087
2149
|
* @example
|
|
2088
|
-
|
|
2150
|
+
createCanvas(200, 56);
|
|
2089
2151
|
|
|
2090
2152
|
loadFont('/assets/Robotica.ttf');
|
|
2091
2153
|
|
|
@@ -2095,7 +2157,7 @@ function setup() {
|
|
|
2095
2157
|
text('Hello!', 2, 54);
|
|
2096
2158
|
}
|
|
2097
2159
|
* @example
|
|
2098
|
-
|
|
2160
|
+
createCanvas(200, 74);
|
|
2099
2161
|
|
|
2100
2162
|
loadFont(
|
|
2101
2163
|
'fonts.googleapis.com/css2?family=Pacifico'
|
|
@@ -2107,7 +2169,7 @@ function setup() {
|
|
|
2107
2169
|
text('Hello!', 2, 68);
|
|
2108
2170
|
}
|
|
2109
2171
|
*/
|
|
2110
|
-
function loadFont(url: string): FontFace | Promise<FontFace
|
|
2172
|
+
function loadFont(url: string): FontFace | Promise<FontFace>;
|
|
2111
2173
|
|
|
2112
2174
|
/** ✍️
|
|
2113
2175
|
* Sets the current font to be used for rendering text.
|
|
@@ -2116,7 +2178,7 @@ function setup() {
|
|
|
2116
2178
|
* "sans-serif" or the last font loaded.
|
|
2117
2179
|
* @param {string} fontName name of the font family or a FontFace object
|
|
2118
2180
|
* @example
|
|
2119
|
-
|
|
2181
|
+
createCanvas(200, 160);
|
|
2120
2182
|
background(200);
|
|
2121
2183
|
|
|
2122
2184
|
textFont('serif');
|
|
@@ -2124,13 +2186,12 @@ textFont('serif');
|
|
|
2124
2186
|
textSize(32);
|
|
2125
2187
|
text('Hello, world!', 15, 90);
|
|
2126
2188
|
* @example
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
background(0.8);
|
|
2189
|
+
createCanvas(200);
|
|
2190
|
+
background(200);
|
|
2130
2191
|
|
|
2131
2192
|
textFont('monospace');
|
|
2132
2193
|
|
|
2133
|
-
|
|
2194
|
+
function setup() {
|
|
2134
2195
|
text('Hello, world!', -65, 0);
|
|
2135
2196
|
}
|
|
2136
2197
|
*/
|
|
@@ -2141,7 +2202,7 @@ Q5.setup = function () {
|
|
|
2141
2202
|
* @param {number} [size] size of the font in pixels
|
|
2142
2203
|
* @returns {number | void} current font size when no argument is provided
|
|
2143
2204
|
* @example
|
|
2144
|
-
|
|
2205
|
+
function draw() {
|
|
2145
2206
|
background(200);
|
|
2146
2207
|
|
|
2147
2208
|
textSize(abs(mouseX));
|
|
@@ -2155,7 +2216,7 @@ Q5.draw = function () {
|
|
|
2155
2216
|
* @param {number} [leading] line height in pixels
|
|
2156
2217
|
* @returns {number | void} current line height when no argument is provided
|
|
2157
2218
|
* @example
|
|
2158
|
-
|
|
2219
|
+
function draw() {
|
|
2159
2220
|
background(200);
|
|
2160
2221
|
|
|
2161
2222
|
textSize(abs(mouseX));
|
|
@@ -2169,7 +2230,7 @@ Q5.draw = function () {
|
|
|
2169
2230
|
* Sets the current text style.
|
|
2170
2231
|
* @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style font style
|
|
2171
2232
|
* @example
|
|
2172
|
-
|
|
2233
|
+
createCanvas(200);
|
|
2173
2234
|
background(200);
|
|
2174
2235
|
|
|
2175
2236
|
textStyle(ITALIC);
|
|
@@ -2184,7 +2245,7 @@ text('Hello, world!', 12, 106);
|
|
|
2184
2245
|
* @param {'left' | 'center' | 'right'} horiz horizontal alignment
|
|
2185
2246
|
* @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] vertical alignment
|
|
2186
2247
|
* @example
|
|
2187
|
-
|
|
2248
|
+
createCanvas(200);
|
|
2188
2249
|
background(200);
|
|
2189
2250
|
textSize(32);
|
|
2190
2251
|
|
|
@@ -2207,7 +2268,7 @@ text('Hello, world!', 100, 100);
|
|
|
2207
2268
|
* - 900: black/heavy
|
|
2208
2269
|
* @param {number | string} weight font weight
|
|
2209
2270
|
* @example
|
|
2210
|
-
|
|
2271
|
+
createCanvas(200);
|
|
2211
2272
|
background(200);
|
|
2212
2273
|
textSize(32);
|
|
2213
2274
|
textAlign(CENTER, MIDDLE);
|
|
@@ -2222,7 +2283,7 @@ text('Hello, world!', 100, 100);
|
|
|
2222
2283
|
* @param {string} str string to measure
|
|
2223
2284
|
* @returns {number} width of the text in pixels
|
|
2224
2285
|
* @example
|
|
2225
|
-
|
|
2286
|
+
function draw() {
|
|
2226
2287
|
background(200);
|
|
2227
2288
|
|
|
2228
2289
|
textSize(abs(mouseX));
|
|
@@ -2237,7 +2298,7 @@ Q5.draw = function () {
|
|
|
2237
2298
|
* @param {string} str string to measure
|
|
2238
2299
|
* @returns {number} ascent of the text in pixels
|
|
2239
2300
|
* @example
|
|
2240
|
-
|
|
2301
|
+
function draw() {
|
|
2241
2302
|
background(200);
|
|
2242
2303
|
|
|
2243
2304
|
textSize(abs(mouseX));
|
|
@@ -2252,7 +2313,7 @@ Q5.draw = function () {
|
|
|
2252
2313
|
* @param {string} str string to measure
|
|
2253
2314
|
* @returns {number} descent of the text in pixels
|
|
2254
2315
|
* @example
|
|
2255
|
-
|
|
2316
|
+
createCanvas(200);
|
|
2256
2317
|
background(200);
|
|
2257
2318
|
textSize(64);
|
|
2258
2319
|
|
|
@@ -2268,13 +2329,13 @@ await createCanvas(200);
|
|
|
2268
2329
|
* @param {number} [lineLimit] maximum number of lines
|
|
2269
2330
|
* @returns {Q5.Image} an image object representing the rendered text
|
|
2270
2331
|
* @example
|
|
2271
|
-
|
|
2332
|
+
createCanvas(200);
|
|
2272
2333
|
textSize(96);
|
|
2273
2334
|
|
|
2274
2335
|
let img = createTextImage('🐶');
|
|
2275
2336
|
img.filter(INVERT);
|
|
2276
2337
|
|
|
2277
|
-
|
|
2338
|
+
function draw() {
|
|
2278
2339
|
image(img, 55, 10);
|
|
2279
2340
|
}
|
|
2280
2341
|
*/
|
|
@@ -2297,21 +2358,21 @@ Q5.draw = function () {
|
|
|
2297
2358
|
* @param {number} x x-coordinate where the image should be placed
|
|
2298
2359
|
* @param {number} y y-coordinate where the image should be placed
|
|
2299
2360
|
* @example
|
|
2300
|
-
|
|
2301
|
-
background(
|
|
2361
|
+
createCanvas(200);
|
|
2362
|
+
background(200);
|
|
2302
2363
|
textSize(96);
|
|
2303
2364
|
textAlign(CENTER, CENTER);
|
|
2304
2365
|
|
|
2305
|
-
textImage('🐶',
|
|
2366
|
+
textImage('🐶', 100,100);
|
|
2306
2367
|
* @example
|
|
2307
|
-
|
|
2368
|
+
createCanvas(200);
|
|
2308
2369
|
|
|
2309
2370
|
loadFont('/assets/Robotica.ttf');
|
|
2310
2371
|
|
|
2311
|
-
|
|
2312
|
-
background(
|
|
2372
|
+
function setup() {
|
|
2373
|
+
background(200);
|
|
2313
2374
|
textSize(66);
|
|
2314
|
-
textImage('Hello!',
|
|
2375
|
+
textImage('Hello!', 0, 0);
|
|
2315
2376
|
};
|
|
2316
2377
|
*/
|
|
2317
2378
|
function textImage(img: Q5.Image | String, x: number, y: number): void;
|
|
@@ -2325,7 +2386,7 @@ Q5.setup = function () {
|
|
|
2325
2386
|
* @param {number} r number of digits to appear after the decimal point
|
|
2326
2387
|
* @returns {string} a string representation of the number, formatted accordingly
|
|
2327
2388
|
* @example
|
|
2328
|
-
|
|
2389
|
+
createCanvas(200, 100);
|
|
2329
2390
|
background(200);
|
|
2330
2391
|
|
|
2331
2392
|
textSize(32);
|
|
@@ -2387,9 +2448,9 @@ text(nf(PI, 4, 5), 10, 60);
|
|
|
2387
2448
|
|
|
2388
2449
|
/** 🖲️
|
|
2389
2450
|
* Note that input responses inside `draw` can be delayed by
|
|
2390
|
-
* up to one frame cycle: from the exact moment an input event occurs
|
|
2451
|
+
* up to one frame cycle: from the exact moment an input event occurs
|
|
2391
2452
|
* to the next time a frame is drawn.
|
|
2392
|
-
*
|
|
2453
|
+
*
|
|
2393
2454
|
* Play sounds or trigger other non-visual feedback immediately
|
|
2394
2455
|
* by responding to input events inside functions like
|
|
2395
2456
|
* `mousePressed` and `keyPressed`.
|
|
@@ -2398,7 +2459,7 @@ text(nf(PI, 4, 5), 10, 60);
|
|
|
2398
2459
|
/** 🖲️
|
|
2399
2460
|
* Current X position of the mouse.
|
|
2400
2461
|
* @example
|
|
2401
|
-
|
|
2462
|
+
function draw() {
|
|
2402
2463
|
background(200);
|
|
2403
2464
|
textSize(64);
|
|
2404
2465
|
text(round(mouseX), 50, 120);
|
|
@@ -2409,7 +2470,7 @@ Q5.draw = function () {
|
|
|
2409
2470
|
/** 🖲️
|
|
2410
2471
|
* Current Y position of the mouse.
|
|
2411
2472
|
* @example
|
|
2412
|
-
|
|
2473
|
+
function draw() {
|
|
2413
2474
|
background(200);
|
|
2414
2475
|
circle(100, mouseY, 100);
|
|
2415
2476
|
}
|
|
@@ -2431,7 +2492,7 @@ Q5.draw = function () {
|
|
|
2431
2492
|
*
|
|
2432
2493
|
* The default value is an empty string.
|
|
2433
2494
|
* @example
|
|
2434
|
-
|
|
2495
|
+
function draw() {
|
|
2435
2496
|
background(200);
|
|
2436
2497
|
textSize(64);
|
|
2437
2498
|
text(mouseButton, 20, 120);
|
|
@@ -2442,7 +2503,7 @@ Q5.draw = function () {
|
|
|
2442
2503
|
/** 🖲️
|
|
2443
2504
|
* True if the mouse is currently pressed, false otherwise.
|
|
2444
2505
|
* @example
|
|
2445
|
-
|
|
2506
|
+
function draw() {
|
|
2446
2507
|
if (mouseIsPressed) background(100);
|
|
2447
2508
|
else background(200);
|
|
2448
2509
|
}
|
|
@@ -2452,10 +2513,10 @@ Q5.draw = function () {
|
|
|
2452
2513
|
/** 🖲️
|
|
2453
2514
|
* Define this function to respond to mouse down events.
|
|
2454
2515
|
* @example
|
|
2455
|
-
|
|
2516
|
+
createCanvas(200);
|
|
2456
2517
|
let gray = 95;
|
|
2457
2518
|
|
|
2458
|
-
|
|
2519
|
+
function mousePressed() {
|
|
2459
2520
|
background(gray % 256);
|
|
2460
2521
|
gray += 40;
|
|
2461
2522
|
}
|
|
@@ -2465,7 +2526,7 @@ Q5.mousePressed = function () {
|
|
|
2465
2526
|
/** 🖲️
|
|
2466
2527
|
* Define this function to respond to mouse up events.
|
|
2467
2528
|
* @example
|
|
2468
|
-
|
|
2529
|
+
createCanvas(200);
|
|
2469
2530
|
let gray = 95;
|
|
2470
2531
|
|
|
2471
2532
|
function mouseReleased() {
|
|
@@ -2481,7 +2542,7 @@ function mouseReleased() {
|
|
|
2481
2542
|
* On touchscreen devices this function is not called
|
|
2482
2543
|
* when the user drags their finger on the screen.
|
|
2483
2544
|
* @example
|
|
2484
|
-
|
|
2545
|
+
createCanvas(200);
|
|
2485
2546
|
let gray = 95;
|
|
2486
2547
|
|
|
2487
2548
|
function mouseMoved() {
|
|
@@ -2497,7 +2558,7 @@ function mouseMoved() {
|
|
|
2497
2558
|
* Dragging the mouse is defined as moving the mouse
|
|
2498
2559
|
* while a mouse button is pressed.
|
|
2499
2560
|
* @example
|
|
2500
|
-
|
|
2561
|
+
createCanvas(200);
|
|
2501
2562
|
let gray = 95;
|
|
2502
2563
|
|
|
2503
2564
|
function mouseDragged() {
|
|
@@ -2510,7 +2571,7 @@ function mouseDragged() {
|
|
|
2510
2571
|
/** 🖲️
|
|
2511
2572
|
* Define this function to respond to mouse double click events.
|
|
2512
2573
|
* @example
|
|
2513
|
-
|
|
2574
|
+
createCanvas(200);
|
|
2514
2575
|
let gray = 95;
|
|
2515
2576
|
|
|
2516
2577
|
function doubleClicked() {
|
|
@@ -2523,7 +2584,7 @@ function doubleClicked() {
|
|
|
2523
2584
|
/** 🖲️
|
|
2524
2585
|
* The name of the last key pressed.
|
|
2525
2586
|
* @example
|
|
2526
|
-
|
|
2587
|
+
function draw() {
|
|
2527
2588
|
background(200);
|
|
2528
2589
|
textSize(64);
|
|
2529
2590
|
text(key, 20, 120);
|
|
@@ -2534,7 +2595,7 @@ Q5.draw = function () {
|
|
|
2534
2595
|
/** 🖲️
|
|
2535
2596
|
* True if a key is currently pressed, false otherwise.
|
|
2536
2597
|
* @example
|
|
2537
|
-
|
|
2598
|
+
function draw() {
|
|
2538
2599
|
if (keyIsPressed) background(100);
|
|
2539
2600
|
else background(200);
|
|
2540
2601
|
}
|
|
@@ -2547,7 +2608,7 @@ Q5.draw = function () {
|
|
|
2547
2608
|
* @param {string} key key to check
|
|
2548
2609
|
* @returns {boolean} true if the key is pressed, false otherwise
|
|
2549
2610
|
* @example
|
|
2550
|
-
|
|
2611
|
+
function draw() {
|
|
2551
2612
|
background(200);
|
|
2552
2613
|
|
|
2553
2614
|
if (keyIsDown('f') && keyIsDown('j')) {
|
|
@@ -2560,7 +2621,7 @@ Q5.draw = function () {
|
|
|
2560
2621
|
/** 🖲️
|
|
2561
2622
|
* Define this function to respond to key down events.
|
|
2562
2623
|
* @example
|
|
2563
|
-
|
|
2624
|
+
createCanvas(200);
|
|
2564
2625
|
|
|
2565
2626
|
let gray = 95;
|
|
2566
2627
|
function keyPressed() {
|
|
@@ -2573,7 +2634,7 @@ function keyPressed() {
|
|
|
2573
2634
|
/** 🖲️
|
|
2574
2635
|
* Define this function to respond to key up events.
|
|
2575
2636
|
* @example
|
|
2576
|
-
|
|
2637
|
+
createCanvas(200);
|
|
2577
2638
|
|
|
2578
2639
|
let gray = 95;
|
|
2579
2640
|
function keyReleased() {
|
|
@@ -2588,7 +2649,7 @@ function keyReleased() {
|
|
|
2588
2649
|
* browser window. Each touch being an object with
|
|
2589
2650
|
* `id`, `x`, and `y` properties.
|
|
2590
2651
|
* @example
|
|
2591
|
-
|
|
2652
|
+
function draw() {
|
|
2592
2653
|
background(200);
|
|
2593
2654
|
for (let touch of touches) {
|
|
2594
2655
|
circle(touch.x, touch.y, 100);
|
|
@@ -2604,7 +2665,7 @@ Q5.draw = function () {
|
|
|
2604
2665
|
* Return true to enable touch gestures like pinch-to-zoom
|
|
2605
2666
|
* and scroll, which q5 disables on the canvas by default.
|
|
2606
2667
|
* @example
|
|
2607
|
-
|
|
2668
|
+
createCanvas(200);
|
|
2608
2669
|
|
|
2609
2670
|
let gray = 95;
|
|
2610
2671
|
function touchStarted() {
|
|
@@ -2621,7 +2682,7 @@ function touchStarted() {
|
|
|
2621
2682
|
* Return true to enable touch gestures like pinch-to-zoom
|
|
2622
2683
|
* and scroll, which q5 disables on the canvas by default.
|
|
2623
2684
|
* @example
|
|
2624
|
-
|
|
2685
|
+
createCanvas(200);
|
|
2625
2686
|
|
|
2626
2687
|
let gray = 95;
|
|
2627
2688
|
function touchEnded() {
|
|
@@ -2638,7 +2699,7 @@ function touchEnded() {
|
|
|
2638
2699
|
* Return true to enable touch gestures like pinch-to-zoom
|
|
2639
2700
|
* and scroll, which q5 disables on the canvas by default.
|
|
2640
2701
|
* @example
|
|
2641
|
-
|
|
2702
|
+
createCanvas(200);
|
|
2642
2703
|
let gray = 95;
|
|
2643
2704
|
|
|
2644
2705
|
function touchMoved() {
|
|
@@ -2659,7 +2720,7 @@ function touchMoved() {
|
|
|
2659
2720
|
* The `event` property contains the original
|
|
2660
2721
|
* [PointerEvent](https://developer.mozilla.org/docs/Web/API/PointerEvent).
|
|
2661
2722
|
* @example
|
|
2662
|
-
|
|
2723
|
+
function draw() {
|
|
2663
2724
|
background(200);
|
|
2664
2725
|
for (let pointerID in pointers) {
|
|
2665
2726
|
let pointer = pointers[pointerID];
|
|
@@ -2677,7 +2738,7 @@ Q5.draw = function () {
|
|
|
2677
2738
|
* @param {number} [x] x-coordinate of the cursor's point
|
|
2678
2739
|
* @param {number} [y] y-coordinate of the cursor's point
|
|
2679
2740
|
* @example
|
|
2680
|
-
|
|
2741
|
+
createCanvas(200, 100);
|
|
2681
2742
|
cursor('pointer');
|
|
2682
2743
|
*/
|
|
2683
2744
|
function cursor(name: string, x?: number, y?: number): void;
|
|
@@ -2685,7 +2746,7 @@ cursor('pointer');
|
|
|
2685
2746
|
/** 🖲️
|
|
2686
2747
|
* Hides the cursor within the bounds of the canvas.
|
|
2687
2748
|
* @example
|
|
2688
|
-
|
|
2749
|
+
createCanvas(200, 100);
|
|
2689
2750
|
noCursor();
|
|
2690
2751
|
*/
|
|
2691
2752
|
function noCursor(): void;
|
|
@@ -2699,7 +2760,7 @@ noCursor();
|
|
|
2699
2760
|
* Return true to allow the default behavior of scrolling the page.
|
|
2700
2761
|
* @example
|
|
2701
2762
|
let x = y = 100;
|
|
2702
|
-
|
|
2763
|
+
function draw() {
|
|
2703
2764
|
circle(x, y, 10);
|
|
2704
2765
|
}
|
|
2705
2766
|
function mouseWheel(e) {
|
|
@@ -2720,7 +2781,7 @@ function mouseWheel(e) {
|
|
|
2720
2781
|
*
|
|
2721
2782
|
* @param {boolean} unadjustedMovement set to true to disable OS-level mouse acceleration and access raw mouse input
|
|
2722
2783
|
* @example
|
|
2723
|
-
|
|
2784
|
+
function draw() {
|
|
2724
2785
|
circle(mouseX / 10, mouseY / 10, 10);
|
|
2725
2786
|
}
|
|
2726
2787
|
|
|
@@ -2747,15 +2808,15 @@ function doubleClicked() {
|
|
|
2747
2808
|
* @param {number} [high] upper bound (exclusive)
|
|
2748
2809
|
* @returns {number | any} a random number or element
|
|
2749
2810
|
* @example
|
|
2750
|
-
|
|
2811
|
+
createCanvas(200);
|
|
2751
2812
|
background(200);
|
|
2752
2813
|
frameRate(5);
|
|
2753
2814
|
|
|
2754
|
-
|
|
2815
|
+
function draw() {
|
|
2755
2816
|
circle(100, 100, random(20, 200));
|
|
2756
2817
|
}
|
|
2757
2818
|
* @example
|
|
2758
|
-
|
|
2819
|
+
function draw() {
|
|
2759
2820
|
circle(random(200), random(200), 10);
|
|
2760
2821
|
}
|
|
2761
2822
|
*/
|
|
@@ -2770,13 +2831,14 @@ Q5.draw = function () {
|
|
|
2770
2831
|
* @param {number} amount absolute maximum amount of jitter, default is 1
|
|
2771
2832
|
* @returns {number} random number between -val and val
|
|
2772
2833
|
* @example
|
|
2773
|
-
|
|
2834
|
+
function draw() {
|
|
2774
2835
|
circle(mouseX + jit(3), mouseY + jit(3), 5);
|
|
2775
2836
|
}
|
|
2776
2837
|
* @example
|
|
2777
|
-
await
|
|
2838
|
+
let q = await Q5.WebGPU();
|
|
2839
|
+
createCanvas(200, 100);
|
|
2778
2840
|
|
|
2779
|
-
|
|
2841
|
+
q.draw = () => {
|
|
2780
2842
|
circle(jit(50), 0, random(50));
|
|
2781
2843
|
};
|
|
2782
2844
|
*/
|
|
@@ -2791,13 +2853,13 @@ Q5.draw = function () {
|
|
|
2791
2853
|
* @param {number} [z] z-coordinate input
|
|
2792
2854
|
* @returns {number} a noise value
|
|
2793
2855
|
* @example
|
|
2794
|
-
|
|
2856
|
+
function draw() {
|
|
2795
2857
|
background(200);
|
|
2796
2858
|
let n = noise(frameCount * 0.01);
|
|
2797
2859
|
circle(100, 100, n * 200);
|
|
2798
2860
|
}
|
|
2799
2861
|
* @example
|
|
2800
|
-
|
|
2862
|
+
function draw() {
|
|
2801
2863
|
background(200);
|
|
2802
2864
|
let t = (frameCount + mouseX) * 0.02;
|
|
2803
2865
|
for (let x = -5; x < 220; x += 10) {
|
|
@@ -2805,19 +2867,6 @@ Q5.draw = function () {
|
|
|
2805
2867
|
circle(x, 100, n * 40);
|
|
2806
2868
|
}
|
|
2807
2869
|
}
|
|
2808
|
-
* @example
|
|
2809
|
-
await createCanvas(200);
|
|
2810
|
-
|
|
2811
|
-
Q5.draw = () => {
|
|
2812
|
-
noStroke();
|
|
2813
|
-
let t = millis() * 0.002;
|
|
2814
|
-
for (let x = -100; x < 100; x += 5) {
|
|
2815
|
-
for (let y = -100; y < 100; y += 5) {
|
|
2816
|
-
fill(noise(t, (mouseX + x) * .05, y * .05));
|
|
2817
|
-
square(x, y, 5);
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
};
|
|
2821
2870
|
*/
|
|
2822
2871
|
function noise(x?: number, y?: number, z?: number): number;
|
|
2823
2872
|
|
|
@@ -2831,7 +2880,7 @@ Q5.draw = () => {
|
|
|
2831
2880
|
* @param {number} y2 y-coordinate of the second point
|
|
2832
2881
|
* @returns {number} distance between the points
|
|
2833
2882
|
* @example
|
|
2834
|
-
|
|
2883
|
+
function draw() {
|
|
2835
2884
|
background(200);
|
|
2836
2885
|
circle(100, 100, 20);
|
|
2837
2886
|
circle(mouseX, mouseY, 20);
|
|
@@ -2920,7 +2969,7 @@ Q5.draw = function () {
|
|
|
2920
2969
|
* @param {number} [d] number of decimal places to round to
|
|
2921
2970
|
* @returns {number} rounded number
|
|
2922
2971
|
* @example
|
|
2923
|
-
|
|
2972
|
+
createCanvas(200, 100);
|
|
2924
2973
|
background(200);
|
|
2925
2974
|
textSize(32);
|
|
2926
2975
|
text(round(PI, 5), 10, 60);
|
|
@@ -2932,7 +2981,7 @@ text(round(PI, 5), 10, 60);
|
|
|
2932
2981
|
* @param {number} n a number
|
|
2933
2982
|
* @returns {number} rounded number
|
|
2934
2983
|
* @example
|
|
2935
|
-
|
|
2984
|
+
createCanvas(200, 100);
|
|
2936
2985
|
background(200);
|
|
2937
2986
|
textSize(32);
|
|
2938
2987
|
text(ceil(PI), 10, 60);
|
|
@@ -2944,7 +2993,7 @@ text(ceil(PI), 10, 60);
|
|
|
2944
2993
|
* @param {number} n a number
|
|
2945
2994
|
* @returns {number} rounded number
|
|
2946
2995
|
* @example
|
|
2947
|
-
|
|
2996
|
+
createCanvas(200, 100);
|
|
2948
2997
|
background(200);
|
|
2949
2998
|
textSize(32);
|
|
2950
2999
|
text(floor(-PI), 10, 60);
|
|
@@ -2956,7 +3005,7 @@ text(floor(-PI), 10, 60);
|
|
|
2956
3005
|
* @param {...number} args numbers to compare
|
|
2957
3006
|
* @returns {number} minimum
|
|
2958
3007
|
* @example
|
|
2959
|
-
|
|
3008
|
+
function draw() {
|
|
2960
3009
|
background(min(mouseX, 100));
|
|
2961
3010
|
}
|
|
2962
3011
|
*/
|
|
@@ -2967,7 +3016,7 @@ Q5.draw = function () {
|
|
|
2967
3016
|
* @param {...number} args numbers to compare
|
|
2968
3017
|
* @returns {number} maximum
|
|
2969
3018
|
* @example
|
|
2970
|
-
|
|
3019
|
+
function draw() {
|
|
2971
3020
|
background(max(mouseX, 100));
|
|
2972
3021
|
}
|
|
2973
3022
|
*/
|
|
@@ -2975,7 +3024,7 @@ Q5.draw = function () {
|
|
|
2975
3024
|
|
|
2976
3025
|
/** 🧮
|
|
2977
3026
|
* Calculates the value of a base raised to a power.
|
|
2978
|
-
*
|
|
3027
|
+
*
|
|
2979
3028
|
* For example, `pow(2, 3)` calculates 2 * 2 * 2 which is 8.
|
|
2980
3029
|
* @param {number} base base
|
|
2981
3030
|
* @param {number} exponent exponent
|
|
@@ -3039,8 +3088,8 @@ Q5.draw = function () {
|
|
|
3039
3088
|
|
|
3040
3089
|
/** 🧮
|
|
3041
3090
|
* Sets the noise generation mode.
|
|
3042
|
-
*
|
|
3043
|
-
* Only the default mode, "perlin", is included in q5.js. Use of the
|
|
3091
|
+
*
|
|
3092
|
+
* Only the default mode, "perlin", is included in q5.js. Use of the
|
|
3044
3093
|
* other modes requires the q5-noiser module.
|
|
3045
3094
|
* @param {'perlin' | 'simplex' | 'blocky'} mode noise generation mode
|
|
3046
3095
|
*/
|
|
@@ -3094,7 +3143,7 @@ Q5.draw = function () {
|
|
|
3094
3143
|
/** 🔊
|
|
3095
3144
|
* q5.js includes low latency sound playback and basic mixing powered
|
|
3096
3145
|
* by WebAudio.
|
|
3097
|
-
*
|
|
3146
|
+
*
|
|
3098
3147
|
* For audio filtering, synthesis, and analysis, consider using
|
|
3099
3148
|
* [p5.sound](https://p5js.org/reference/p5.sound/).
|
|
3100
3149
|
*/
|
|
@@ -3124,12 +3173,12 @@ Q5.draw = function () {
|
|
|
3124
3173
|
* @param {string} url sound file
|
|
3125
3174
|
* @returns {Sound | Promise<Sound>} a new `Sound` object or promise
|
|
3126
3175
|
* @example
|
|
3127
|
-
|
|
3176
|
+
createCanvas(200);
|
|
3128
3177
|
|
|
3129
3178
|
let sound = loadSound('/assets/jump.wav');
|
|
3130
3179
|
sound.volume = 0.3;
|
|
3131
3180
|
|
|
3132
|
-
|
|
3181
|
+
function mousePressed() {
|
|
3133
3182
|
sound.play();
|
|
3134
3183
|
}
|
|
3135
3184
|
*/
|
|
@@ -3148,12 +3197,12 @@ Q5.mousePressed = function () {
|
|
|
3148
3197
|
* @param url audio file
|
|
3149
3198
|
* @returns {HTMLAudioElement | Promise<HTMLAudioElement>} an HTMLAudioElement or promise
|
|
3150
3199
|
* @example
|
|
3151
|
-
|
|
3200
|
+
createCanvas(200);
|
|
3152
3201
|
|
|
3153
3202
|
let audio = loadAudio('/assets/retro.flac');
|
|
3154
3203
|
audio.volume = 0.4;
|
|
3155
3204
|
|
|
3156
|
-
|
|
3205
|
+
function mousePressed() {
|
|
3157
3206
|
audio.play();
|
|
3158
3207
|
}
|
|
3159
3208
|
*/
|
|
@@ -3210,10 +3259,10 @@ Q5.mousePressed = function () {
|
|
|
3210
3259
|
|
|
3211
3260
|
/** 🔊
|
|
3212
3261
|
* Plays the sound.
|
|
3213
|
-
*
|
|
3262
|
+
*
|
|
3214
3263
|
* If this function is run when the sound is already playing,
|
|
3215
3264
|
* a new playback will start, causing a layering effect.
|
|
3216
|
-
*
|
|
3265
|
+
*
|
|
3217
3266
|
* If this function is run when the sound is paused,
|
|
3218
3267
|
* all playback instances will be resumed.
|
|
3219
3268
|
*/
|
|
@@ -3227,7 +3276,7 @@ Q5.mousePressed = function () {
|
|
|
3227
3276
|
/** 🔊
|
|
3228
3277
|
* Stops the sound, resetting its playback position
|
|
3229
3278
|
* to the beginning.
|
|
3230
|
-
*
|
|
3279
|
+
*
|
|
3231
3280
|
* Removes all playback instances.
|
|
3232
3281
|
*/
|
|
3233
3282
|
stop(): void;
|
|
@@ -3262,7 +3311,7 @@ Q5.mousePressed = function () {
|
|
|
3262
3311
|
* @param {string} [content] content of the element
|
|
3263
3312
|
* @returns {HTMLElement} element
|
|
3264
3313
|
* @example
|
|
3265
|
-
|
|
3314
|
+
createCanvas(200);
|
|
3266
3315
|
|
|
3267
3316
|
let el = createEl('div', '*');
|
|
3268
3317
|
el.position(50, 50);
|
|
@@ -3280,7 +3329,7 @@ el.style.color = 'white';
|
|
|
3280
3329
|
* @param {string} [text] text content
|
|
3281
3330
|
* @param {boolean} [newTab] whether to open the link in a new tab
|
|
3282
3331
|
* @example
|
|
3283
|
-
|
|
3332
|
+
createCanvas(200);
|
|
3284
3333
|
|
|
3285
3334
|
let link = createA('https://q5js.org', 'q5.js');
|
|
3286
3335
|
link.position(16, 42);
|
|
@@ -3296,7 +3345,7 @@ link.addEventListener('mouseover', () => {
|
|
|
3296
3345
|
* Creates a button element.
|
|
3297
3346
|
* @param {string} [content] text content
|
|
3298
3347
|
* @example
|
|
3299
|
-
|
|
3348
|
+
createCanvas(200, 100);
|
|
3300
3349
|
|
|
3301
3350
|
let btn = createButton('Click me!');
|
|
3302
3351
|
|
|
@@ -3315,7 +3364,7 @@ btn.addEventListener('click', () => {
|
|
|
3315
3364
|
* @param {string} [label] text label placed next to the checkbox
|
|
3316
3365
|
* @param {boolean} [checked] initial state
|
|
3317
3366
|
* @example
|
|
3318
|
-
|
|
3367
|
+
createCanvas(200, 100);
|
|
3319
3368
|
|
|
3320
3369
|
let box = createCheckbox('Check me!');
|
|
3321
3370
|
box.label.style.color = 'lime';
|
|
@@ -3333,12 +3382,12 @@ box.addEventListener('input', () => {
|
|
|
3333
3382
|
* Use the `value` property to get or set the color value.
|
|
3334
3383
|
* @param {string} [value] initial color value
|
|
3335
3384
|
* @example
|
|
3336
|
-
|
|
3385
|
+
createCanvas(200, 100);
|
|
3337
3386
|
|
|
3338
3387
|
let picker = createColorPicker();
|
|
3339
3388
|
picker.value = '#fd7575';
|
|
3340
3389
|
|
|
3341
|
-
|
|
3390
|
+
function draw() {
|
|
3342
3391
|
background(picker.value);
|
|
3343
3392
|
}
|
|
3344
3393
|
*/
|
|
@@ -3348,7 +3397,7 @@ Q5.draw = function () {
|
|
|
3348
3397
|
* Creates an image element.
|
|
3349
3398
|
* @param {string} src url of the image
|
|
3350
3399
|
* @example
|
|
3351
|
-
|
|
3400
|
+
createCanvas(200, 100);
|
|
3352
3401
|
|
|
3353
3402
|
let img = createImg('/assets/p5play_logo.webp')
|
|
3354
3403
|
.position(0, 0)
|
|
@@ -3368,7 +3417,7 @@ let img = createImg('/assets/p5play_logo.webp')
|
|
|
3368
3417
|
* @param {string} [value] initial value
|
|
3369
3418
|
* @param {string} [type] text input type, can be 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
|
|
3370
3419
|
* @example
|
|
3371
|
-
|
|
3420
|
+
createCanvas(200, 100);
|
|
3372
3421
|
textSize(64);
|
|
3373
3422
|
|
|
3374
3423
|
let input = createInput();
|
|
@@ -3386,7 +3435,7 @@ input.addEventListener('input', () => {
|
|
|
3386
3435
|
* Creates a paragraph element.
|
|
3387
3436
|
* @param {string} [content] text content
|
|
3388
3437
|
* @example
|
|
3389
|
-
|
|
3438
|
+
createCanvas(200, 50);
|
|
3390
3439
|
background('coral');
|
|
3391
3440
|
|
|
3392
3441
|
let p = createP('Hello, world!');
|
|
@@ -3403,19 +3452,19 @@ p.style.color = 'pink';
|
|
|
3403
3452
|
* Use the `value` property to get or set the value of the selected radio button.
|
|
3404
3453
|
* @param {string} [groupName]
|
|
3405
3454
|
* @example
|
|
3406
|
-
|
|
3455
|
+
createCanvas(200, 100);
|
|
3407
3456
|
|
|
3408
3457
|
let radio = createRadio()
|
|
3409
3458
|
.option('square', '1')
|
|
3410
3459
|
.option('circle', '2');
|
|
3411
3460
|
|
|
3412
|
-
|
|
3461
|
+
function draw() {
|
|
3413
3462
|
background(200);
|
|
3414
3463
|
if (radio.value == '1') square(75, 25, 50);
|
|
3415
3464
|
if (radio.value == '2') circle(100, 50, 50);
|
|
3416
3465
|
}
|
|
3417
3466
|
*/
|
|
3418
|
-
function createRadio(groupName): HTMLDivElement;
|
|
3467
|
+
function createRadio(groupName?: string): HTMLDivElement;
|
|
3419
3468
|
|
|
3420
3469
|
/** 📑
|
|
3421
3470
|
* Creates a select element.
|
|
@@ -3432,7 +3481,7 @@ Q5.draw = function () {
|
|
|
3432
3481
|
* string or an array of strings.
|
|
3433
3482
|
* @param {string} [placeholder] optional placeholder text that appears before an option is selected
|
|
3434
3483
|
* @example
|
|
3435
|
-
|
|
3484
|
+
createCanvas(200, 100);
|
|
3436
3485
|
|
|
3437
3486
|
let sel = createSelect('Select a color')
|
|
3438
3487
|
.option('Red', '#f55')
|
|
@@ -3442,7 +3491,7 @@ sel.addEventListener('change', () => {
|
|
|
3442
3491
|
background(sel.value);
|
|
3443
3492
|
});
|
|
3444
3493
|
*/
|
|
3445
|
-
function createSelect(placeholder): HTMLSelectElement;
|
|
3494
|
+
function createSelect(placeholder?: string): HTMLSelectElement;
|
|
3446
3495
|
|
|
3447
3496
|
/** 📑
|
|
3448
3497
|
* Creates a slider element.
|
|
@@ -3455,13 +3504,13 @@ sel.addEventListener('change', () => {
|
|
|
3455
3504
|
* @param {number} [value] initial value
|
|
3456
3505
|
* @param {number} [step] step size
|
|
3457
3506
|
* @example
|
|
3458
|
-
|
|
3507
|
+
createCanvas(200);
|
|
3459
3508
|
|
|
3460
3509
|
let slider = createSlider(0, 255)
|
|
3461
3510
|
.position(10, 10)
|
|
3462
3511
|
.size(180);
|
|
3463
3512
|
|
|
3464
|
-
|
|
3513
|
+
function draw() {
|
|
3465
3514
|
background(slider.val());
|
|
3466
3515
|
}
|
|
3467
3516
|
*/
|
|
@@ -3481,7 +3530,7 @@ Q5.draw = function () {
|
|
|
3481
3530
|
* @param {string} src url of the video
|
|
3482
3531
|
* @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
|
|
3483
3532
|
* @example
|
|
3484
|
-
|
|
3533
|
+
createCanvas(0);
|
|
3485
3534
|
|
|
3486
3535
|
let vid = createVideo('/assets/apollo4.mp4');
|
|
3487
3536
|
vid.size(200, 150);
|
|
@@ -3489,15 +3538,15 @@ vid.autoplay = vid.muted = vid.loop = true;
|
|
|
3489
3538
|
vid.controls = true;
|
|
3490
3539
|
|
|
3491
3540
|
* @example
|
|
3492
|
-
|
|
3541
|
+
createCanvas(200, 150);
|
|
3493
3542
|
let vid = createVideo('/assets/apollo4.mp4');
|
|
3494
3543
|
vid.hide();
|
|
3495
3544
|
|
|
3496
|
-
|
|
3545
|
+
function mousePressed() {
|
|
3497
3546
|
vid.currentTime = 0;
|
|
3498
3547
|
vid.play();
|
|
3499
3548
|
}
|
|
3500
|
-
|
|
3549
|
+
function draw() {
|
|
3501
3550
|
image(vid, 0, 0, 200, 150);
|
|
3502
3551
|
filter(HUE_ROTATE, 90);
|
|
3503
3552
|
}
|
|
@@ -3524,30 +3573,30 @@ Q5.draw = function () {
|
|
|
3524
3573
|
* @param {boolean} [flipped] whether to mirror the video vertically, true by default
|
|
3525
3574
|
* @returns {HTMLVideoElement | Promise<HTMLVideoElement>} a new video element or promise
|
|
3526
3575
|
* @example
|
|
3527
|
-
|
|
3576
|
+
createCanvas(200);
|
|
3528
3577
|
|
|
3529
|
-
|
|
3578
|
+
function mousePressed() {
|
|
3530
3579
|
let cap = createCapture(VIDEO);
|
|
3531
3580
|
cap.size(200, 112.5);
|
|
3532
3581
|
canvas.remove();
|
|
3533
3582
|
}
|
|
3534
3583
|
* @example
|
|
3535
|
-
|
|
3584
|
+
createCanvas(200);
|
|
3536
3585
|
|
|
3537
3586
|
let cap;
|
|
3538
|
-
|
|
3587
|
+
function mousePressed() {
|
|
3539
3588
|
cap = createCapture(VIDEO);
|
|
3540
3589
|
cap.hide();
|
|
3541
3590
|
}
|
|
3542
3591
|
|
|
3543
|
-
|
|
3592
|
+
function draw() {
|
|
3544
3593
|
let y = frameCount % height;
|
|
3545
3594
|
image(cap, 0, y, 200, 200);
|
|
3546
3595
|
}
|
|
3547
3596
|
* @example
|
|
3548
|
-
|
|
3597
|
+
createCanvas(200);
|
|
3549
3598
|
|
|
3550
|
-
|
|
3599
|
+
function mousePressed() {
|
|
3551
3600
|
let cap = createCapture({
|
|
3552
3601
|
video: { width: 640, height: 480 }
|
|
3553
3602
|
});
|
|
@@ -3594,12 +3643,12 @@ Q5.mousePressed = function () {
|
|
|
3594
3643
|
*
|
|
3595
3644
|
* @returns {HTMLElement} a recorder, q5 DOM element
|
|
3596
3645
|
* @example
|
|
3597
|
-
|
|
3646
|
+
createCanvas(200);
|
|
3598
3647
|
|
|
3599
3648
|
let rec = createRecorder();
|
|
3600
3649
|
rec.bitrate = 10;
|
|
3601
3650
|
|
|
3602
|
-
|
|
3651
|
+
function draw() {
|
|
3603
3652
|
circle(mouseX, random(height), 10);
|
|
3604
3653
|
}
|
|
3605
3654
|
*/
|
|
@@ -3607,7 +3656,7 @@ Q5.draw = function () {
|
|
|
3607
3656
|
|
|
3608
3657
|
/** 🎞️
|
|
3609
3658
|
* Starts recording the canvas or resumes recording if it was paused.
|
|
3610
|
-
*
|
|
3659
|
+
*
|
|
3611
3660
|
* If no recorder exists, one is created but not displayed.
|
|
3612
3661
|
*/
|
|
3613
3662
|
function record(): void;
|
|
@@ -3626,16 +3675,16 @@ Q5.draw = function () {
|
|
|
3626
3675
|
* Saves the current recording as a video file.
|
|
3627
3676
|
* @param {string} fileName
|
|
3628
3677
|
* @example
|
|
3629
|
-
|
|
3678
|
+
function draw() {
|
|
3630
3679
|
square(mouseX, random(200), 10);
|
|
3631
3680
|
}
|
|
3632
3681
|
|
|
3633
|
-
|
|
3682
|
+
function mousePressed() {
|
|
3634
3683
|
if (!recording) record();
|
|
3635
3684
|
else saveRecording('squares');
|
|
3636
3685
|
}
|
|
3637
3686
|
*/
|
|
3638
|
-
function saveRecording(fileName): void;
|
|
3687
|
+
function saveRecording(fileName: string): void;
|
|
3639
3688
|
|
|
3640
3689
|
/** 🎞️
|
|
3641
3690
|
* True if the canvas is currently being recorded.
|
|
@@ -3655,15 +3704,17 @@ Q5.mousePressed = function () {
|
|
|
3655
3704
|
* @param {...string} urls
|
|
3656
3705
|
* @returns {Promise<any[]>} a promise that resolves with objects
|
|
3657
3706
|
* @example
|
|
3658
|
-
|
|
3707
|
+
let logo;
|
|
3659
3708
|
|
|
3660
|
-
|
|
3709
|
+
async function setup() {
|
|
3710
|
+
logo = await load('/q5js_logo.avif');
|
|
3711
|
+
}
|
|
3661
3712
|
|
|
3662
|
-
|
|
3713
|
+
function draw() {
|
|
3663
3714
|
image(logo, 0, 0, 200, 200);
|
|
3664
3715
|
}
|
|
3665
3716
|
* @example
|
|
3666
|
-
|
|
3717
|
+
createCanvas(200);
|
|
3667
3718
|
|
|
3668
3719
|
// use with top level await in a module
|
|
3669
3720
|
await load('/assets/Robotica.ttf');
|
|
@@ -3671,27 +3722,6 @@ await load('/assets/Robotica.ttf');
|
|
|
3671
3722
|
background(255);
|
|
3672
3723
|
textSize(24);
|
|
3673
3724
|
text('Hello, world!', 16, 100);
|
|
3674
|
-
* @example
|
|
3675
|
-
await createCanvas(200);
|
|
3676
|
-
|
|
3677
|
-
let [jump, retro] = await load(
|
|
3678
|
-
'/assets/jump.wav', '/assets/retro.flac'
|
|
3679
|
-
);
|
|
3680
|
-
|
|
3681
|
-
Q5.mousePressed = () => {
|
|
3682
|
-
mouseButton == 'left' ? jump.play() : retro.play();
|
|
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
|
-
}
|
|
3695
3725
|
*/
|
|
3696
3726
|
function load(...urls: string[]): Promise<any[]>;
|
|
3697
3727
|
|
|
@@ -3705,21 +3735,21 @@ for (let mammal of mammals) {
|
|
|
3705
3735
|
* @param {object} [data] canvas, image, or JS object
|
|
3706
3736
|
* @param {string} [fileName] filename to save as
|
|
3707
3737
|
* @example
|
|
3708
|
-
|
|
3738
|
+
createCanvas(200);
|
|
3709
3739
|
background(200);
|
|
3710
3740
|
circle(100, 100, 50);
|
|
3711
3741
|
|
|
3712
|
-
|
|
3742
|
+
function mousePressed() {
|
|
3713
3743
|
save('circle.png');
|
|
3714
3744
|
}
|
|
3715
3745
|
* @example
|
|
3716
|
-
|
|
3746
|
+
createCanvas(200);
|
|
3717
3747
|
|
|
3718
3748
|
textSize(180);
|
|
3719
3749
|
let bolt = createTextImage('⚡️');
|
|
3720
3750
|
image(bolt, 16, -56);
|
|
3721
3751
|
|
|
3722
|
-
|
|
3752
|
+
function mousePressed() {
|
|
3723
3753
|
save(bolt, 'bolt.png');
|
|
3724
3754
|
}
|
|
3725
3755
|
*/
|
|
@@ -3727,9 +3757,9 @@ Q5.mousePressed = function () {
|
|
|
3727
3757
|
|
|
3728
3758
|
/** 🛠️
|
|
3729
3759
|
* Loads a text file from the specified url.
|
|
3730
|
-
*
|
|
3760
|
+
*
|
|
3731
3761
|
* Returns a promise if used in async `setup`.
|
|
3732
|
-
*
|
|
3762
|
+
*
|
|
3733
3763
|
* @param {string} url text file
|
|
3734
3764
|
* @returns {object | Promise} an object containing the loaded text in the property `obj.text` or a promise
|
|
3735
3765
|
*/
|
|
@@ -3737,9 +3767,9 @@ Q5.mousePressed = function () {
|
|
|
3737
3767
|
|
|
3738
3768
|
/** 🛠️
|
|
3739
3769
|
* Loads a JSON file from the specified url.
|
|
3740
|
-
*
|
|
3770
|
+
*
|
|
3741
3771
|
* Returns a promise if used in async `setup`.
|
|
3742
|
-
*
|
|
3772
|
+
*
|
|
3743
3773
|
* @param {string} url JSON file
|
|
3744
3774
|
* @returns {any | Promise} an object or array containing the loaded JSON or a promise
|
|
3745
3775
|
*/
|
|
@@ -3747,9 +3777,9 @@ Q5.mousePressed = function () {
|
|
|
3747
3777
|
|
|
3748
3778
|
/** 🛠️
|
|
3749
3779
|
* Loads a CSV file from the specified url.
|
|
3750
|
-
*
|
|
3780
|
+
*
|
|
3751
3781
|
* Returns a promise if used in async `setup`.
|
|
3752
|
-
*
|
|
3782
|
+
*
|
|
3753
3783
|
* @param {string} url CSV file
|
|
3754
3784
|
* @returns {object[] | Promise<object[]>} an array of objects containing the loaded CSV or a promise
|
|
3755
3785
|
*/
|
|
@@ -3762,6 +3792,20 @@ Q5.mousePressed = function () {
|
|
|
3762
3792
|
*
|
|
3763
3793
|
* @param {string} url xml file
|
|
3764
3794
|
* @returns {Element | Promise<Element>} an object containing the loaded XML in a property called `obj.DOM` or a promise
|
|
3795
|
+
* @example
|
|
3796
|
+
async function setup() {
|
|
3797
|
+
createCanvas(200);
|
|
3798
|
+
background(200);
|
|
3799
|
+
textSize(32);
|
|
3800
|
+
|
|
3801
|
+
let myXML = await loadXML('/assets/animals.xml');
|
|
3802
|
+
|
|
3803
|
+
let mammals = myXML.getElementsByTagName('mammal');
|
|
3804
|
+
let y = 64;
|
|
3805
|
+
for (let mammal of mammals) {
|
|
3806
|
+
text(mammal.textContent, 20, (y += 32));
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3765
3809
|
*/
|
|
3766
3810
|
function loadXML(url: string): object | Promise<Element>;
|
|
3767
3811
|
|
|
@@ -3776,7 +3820,7 @@ Q5.mousePressed = function () {
|
|
|
3776
3820
|
|
|
3777
3821
|
/** 🛠
|
|
3778
3822
|
* Shuffles the elements of an array.
|
|
3779
|
-
*
|
|
3823
|
+
*
|
|
3780
3824
|
* @param {any[]} arr array to shuffle
|
|
3781
3825
|
* @param {boolean} [modify] whether to modify the original array, false by default which copies the array before shuffling
|
|
3782
3826
|
* @returns {any[]} shuffled array
|
|
@@ -4028,7 +4072,7 @@ Q5.mousePressed = function () {
|
|
|
4028
4072
|
* @param {string} code WGSL shader code excerpt
|
|
4029
4073
|
* @returns {GPUShaderModule} a shader program
|
|
4030
4074
|
* @example
|
|
4031
|
-
await
|
|
4075
|
+
let q = await Q5.WebGPU();
|
|
4032
4076
|
|
|
4033
4077
|
let wobble = createShader(`
|
|
4034
4078
|
@vertex
|
|
@@ -4044,13 +4088,13 @@ fn vertexMain(v: VertexParams) -> FragParams {
|
|
|
4044
4088
|
return f;
|
|
4045
4089
|
}`);
|
|
4046
4090
|
|
|
4047
|
-
|
|
4091
|
+
q.draw = () => {
|
|
4048
4092
|
clear();
|
|
4049
4093
|
shader(wobble);
|
|
4050
4094
|
plane(0, 0, 100);
|
|
4051
4095
|
};
|
|
4052
4096
|
* @example
|
|
4053
|
-
await
|
|
4097
|
+
let q = await Q5.WebGPU();
|
|
4054
4098
|
|
|
4055
4099
|
let stripes = createShader(`
|
|
4056
4100
|
@fragment
|
|
@@ -4059,7 +4103,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
4059
4103
|
return vec4(r, 0.0, 1, 1);
|
|
4060
4104
|
}`);
|
|
4061
4105
|
|
|
4062
|
-
|
|
4106
|
+
q.draw = () => {
|
|
4063
4107
|
shader(stripes);
|
|
4064
4108
|
triangle(-50, -50, 0, 50, 50, -50);
|
|
4065
4109
|
};
|
|
@@ -4073,7 +4117,8 @@ Q5.draw = function () {
|
|
|
4073
4117
|
* @param {number} w width or side length
|
|
4074
4118
|
* @param {number} [h] height
|
|
4075
4119
|
* @example
|
|
4076
|
-
await
|
|
4120
|
+
let q = await Q5.WebGPU();
|
|
4121
|
+
createCanvas(200);
|
|
4077
4122
|
plane(0, 0, 100);
|
|
4078
4123
|
*/
|
|
4079
4124
|
function plane(x: number, y: number, w: number, h?: number): void;
|
|
@@ -4087,7 +4132,7 @@ plane(0, 0, 100);
|
|
|
4087
4132
|
/** ⚡️
|
|
4088
4133
|
* Make q5 use the default shapes shader.
|
|
4089
4134
|
* @example
|
|
4090
|
-
await
|
|
4135
|
+
let q = await Q5.WebGPU();
|
|
4091
4136
|
|
|
4092
4137
|
let stripes = createShader(`
|
|
4093
4138
|
@fragment
|
|
@@ -4096,7 +4141,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
4096
4141
|
return vec4(1, g, 0, 1);
|
|
4097
4142
|
}`);
|
|
4098
4143
|
|
|
4099
|
-
|
|
4144
|
+
q.draw = () => {
|
|
4100
4145
|
shader(stripes);
|
|
4101
4146
|
background(0);
|
|
4102
4147
|
|
|
@@ -4139,7 +4184,8 @@ Q5.draw = function () {
|
|
|
4139
4184
|
* Use this function to customize a copy of the
|
|
4140
4185
|
* [default frame shader](https://github.com/q5js/q5.js/blob/main/src/shaders/frame.wgsl).
|
|
4141
4186
|
* @example
|
|
4142
|
-
await
|
|
4187
|
+
let q = await Q5.WebGPU();
|
|
4188
|
+
createCanvas(200);
|
|
4143
4189
|
|
|
4144
4190
|
let boxy = createFrameShader(`
|
|
4145
4191
|
@fragment
|
|
@@ -4150,7 +4196,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
4150
4196
|
return textureSample(tex, samp, uv);
|
|
4151
4197
|
}`);
|
|
4152
4198
|
|
|
4153
|
-
|
|
4199
|
+
q.draw = () => {
|
|
4154
4200
|
stroke(1);
|
|
4155
4201
|
strokeWeight(8);
|
|
4156
4202
|
line(mouseX, mouseY, pmouseX, pmouseY);
|
|
@@ -4167,7 +4213,7 @@ Q5.draw = function () {
|
|
|
4167
4213
|
* @param {string} code WGSL shader code excerpt
|
|
4168
4214
|
* @returns {GPUShaderModule} a shader program
|
|
4169
4215
|
* @example
|
|
4170
|
-
await
|
|
4216
|
+
let q = await Q5.WebGPU();
|
|
4171
4217
|
imageMode(CENTER);
|
|
4172
4218
|
|
|
4173
4219
|
let logo = loadImage('/q5js_logo.avif');
|
|
@@ -4180,7 +4226,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
4180
4226
|
return texColor;
|
|
4181
4227
|
}`);
|
|
4182
4228
|
|
|
4183
|
-
|
|
4229
|
+
q.draw = () => {
|
|
4184
4230
|
background(0.7);
|
|
4185
4231
|
shader(grate);
|
|
4186
4232
|
image(logo, 0, 0, 180, 180);
|
|
@@ -4196,7 +4242,8 @@ Q5.draw = function () {
|
|
|
4196
4242
|
* @param {string} code WGSL shader code excerpt
|
|
4197
4243
|
* @returns {GPUShaderModule} a shader program
|
|
4198
4244
|
* @example
|
|
4199
|
-
await
|
|
4245
|
+
let q = await Q5.WebGPU();
|
|
4246
|
+
createCanvas(200, 600);
|
|
4200
4247
|
|
|
4201
4248
|
let vid = createVideo('/assets/apollo4.mp4');
|
|
4202
4249
|
vid.hide();
|
|
@@ -4224,7 +4271,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
4224
4271
|
return texColor;
|
|
4225
4272
|
}`);
|
|
4226
4273
|
|
|
4227
|
-
|
|
4274
|
+
q.draw = () => {
|
|
4228
4275
|
clear();
|
|
4229
4276
|
if (mouseIsPressed) vid.play();
|
|
4230
4277
|
shader(flipper);
|
|
@@ -4241,7 +4288,7 @@ Q5.draw = function () {
|
|
|
4241
4288
|
* @param {string} code WGSL shader code excerpt
|
|
4242
4289
|
* @returns {GPUShaderModule} a shader program
|
|
4243
4290
|
* @example
|
|
4244
|
-
await
|
|
4291
|
+
let q = await Q5.WebGPU();
|
|
4245
4292
|
textAlign(CENTER, CENTER);
|
|
4246
4293
|
|
|
4247
4294
|
let spin = createTextShader(`
|
|
@@ -4267,7 +4314,7 @@ fn vertexMain(v : VertexParams) -> FragParams {
|
|
|
4267
4314
|
return f;
|
|
4268
4315
|
}`);
|
|
4269
4316
|
|
|
4270
|
-
|
|
4317
|
+
q.draw = () => {
|
|
4271
4318
|
clear();
|
|
4272
4319
|
shader(spin);
|
|
4273
4320
|
fill(1, 0, 1);
|