q5 2.7.4 → 2.8.2
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/package.json +1 -1
- package/q5.d.ts +131 -51
- package/q5.js +117 -111
- package/q5.min.js +2 -2
- package/src/q5-2d-canvas.js +4 -2
- package/src/q5-2d-drawing.js +14 -13
- package/src/q5-core.js +1 -1
- package/src/q5-math.js +1 -1
- package/src/q5-webgpu-canvas.js +7 -6
- package/src/q5-webgpu-drawing.js +88 -84
- package/src/q5-webgpu-image.js +2 -4
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ declare global {
|
|
|
54
54
|
* @example
|
|
55
55
|
function draw() {
|
|
56
56
|
background('lightgray');
|
|
57
|
-
circle(frameCount % 200, 100,
|
|
57
|
+
circle(frameCount % 200, 100, 80);
|
|
58
58
|
}
|
|
59
59
|
*/
|
|
60
60
|
function draw(): void;
|
|
@@ -98,7 +98,7 @@ function draw() {
|
|
|
98
98
|
* Stops the draw loop.
|
|
99
99
|
* @example
|
|
100
100
|
function draw() {
|
|
101
|
-
circle(frameCount * 5, 100,
|
|
101
|
+
circle(frameCount * 5, 100, 80);
|
|
102
102
|
noLoop();
|
|
103
103
|
}
|
|
104
104
|
*/
|
|
@@ -113,7 +113,7 @@ new Q5();
|
|
|
113
113
|
noLoop();
|
|
114
114
|
|
|
115
115
|
function draw() {
|
|
116
|
-
circle(frameCount * 5, 100,
|
|
116
|
+
circle(frameCount * 5, 100, 80);
|
|
117
117
|
}
|
|
118
118
|
function mouseClicked() {
|
|
119
119
|
redraw();
|
|
@@ -128,7 +128,7 @@ new Q5();
|
|
|
128
128
|
noLoop();
|
|
129
129
|
|
|
130
130
|
function draw() {
|
|
131
|
-
circle(frameCount * 5, 100,
|
|
131
|
+
circle(frameCount * 5, 100, 80);
|
|
132
132
|
}
|
|
133
133
|
function mouseClicked() {
|
|
134
134
|
loop();
|
|
@@ -147,7 +147,7 @@ function draw() {
|
|
|
147
147
|
if (mouseIsPressed) frameRate(10);
|
|
148
148
|
else frameRate(60);
|
|
149
149
|
|
|
150
|
-
circle(frameCount % 200, 100,
|
|
150
|
+
circle(frameCount % 200, 100, 80);
|
|
151
151
|
}
|
|
152
152
|
* @example
|
|
153
153
|
function draw() {
|
|
@@ -239,7 +239,7 @@ function draw() {
|
|
|
239
239
|
frameRate(random(30, 60));
|
|
240
240
|
|
|
241
241
|
x += deltaTime * 0.2;
|
|
242
|
-
circle(x % 200, 100,
|
|
242
|
+
circle(x % 200, 100, 20);
|
|
243
243
|
}
|
|
244
244
|
*/
|
|
245
245
|
var deltaTime: number;
|
|
@@ -255,9 +255,18 @@ function draw() {
|
|
|
255
255
|
* @param {number} [w] - width of the canvas
|
|
256
256
|
* @param {number} [h] - height of the canvas
|
|
257
257
|
* @param {Object} [options] - options for the canvas
|
|
258
|
-
* @param {boolean} [options.alpha] - whether the canvas should have an alpha channel, default is false
|
|
258
|
+
* @param {boolean} [options.alpha] - whether the canvas should have an alpha channel that allows it to be seen through, default is false
|
|
259
259
|
* @param {string} [options.colorSpace] - color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
|
|
260
260
|
* @returns {HTMLCanvasElement} created canvas element
|
|
261
|
+
* @example
|
|
262
|
+
function setup() {
|
|
263
|
+
createCanvas(200, 200, { alpha: true });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function draw() {
|
|
267
|
+
clear();
|
|
268
|
+
circle(frameCount % 200, 100, 80);
|
|
269
|
+
}
|
|
261
270
|
*/
|
|
262
271
|
function createCanvas(w?: number, h?: number, options?: CanvasRenderingContext2DSettings): HTMLCanvasElement;
|
|
263
272
|
|
|
@@ -268,87 +277,118 @@ function draw() {
|
|
|
268
277
|
|
|
269
278
|
/** ⬜️
|
|
270
279
|
* The width of the canvas.
|
|
280
|
+
* Can also be accessed via `canvas.w`/`canvas.width`.
|
|
271
281
|
*/
|
|
272
282
|
var width: number;
|
|
273
283
|
|
|
274
284
|
/** ⬜️
|
|
275
285
|
* The height of the canvas.
|
|
286
|
+
* Can also be accessed via `canvas.h`/`canvas.height`.
|
|
276
287
|
*/
|
|
277
288
|
var height: number;
|
|
278
289
|
|
|
279
290
|
/** ⬜️
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
291
|
+
* Clears the canvas, making every pixel completely transparent.
|
|
292
|
+
*
|
|
293
|
+
* The canvas can only be seen through if it has an alpha channel though.
|
|
283
294
|
*/
|
|
284
|
-
function
|
|
295
|
+
function clear(): void;
|
|
285
296
|
|
|
286
297
|
/** ⬜️
|
|
287
|
-
* Sets the
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
|
|
291
|
-
|
|
298
|
+
* Sets the fill color for shapes. The default is white.
|
|
299
|
+
*
|
|
300
|
+
* 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.
|
|
301
|
+
* @param {string | Color} color - fill color
|
|
302
|
+
* @example
|
|
303
|
+
function draw() {
|
|
304
|
+
background(200);
|
|
292
305
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
* @returns {number} display density
|
|
296
|
-
*/
|
|
297
|
-
function displayDensity(): number;
|
|
306
|
+
fill('red');
|
|
307
|
+
circle(80, 80, 80);
|
|
298
308
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
* @returns {void | boolean} true if fullscreen mode is enabled, false otherwise
|
|
309
|
+
fill('lime');
|
|
310
|
+
square(80, 80, 80);
|
|
311
|
+
}
|
|
303
312
|
*/
|
|
304
|
-
function
|
|
313
|
+
function fill(color: string | Color): void;
|
|
305
314
|
|
|
306
315
|
/** ⬜️
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
316
|
+
* Sets the stroke (outline) color for shapes. The default is black.
|
|
317
|
+
*
|
|
318
|
+
* 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.
|
|
319
|
+
* @param {string | Color} color - stroke color
|
|
310
320
|
* @example
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// rect will appear in the middle of the canvas
|
|
315
|
-
rect(20, 20, 60, 60);
|
|
316
|
-
*/
|
|
317
|
-
function flexibleCanvas(unit: number): void;
|
|
318
|
-
|
|
319
|
-
/** ⬜️
|
|
320
|
-
* Sets the fill color for shapes.
|
|
321
|
-
* @param {string | number} color - fill color
|
|
322
|
-
*/
|
|
323
|
-
function fill(color: string | number): void;
|
|
321
|
+
function draw() {
|
|
322
|
+
background(200);
|
|
323
|
+
fill(36);
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
325
|
+
stroke('red');
|
|
326
|
+
circle(80, 80, 80);
|
|
327
|
+
stroke('lime');
|
|
328
|
+
square(80, 80, 80);
|
|
329
|
+
}
|
|
328
330
|
*/
|
|
329
|
-
function stroke(color: string |
|
|
331
|
+
function stroke(color: string | Color): void;
|
|
330
332
|
|
|
331
333
|
/** ⬜️
|
|
332
334
|
* After calling this function, shapes will not be filled.
|
|
335
|
+
* @example
|
|
336
|
+
function draw() {
|
|
337
|
+
background(200);
|
|
338
|
+
|
|
339
|
+
noFill();
|
|
340
|
+
stroke('red');
|
|
341
|
+
circle(80, 80, 80);
|
|
342
|
+
stroke('lime');
|
|
343
|
+
square(80, 80, 80);
|
|
344
|
+
}
|
|
333
345
|
*/
|
|
334
346
|
function noFill(): void;
|
|
335
347
|
|
|
336
348
|
/** ⬜️
|
|
337
349
|
* After calling this function, shapes will not have a stroke (outline).
|
|
350
|
+
* @example
|
|
351
|
+
function draw() {
|
|
352
|
+
background(200);
|
|
353
|
+
fill(36);
|
|
354
|
+
stroke('red');
|
|
355
|
+
circle(80, 80, 80);
|
|
356
|
+
|
|
357
|
+
noStroke();
|
|
358
|
+
square(80, 80, 80);
|
|
359
|
+
}
|
|
338
360
|
*/
|
|
339
361
|
function noStroke(): void;
|
|
340
362
|
|
|
341
363
|
/** ⬜️
|
|
342
364
|
* Sets the size of the stroke used for lines and the border around shapes.
|
|
343
365
|
* @param {number} weight - size of the stroke in pixels
|
|
366
|
+
* @example
|
|
367
|
+
function setup() {
|
|
368
|
+
createCanvas(200, 200);
|
|
369
|
+
background(200);
|
|
370
|
+
stroke('red');
|
|
371
|
+
circle(50, 100, 80);
|
|
372
|
+
|
|
373
|
+
strokeWeight(20);
|
|
374
|
+
circle(150, 100, 80)
|
|
375
|
+
}
|
|
344
376
|
*/
|
|
345
377
|
function strokeWeight(weight: number): void;
|
|
346
378
|
|
|
347
379
|
/** ⬜️
|
|
348
|
-
* Sets the global opacity, `
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
|
|
380
|
+
* Sets the global opacity, which affects all subsequent drawing operations, except `background`. Default is 1, fully opaque.
|
|
381
|
+
* @param {number} alpha - opacity level, ranging from 0 to 1
|
|
382
|
+
* @example
|
|
383
|
+
function draw() {
|
|
384
|
+
background(200);
|
|
385
|
+
|
|
386
|
+
opacity(1);
|
|
387
|
+
circle(80, 80, 80);
|
|
388
|
+
|
|
389
|
+
opacity(0.2);
|
|
390
|
+
square(80, 80, 80);
|
|
391
|
+
}
|
|
352
392
|
*/
|
|
353
393
|
function opacity(alpha: number): void;
|
|
354
394
|
|
|
@@ -434,11 +474,51 @@ rect(20, 20, 60, 60);
|
|
|
434
474
|
*/
|
|
435
475
|
function pop(): void;
|
|
436
476
|
|
|
477
|
+
/** ⬜️
|
|
478
|
+
* Resizes the canvas to the specified width and height.
|
|
479
|
+
* @param {number} w - width of the canvas
|
|
480
|
+
* @param {number} h - height of the canvas
|
|
481
|
+
*/
|
|
482
|
+
function resizeCanvas(w: number, h: number): void;
|
|
483
|
+
|
|
484
|
+
/** ⬜️
|
|
485
|
+
* Sets the pixel density of the canvas.
|
|
486
|
+
* @param {number} v - pixel density value
|
|
487
|
+
* @returns {number} pixel density
|
|
488
|
+
*/
|
|
489
|
+
function pixelDensity(v: number): number;
|
|
490
|
+
|
|
491
|
+
/** ⬜️
|
|
492
|
+
* Returns the current display density.
|
|
493
|
+
* @returns {number} display density
|
|
494
|
+
*/
|
|
495
|
+
function displayDensity(): number;
|
|
496
|
+
|
|
497
|
+
/** ⬜️
|
|
498
|
+
* Enables or disables fullscreen mode.
|
|
499
|
+
* @param {boolean} [v] - boolean indicating whether to enable or disable fullscreen mode
|
|
500
|
+
* @returns {void | boolean} true if fullscreen mode is enabled, false otherwise
|
|
501
|
+
*/
|
|
502
|
+
function fullscreen(v?: boolean): void | boolean;
|
|
503
|
+
|
|
504
|
+
/** ⬜️
|
|
505
|
+
* Any position coordinates or dimensions you use will be scaled based
|
|
506
|
+
* on the unit provided to this function.
|
|
507
|
+
* @param {number} unit - unit to scale by
|
|
508
|
+
* @example
|
|
509
|
+
new Q5();
|
|
510
|
+
createCanvas(200, 200);
|
|
511
|
+
flexibleCanvas(100);
|
|
512
|
+
// rect will appear in the middle of the canvas
|
|
513
|
+
rect(20, 20, 60, 60);
|
|
514
|
+
*/
|
|
515
|
+
function flexibleCanvas(unit: number): void;
|
|
516
|
+
|
|
437
517
|
/** ⬜️
|
|
438
518
|
* Creates a graphics buffer.
|
|
439
519
|
* @param {number} w - width
|
|
440
520
|
* @param {number} h - height
|
|
441
|
-
* @param {
|
|
521
|
+
* @param {Object} [opt] - options
|
|
442
522
|
* @returns {Q5} a new Q5 graphics buffer
|
|
443
523
|
*/
|
|
444
524
|
function createGraphics(w: number, h: number, opt?: CanvasRenderingContext2DSettings): Q5;
|