q5 1.9.46 → 1.9.67
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/README.md +51 -15
- package/package.json +2 -2
- package/q5.js +2307 -2082
- package/q5.min.js +4 -3
- package/src/q5-2d-canvas.js +63 -33
- package/src/q5-2d-drawing.js +111 -102
- package/src/q5-2d-image.js +122 -293
- package/src/q5-2d-soft-filters.js +176 -0
- package/src/q5-2d-text.js +4 -4
- package/src/q5-ai.js +3 -3
- package/src/q5-color.js +5 -5
- package/src/q5-core.js +50 -49
- package/src/q5-display.js +7 -5
- package/src/q5-dom.js +2 -6
- package/src/q5-input.js +32 -25
- package/src/q5-math.js +53 -136
- package/src/q5-noisier.js +264 -0
- package/src/q5-sensors.js +1 -0
- package/src/q5-sound.js +15 -8
- package/src/q5-util.js +3 -3
- package/src/readme.md +93 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The sequel to p5.js is here!
|
|
|
4
4
|
|
|
5
5
|
**q5.js** implements all of [p5][]'s 2D drawing, math, and user input functionality.
|
|
6
6
|
|
|
7
|
-
It's a drop-in replacement that's performance optimized and ~
|
|
7
|
+
It's a drop-in replacement that's performance optimized and ~70x smaller than p5, while packing exclusive new features: HDR color support, modular use, top-level global mode, namespace mode, and text image caching.
|
|
8
8
|
|
|
9
9
|
## Typical Use
|
|
10
10
|
|
|
@@ -59,6 +59,8 @@ p5's error messages are friendlier but often too vague, leaving beginners search
|
|
|
59
59
|
🌸 p5.js says: [test.js, line 19] text() was expecting at least 3 arguments, but received only 1.
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
Why not ask ChatGPT 4o? It excels at identifying the most common errors that beginners make: typos, missing syntax, incorrect arguments, and more.
|
|
63
|
+
|
|
62
64
|
q5 creates error reports that can be sent to an AI just by clicking a link! Users can also run the `askAI()` function before a line of code that isn't working as expected. 🤖
|
|
63
65
|
|
|
64
66
|
```js
|
|
@@ -83,7 +85,7 @@ In **p5**, functions like `rect` can't be used on the file level. They must be c
|
|
|
83
85
|
In **q5**, existing p5 2D sketches don't require any modification. But if you initialize Q5 at the top of your sketch, the `preload` and `setup` functions become optional.
|
|
84
86
|
|
|
85
87
|
```js
|
|
86
|
-
Q5();
|
|
88
|
+
new Q5();
|
|
87
89
|
|
|
88
90
|
noStroke();
|
|
89
91
|
let c = color(0, 126, 255, 102);
|
|
@@ -94,7 +96,7 @@ rect(15, 15, 35, 70);
|
|
|
94
96
|
This is great because you don't have to declare variables on the file level and then define them in `preload` or `setup`. You can declare and define them at the same time!
|
|
95
97
|
|
|
96
98
|
```js
|
|
97
|
-
Q5();
|
|
99
|
+
new Q5();
|
|
98
100
|
|
|
99
101
|
let cow = loadImage('cow.png');
|
|
100
102
|
|
|
@@ -192,6 +194,46 @@ with (q) {
|
|
|
192
194
|
}
|
|
193
195
|
```
|
|
194
196
|
|
|
197
|
+
## Dimension Agnostic
|
|
198
|
+
|
|
199
|
+
In **p5** the only way to do dimension agnostic sketches is to set variables to percentages of the canvas' width and height but this is cumbersome and makes code look messy.
|
|
200
|
+
|
|
201
|
+
In **q5**, @Tezumie added a new feature called `flexibleCanvas`. It takes a unit as input, then any position coordinates or dimensions you use will be scaled based on that unit.
|
|
202
|
+
|
|
203
|
+
In this example, the rect will appear in the middle of the canvas, regardless of its size.
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
new Q5();
|
|
207
|
+
createCanvas(1000, 1000);
|
|
208
|
+
|
|
209
|
+
flexibleCanvas(400);
|
|
210
|
+
rect(100, 100, 200, 200);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Frame your Art
|
|
214
|
+
|
|
215
|
+
The `displayMode` function lets you customize how your canvas is presented.
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
displayMode(mode, renderQuality, displayScale);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Display modes:
|
|
222
|
+
|
|
223
|
+
"normal": no styling to canvas or its parent element
|
|
224
|
+
"centered": canvas will be centered horizontally and vertically within its parent and if it's display size is bigger than its parent it will not clip
|
|
225
|
+
"maxed": canvas will fill the parent element, same as fullscreen for a global mode canvas inside a `main` element
|
|
226
|
+
"fullscreen": canvas will fill the screen with letterboxing to persevere its aspect ratio, like css object-fit contain
|
|
227
|
+
|
|
228
|
+
Render qualities:
|
|
229
|
+
|
|
230
|
+
"default": pixelDensity set to displayDensity
|
|
231
|
+
"pixelated": pixelDensity set to 1 and various css styles are applied to the canvas to make it render without image smoothing
|
|
232
|
+
|
|
233
|
+
displayScale:
|
|
234
|
+
|
|
235
|
+
Can be given as a string "x2" or a number. This can be used to make small canvases appear larger.
|
|
236
|
+
|
|
195
237
|
## Node.js Usage
|
|
196
238
|
|
|
197
239
|
> Node.js support was recently added, please [make an issue report][] if you encounter any problems.
|
|
@@ -212,7 +254,7 @@ In node.js, q5's automatic global mode is disabled. To use global mode you need
|
|
|
212
254
|
|
|
213
255
|
**p5.js** is nearly 5MB in size. This is mainly [due to the inclusion of the webgl render and the dependencies corejs and opentype](https://github.com/processing/p5.js/issues/6776#issuecomment-1918238317). If 2d rendering is all a sketch needs, p5 wastes user bandwidth and is slower to load, parse, and run.
|
|
214
256
|
|
|
215
|
-
**q5.js** (the default bundle) is
|
|
257
|
+
**q5.js** (the default bundle) is 70x smaller than p5, which is already great for typical use. For extremely lightweight use you can load a subset of scripts from the `src` folder, just be sure to load `src/q5-core.js` first.
|
|
216
258
|
|
|
217
259
|
## Motivation: Part 1
|
|
218
260
|
|
|
@@ -246,10 +288,6 @@ Thanks in large part to @LingDong-'s design, q5 is well organized, concise, and
|
|
|
246
288
|
|
|
247
289
|
## More exclusive features
|
|
248
290
|
|
|
249
|
-
Features added by @Tezumie:
|
|
250
|
-
|
|
251
|
-
- `point()`: more efficient point drawing.
|
|
252
|
-
|
|
253
291
|
Features added by @quinton-ashley:
|
|
254
292
|
|
|
255
293
|
- `image.trim()`: removes transparent pixels from the edges of an image.
|
|
@@ -273,15 +311,15 @@ Features added by @LingDong-:
|
|
|
273
311
|
|
|
274
312
|
Unminified:
|
|
275
313
|
|
|
276
|
-
- p5.js **
|
|
314
|
+
- p5.js **5112kb** ⚠️
|
|
277
315
|
- p5.sound.js 488kb
|
|
278
|
-
- q5.js
|
|
316
|
+
- q5.js 74kb
|
|
279
317
|
|
|
280
318
|
Minified:
|
|
281
319
|
|
|
282
|
-
- p5.min.js
|
|
320
|
+
- p5.min.js 1034kb ⚠️
|
|
283
321
|
- p5.sound.min.js 200kb
|
|
284
|
-
- q5.min.js **
|
|
322
|
+
- q5.min.js **48kb** 🎉
|
|
285
323
|
|
|
286
324
|
## Benchmarks
|
|
287
325
|
|
|
@@ -328,9 +366,7 @@ All contributors are required to check their ego at the door and be open to feed
|
|
|
328
366
|
|
|
329
367
|
Code is a language art that can be subjectively judged by its effectiveness at communicating its functionality to humans. Code can also be objectively measured by its performance. Since JavaScript is served over a network, size is a factor as well. Therefore, the q5 team strives to balance code readability with brevity and performance.
|
|
330
368
|
|
|
331
|
-
Check out the q5
|
|
332
|
-
|
|
333
|
-
https://github.com/users/quinton-ashley/projects/4/views/1
|
|
369
|
+
Check out the [q5 planning board](https://github.com/orgs/q5js/projects/1/views/1).
|
|
334
370
|
|
|
335
371
|
## Organization
|
|
336
372
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q5",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.67",
|
|
4
4
|
"description": "The sequel to p5.js that's smaller and faster",
|
|
5
5
|
"author": "quinton-ashley",
|
|
6
6
|
"contributors": [
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"homepage": "https://q5js.org/home",
|
|
12
12
|
"main": "q5-server.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"bundle": "cat src/q5-core.js src/q5-2d-canvas.js src/q5-2d-drawing.js src/q5-2d-image.js src/q5-2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-input.js src/q5-math.js src/q5-sound.js src/q5-util.js src/q5-vector.js > q5.js",
|
|
14
|
+
"bundle": "cat src/q5-core.js src/q5-2d-canvas.js src/q5-2d-drawing.js src/q5-2d-image.js src/q5-2d-soft-filters.js src/q5-2d-text.js src/q5-ai.js src/q5-color.js src/q5-display.js src/q5-input.js src/q5-math.js src/q5-sound.js src/q5-util.js src/q5-vector.js > q5.js",
|
|
15
15
|
"min": "terser q5.js --compress ecma=2024 --mangle > q5.min.js",
|
|
16
16
|
"dist": "bun bundle && cp q5.js ../../web/p5play-web/v3/q5.js && bun min && cp q5.min.js ../../web/p5play-web/v3/q5.min.js",
|
|
17
17
|
"v": "npm version patch --force",
|