q5 2.18.3 → 2.19.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 +1 -1
- package/q5.d.ts +194 -49
- package/q5.js +284 -128
- package/q5.min.js +2 -2
package/deno.json
CHANGED
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -293,18 +293,19 @@ function draw() {
|
|
|
293
293
|
/** ⭐️
|
|
294
294
|
* Creates an instance of Q5.
|
|
295
295
|
*
|
|
296
|
-
* Running `new Q5()` enables
|
|
297
|
-
* anywhere in your
|
|
298
|
-
* running [`createCanvas`](https://q5js.org/learn/#createCanvas).
|
|
296
|
+
* Running `new Q5()` enables use of q5 functions and variables
|
|
297
|
+
* anywhere in your sketch. You can also start Q5 in global
|
|
298
|
+
* mode by running [`createCanvas`](https://q5js.org/learn/#createCanvas).
|
|
299
299
|
*
|
|
300
|
-
* By default q5 uses the CanvasRenderingContext2D
|
|
300
|
+
* By default q5 uses the CanvasRenderingContext2D (aka Canvas2D)
|
|
301
|
+
* based c2d renderer.
|
|
301
302
|
*
|
|
302
|
-
* To use the q5 WebGPU renderer, run `Q5.webgpu()` after the creation of file level variables.
|
|
303
|
+
* To use the [q5 WebGPU renderer](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer), run `Q5.webgpu()` after the creation of file level variables.
|
|
303
304
|
* @param {string | Function} [scope]
|
|
304
305
|
* - "global": (default) top-level global mode, adds q5 functions
|
|
305
306
|
* and variables to the global scope
|
|
306
307
|
* - "auto": if users don't create a new instance of Q5 themselves, an instance will be created automatically with this scope, which replicates p5's global mode
|
|
307
|
-
* - "instance": enables users to [assign a Q5 instance to a variable](https://github.com/q5js/q5.js/wiki/Instance-Mode)
|
|
308
|
+
* - "instance": enables users to [assign a Q5 instance to a variable](https://github.com/q5js/q5.js/wiki/Instance-Mode)
|
|
308
309
|
* @param {HTMLElement} [parent] element that the canvas will be placed inside
|
|
309
310
|
* @example
|
|
310
311
|
new Q5();
|
|
@@ -1019,17 +1020,22 @@ point(125, 50);
|
|
|
1019
1020
|
function curveTightness(val: number): void;
|
|
1020
1021
|
|
|
1021
1022
|
/** 🧑🎨
|
|
1022
|
-
* Starts
|
|
1023
|
+
* Starts storing vertices for a convex shape.
|
|
1023
1024
|
*/
|
|
1024
1025
|
function beginShape(): void;
|
|
1025
1026
|
|
|
1026
1027
|
/** 🧑🎨
|
|
1027
|
-
*
|
|
1028
|
+
* Ends storing vertices for a convex shape.
|
|
1029
|
+
*/
|
|
1030
|
+
function endShape(): void;
|
|
1031
|
+
|
|
1032
|
+
/** 🧑🎨
|
|
1033
|
+
* Starts storing vertices for a contour.
|
|
1028
1034
|
*/
|
|
1029
1035
|
function beginContour(): void;
|
|
1030
1036
|
|
|
1031
1037
|
/** 🧑🎨
|
|
1032
|
-
* Ends
|
|
1038
|
+
* Ends storing vertices for a contour.
|
|
1033
1039
|
*/
|
|
1034
1040
|
function endContour(): void;
|
|
1035
1041
|
|
|
@@ -1557,14 +1563,6 @@ function setup() {
|
|
|
1557
1563
|
*/
|
|
1558
1564
|
function mask(img: Image): void;
|
|
1559
1565
|
|
|
1560
|
-
/** 🌆
|
|
1561
|
-
* Saves the image.
|
|
1562
|
-
* @param {string} filename filename or url
|
|
1563
|
-
* @param {string} extension file extension
|
|
1564
|
-
* @param {number} [quality] quality of the saved image
|
|
1565
|
-
*/
|
|
1566
|
-
function save(filename: string, extension: string, quality?: number): void;
|
|
1567
|
-
|
|
1568
1566
|
/** 🌆
|
|
1569
1567
|
* Retrieves a subsection of an image or canvas, as a q5 Image.
|
|
1570
1568
|
* Or if width and height are both 1, returns the color of the pixel at the given coordinates in `[R, G, B, A]` array format.
|
|
@@ -1600,7 +1598,7 @@ createCanvas(200);
|
|
|
1600
1598
|
let c = color('lime');
|
|
1601
1599
|
|
|
1602
1600
|
function draw() {
|
|
1603
|
-
set(
|
|
1601
|
+
set(randomX(), randomY(), c);
|
|
1604
1602
|
updatePixels();
|
|
1605
1603
|
}
|
|
1606
1604
|
*/
|
|
@@ -1934,16 +1932,40 @@ createCanvas(200);
|
|
|
1934
1932
|
* @param {number} [wrapWidth] maximum line width in characters
|
|
1935
1933
|
* @param {number} [lineLimit] maximum number of lines
|
|
1936
1934
|
* @returns {Q5.Image} an image object representing the rendered text
|
|
1935
|
+
* @example
|
|
1936
|
+
createCanvas(200, 200);
|
|
1937
|
+
textSize(80);
|
|
1938
|
+
let img = createTextImage('🐶');
|
|
1939
|
+
img.filter(INVERT);
|
|
1940
|
+
|
|
1941
|
+
function draw() {
|
|
1942
|
+
background(200);
|
|
1943
|
+
text('🐶', 10, 75);
|
|
1944
|
+
image(img, 110, 75);
|
|
1945
|
+
}
|
|
1937
1946
|
*/
|
|
1938
1947
|
function createTextImage(str: string, wrapWidth: number, lineLimit: number): Q5.Image;
|
|
1939
1948
|
|
|
1940
1949
|
/** ✍️
|
|
1941
|
-
* Renders an image generated from text onto the canvas.
|
|
1942
|
-
*
|
|
1950
|
+
* Renders an image generated from text onto the canvas.
|
|
1951
|
+
*
|
|
1952
|
+
* The positioning of the image is affected by the current text
|
|
1943
1953
|
* alignment and baseline settings.
|
|
1944
|
-
*
|
|
1954
|
+
*
|
|
1955
|
+
* If the first parameter is a string, an image of the text is
|
|
1956
|
+
* created automatically, then drawn.
|
|
1957
|
+
* @param {Q5.Image} img image object or text
|
|
1945
1958
|
* @param {number} x x-coordinate where the image should be placed
|
|
1946
1959
|
* @param {number} y y-coordinate where the image should be placed
|
|
1960
|
+
* @example
|
|
1961
|
+
createCanvas(200, 200);
|
|
1962
|
+
textSize(80);
|
|
1963
|
+
textAlign(CENTER, CENTER);
|
|
1964
|
+
|
|
1965
|
+
function draw() {
|
|
1966
|
+
background(200);
|
|
1967
|
+
textImage('🐶', 100, 100);
|
|
1968
|
+
}
|
|
1947
1969
|
*/
|
|
1948
1970
|
function textImage(img: HTMLImageElement, x: number, y: number): void;
|
|
1949
1971
|
|
|
@@ -1955,6 +1977,12 @@ createCanvas(200);
|
|
|
1955
1977
|
* @param {number} l minimum number of digits to appear before the decimal point; the number is padded with zeros if necessary
|
|
1956
1978
|
* @param {number} r number of digits to appear after the decimal point
|
|
1957
1979
|
* @returns {string} a string representation of the number, formatted accordingly
|
|
1980
|
+
* @example
|
|
1981
|
+
createCanvas(200, 100);
|
|
1982
|
+
background(200);
|
|
1983
|
+
|
|
1984
|
+
textSize(32);
|
|
1985
|
+
text(nf(PI, 4, 2), 10, 60);
|
|
1958
1986
|
*/
|
|
1959
1987
|
function nf(n: number, l: number, r: number): string;
|
|
1960
1988
|
|
|
@@ -2109,17 +2137,15 @@ rect(100, 0, 100, 200);
|
|
|
2109
2137
|
* RGB colors have components `r`/`red`, `g`/`green`, `b`/`blue`,
|
|
2110
2138
|
* and `a`/`alpha`.
|
|
2111
2139
|
*
|
|
2112
|
-
*
|
|
2113
|
-
*
|
|
2114
|
-
* By default when a canvas is using the `display-p3` color space,
|
|
2140
|
+
* By default when a canvas is using the HDR `display-p3` color space,
|
|
2115
2141
|
* rgb colors are mapped to the full P3 gamut, even when they use the
|
|
2116
|
-
* legacy integer format.
|
|
2142
|
+
* legacy integer 0-255 format.
|
|
2117
2143
|
* @example
|
|
2118
|
-
createCanvas(200);
|
|
2144
|
+
createCanvas(200, 100);
|
|
2119
2145
|
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2146
|
+
colorMode(RGB, 255);
|
|
2147
|
+
|
|
2148
|
+
background(255, 0, 0);
|
|
2123
2149
|
*/
|
|
2124
2150
|
const RGB: 'rgb';
|
|
2125
2151
|
|
|
@@ -2130,13 +2156,11 @@ function setup() {
|
|
|
2130
2156
|
* example, note that full red appears less saturated, as it would
|
|
2131
2157
|
* on an SDR display.
|
|
2132
2158
|
* @example
|
|
2133
|
-
createCanvas(200);
|
|
2159
|
+
createCanvas(200, 100);
|
|
2134
2160
|
|
|
2135
2161
|
colorMode(SRGB, 255);
|
|
2136
2162
|
|
|
2137
|
-
|
|
2138
|
-
background(255, 0, 0);
|
|
2139
|
-
}
|
|
2163
|
+
background(255, 0, 0);
|
|
2140
2164
|
*/
|
|
2141
2165
|
const SRGB: 'srgb';
|
|
2142
2166
|
|
|
@@ -2229,6 +2253,24 @@ function draw() {
|
|
|
2229
2253
|
*/
|
|
2230
2254
|
let mouseIsPressed: boolean;
|
|
2231
2255
|
|
|
2256
|
+
/** 🖲️
|
|
2257
|
+
* Define this function to respond to mouse events immediately.
|
|
2258
|
+
*
|
|
2259
|
+
* There can be a delay of up to one frame between a mouse event
|
|
2260
|
+
* and the next time the `draw` function is run.
|
|
2261
|
+
*
|
|
2262
|
+
* Useful for playing sounds.
|
|
2263
|
+
* @example
|
|
2264
|
+
createCanvas(200, 100);
|
|
2265
|
+
|
|
2266
|
+
let gray = 100;
|
|
2267
|
+
function mousePressed() {
|
|
2268
|
+
background(gray);
|
|
2269
|
+
gray += 10;
|
|
2270
|
+
}
|
|
2271
|
+
*/
|
|
2272
|
+
function mousePressed(): void;
|
|
2273
|
+
|
|
2232
2274
|
/** 🖲️
|
|
2233
2275
|
* The name of the last key pressed.
|
|
2234
2276
|
* @example
|
|
@@ -2265,6 +2307,24 @@ function draw() {
|
|
|
2265
2307
|
*/
|
|
2266
2308
|
function keyIsDown(key: string): boolean;
|
|
2267
2309
|
|
|
2310
|
+
/** 🖲️
|
|
2311
|
+
* Define this function to respond to key press events immediately.
|
|
2312
|
+
*
|
|
2313
|
+
* There can be a delay of up to one frame between a key press event
|
|
2314
|
+
* and the next time the `draw` function is run.
|
|
2315
|
+
*
|
|
2316
|
+
* Useful for playing sounds.
|
|
2317
|
+
* @example
|
|
2318
|
+
createCanvas(200, 100);
|
|
2319
|
+
|
|
2320
|
+
let gray = 100;
|
|
2321
|
+
function keyPressed() {
|
|
2322
|
+
background(gray);
|
|
2323
|
+
gray += 10;
|
|
2324
|
+
}
|
|
2325
|
+
*/
|
|
2326
|
+
function keyPressed(): void;
|
|
2327
|
+
|
|
2268
2328
|
/** 🖲️
|
|
2269
2329
|
* Array of current touches, each touch being an object with
|
|
2270
2330
|
* id, x, and y properties.
|
|
@@ -2276,19 +2336,53 @@ function draw() {
|
|
|
2276
2336
|
* If an image is provided, optional x and y coordinates can
|
|
2277
2337
|
* specify the active point of the cursor.
|
|
2278
2338
|
* @param {string} name name of the cursor or the url to an image
|
|
2279
|
-
* @param {number} [x] x-coordinate of the cursor's
|
|
2280
|
-
* @param {number} [y] y-coordinate of the cursor's
|
|
2339
|
+
* @param {number} [x] x-coordinate of the cursor's point
|
|
2340
|
+
* @param {number} [y] y-coordinate of the cursor's point
|
|
2341
|
+
* @example
|
|
2342
|
+
createCanvas(200, 100);
|
|
2343
|
+
cursor('pointer');
|
|
2281
2344
|
*/
|
|
2282
2345
|
function cursor(name: string, x?: number, y?: number): void;
|
|
2283
2346
|
|
|
2284
2347
|
/** 🖲️
|
|
2285
2348
|
* Hides the cursor within the bounds of the canvas.
|
|
2286
2349
|
* @example
|
|
2287
|
-
createCanvas(200);
|
|
2350
|
+
createCanvas(200, 100);
|
|
2288
2351
|
noCursor();
|
|
2289
2352
|
*/
|
|
2290
2353
|
function noCursor(): void;
|
|
2291
2354
|
|
|
2355
|
+
/** 🖲️
|
|
2356
|
+
* Prevents mouse wheel events from propagating and causing
|
|
2357
|
+
* the page to scroll when the mouse is inside the canvas.
|
|
2358
|
+
*
|
|
2359
|
+
* Useful for games and interactive art that fill the screen.
|
|
2360
|
+
* @example
|
|
2361
|
+
createCanvas(200, 100);
|
|
2362
|
+
noScroll();
|
|
2363
|
+
*/
|
|
2364
|
+
function noScroll(): void;
|
|
2365
|
+
|
|
2366
|
+
/** 🖲️
|
|
2367
|
+
* Define this function to respond to mouse wheel events.
|
|
2368
|
+
*
|
|
2369
|
+
* `event.deltaX` and `event.deltaY` are the horizontal and vertical
|
|
2370
|
+
* scroll amounts, respectively.
|
|
2371
|
+
*
|
|
2372
|
+
* Return false to prevent the default behavior of scrolling the page.
|
|
2373
|
+
* @example
|
|
2374
|
+
let x = y = 100;
|
|
2375
|
+
function draw() {
|
|
2376
|
+
circle(x, y, 10);
|
|
2377
|
+
}
|
|
2378
|
+
function mouseWheel(e) {
|
|
2379
|
+
x += e.deltaX;
|
|
2380
|
+
y += e.deltaY;
|
|
2381
|
+
return false;
|
|
2382
|
+
}
|
|
2383
|
+
*/
|
|
2384
|
+
function mouseWheel(event: any): void;
|
|
2385
|
+
|
|
2292
2386
|
/** 🖲️
|
|
2293
2387
|
* Requests that the pointer be locked to the document body, hiding the cursor and allowing for unlimited movement.
|
|
2294
2388
|
*/
|
|
@@ -2325,11 +2419,11 @@ function draw() {
|
|
|
2325
2419
|
* @param {number} [margin] distance to extend (positive) or contract (negative) the range from canvas edges
|
|
2326
2420
|
* @returns {number} random x value
|
|
2327
2421
|
* @example
|
|
2328
|
-
createCanvas(200);
|
|
2422
|
+
createCanvas(200, 100);
|
|
2329
2423
|
background(200);
|
|
2330
2424
|
|
|
2331
2425
|
function draw() {
|
|
2332
|
-
circle(randomX(),
|
|
2426
|
+
circle(randomX(), 50, random(50));
|
|
2333
2427
|
}
|
|
2334
2428
|
*/
|
|
2335
2429
|
function randomX(margin?: number): number;
|
|
@@ -2344,6 +2438,13 @@ background(200);
|
|
|
2344
2438
|
|
|
2345
2439
|
function draw() {
|
|
2346
2440
|
circle(100, randomY(), random(50));
|
|
2441
|
+
}
|
|
2442
|
+
* @example
|
|
2443
|
+
createCanvas(200);
|
|
2444
|
+
background(200);
|
|
2445
|
+
|
|
2446
|
+
function draw() {
|
|
2447
|
+
circle(randomX(), randomY(-60), 10);
|
|
2347
2448
|
}
|
|
2348
2449
|
*/
|
|
2349
2450
|
function randomY(margin?: number): number;
|
|
@@ -2357,6 +2458,15 @@ function draw() {
|
|
|
2357
2458
|
* @param {number} x2 x-coordinate of the second point
|
|
2358
2459
|
* @param {number} y2 y-coordinate of the second point
|
|
2359
2460
|
* @returns {number} distance between the points
|
|
2461
|
+
* @example
|
|
2462
|
+
function draw() {
|
|
2463
|
+
background(200);
|
|
2464
|
+
circle(100, 100, 20);
|
|
2465
|
+
circle(mouseX, mouseY, 20);
|
|
2466
|
+
|
|
2467
|
+
let d = dist(100, 100, mouseX, mouseY);
|
|
2468
|
+
text(round(d), 20, 20);
|
|
2469
|
+
}
|
|
2360
2470
|
*/
|
|
2361
2471
|
function dist(x1: number, y1: number, x2: number, y2: number): number;
|
|
2362
2472
|
|
|
@@ -2473,6 +2583,12 @@ function draw() {
|
|
|
2473
2583
|
* @param {number} [y] y-coordinate input
|
|
2474
2584
|
* @param {number} [z] z-coordinate input
|
|
2475
2585
|
* @returns {number} a noise value
|
|
2586
|
+
* @example
|
|
2587
|
+
function draw() {
|
|
2588
|
+
background(200);
|
|
2589
|
+
let n = noise(frameCount * 0.01);
|
|
2590
|
+
square(n * 200, n * 200, 10);
|
|
2591
|
+
}
|
|
2476
2592
|
*/
|
|
2477
2593
|
function noise(x?: number, y?: number, z?: number): number;
|
|
2478
2594
|
|
|
@@ -2511,28 +2627,27 @@ function draw() {
|
|
|
2511
2627
|
|
|
2512
2628
|
/** 🎞️
|
|
2513
2629
|
* q5.js has a built-in canvas recorder powered by
|
|
2514
|
-
* [`MediaRecorder`](https://developer.mozilla.org/docs/Web/API/MediaRecorder/MediaRecorder). It
|
|
2630
|
+
* [`MediaRecorder`](https://developer.mozilla.org/docs/Web/API/MediaRecorder/MediaRecorder). It provides a good balance between
|
|
2631
|
+
* video encoding speed, quality, and file size.
|
|
2515
2632
|
*
|
|
2516
2633
|
* Recording large canvases is an intensive process, so your
|
|
2517
2634
|
* computer may not be able to do it in real time. That's okay,
|
|
2518
2635
|
* the resulting video will playback at your sketch's target
|
|
2519
|
-
* frame rate.
|
|
2520
|
-
*
|
|
2521
|
-
* If real time interaction while recording is a priority,
|
|
2522
|
-
* consider reducing the canvas' size, frame rate, and/or
|
|
2636
|
+
* frame rate. But if real time interaction while recording is a
|
|
2637
|
+
* priority, consider reducing the canvas' size, frame rate, and/or
|
|
2523
2638
|
* recording quality.
|
|
2524
2639
|
*
|
|
2525
2640
|
* HDR video encoding is not yet supported by any web browser.
|
|
2526
|
-
* For that and other advanced
|
|
2641
|
+
* For that and other advanced features, consider using
|
|
2527
2642
|
* a screen capture tool like [OBS Studio](https://obsproject.com).
|
|
2528
2643
|
*/
|
|
2529
2644
|
|
|
2530
2645
|
/** 🎞️
|
|
2531
2646
|
* Creates a recorder. Simply hit record to start recording!
|
|
2532
2647
|
*
|
|
2533
|
-
* `
|
|
2534
|
-
*
|
|
2535
|
-
*
|
|
2648
|
+
* `quality` is set to "high" by default.
|
|
2649
|
+
*
|
|
2650
|
+
* `format` is set automatically based on the height of the canvas.
|
|
2536
2651
|
*
|
|
2537
2652
|
* @returns {HTMLElement} a recorder, q5 DOM element
|
|
2538
2653
|
* @example
|
|
@@ -2541,7 +2656,7 @@ createCanvas(200);
|
|
|
2541
2656
|
createRecorder();
|
|
2542
2657
|
|
|
2543
2658
|
function draw() {
|
|
2544
|
-
circle(mouseX,
|
|
2659
|
+
circle(mouseX, randomY(), 10);
|
|
2545
2660
|
}
|
|
2546
2661
|
*/
|
|
2547
2662
|
function createRecorder(): HTMLElement;
|
|
@@ -2568,7 +2683,7 @@ function draw() {
|
|
|
2568
2683
|
* @param {string} fileName
|
|
2569
2684
|
* @example
|
|
2570
2685
|
function draw() {
|
|
2571
|
-
square(mouseX,
|
|
2686
|
+
square(mouseX, randomY(), 10);
|
|
2572
2687
|
}
|
|
2573
2688
|
|
|
2574
2689
|
function mousePressed() {
|
|
@@ -2763,6 +2878,36 @@ q.mousePressed = () => {
|
|
|
2763
2878
|
*/
|
|
2764
2879
|
function load(...urls: string[]): Promise<any[]>;
|
|
2765
2880
|
|
|
2881
|
+
/** 🛠️
|
|
2882
|
+
* Saves data to a file.
|
|
2883
|
+
*
|
|
2884
|
+
* If data is not specified, the canvas will be saved.
|
|
2885
|
+
*
|
|
2886
|
+
* If no arguments are provided, the canvas will be saved as
|
|
2887
|
+
* an image file named "untitled.png".
|
|
2888
|
+
* @param {object} [data] canvas, image, or JS object
|
|
2889
|
+
* @param {string} [fileName] filename to save as
|
|
2890
|
+
* @example
|
|
2891
|
+
createCanvas(200);
|
|
2892
|
+
background(200);
|
|
2893
|
+
circle(100, 100, 50);
|
|
2894
|
+
|
|
2895
|
+
function mousePressed() {
|
|
2896
|
+
save('circle.png');
|
|
2897
|
+
}
|
|
2898
|
+
* @example
|
|
2899
|
+
createCanvas(200);
|
|
2900
|
+
|
|
2901
|
+
textSize(180);
|
|
2902
|
+
let bolt = createTextImage('⚡️');
|
|
2903
|
+
image(bolt, 16, -56);
|
|
2904
|
+
|
|
2905
|
+
function mousePressed() {
|
|
2906
|
+
save(bolt, 'bolt.png');
|
|
2907
|
+
}
|
|
2908
|
+
*/
|
|
2909
|
+
function save(data?: object, fileName?: string): void;
|
|
2910
|
+
|
|
2766
2911
|
/** 🛠️
|
|
2767
2912
|
* Loads a text file from the specified url. Result is one string.
|
|
2768
2913
|
* @param {string} url text file
|