q5 2.14.4 → 2.15.0

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 CHANGED
@@ -1,10 +1,20 @@
1
- # <img src="q5js_logo.webp" height="64"> <img src="q5js_brand.webp" height="64">
1
+ # <img src="https://q5js.org/q5js_logo.webp" height="64"> <img src="https://q5js.org/q5js_brand.webp" height="64">
2
2
 
3
- [**q5.js**](https://q5js.org) is a spiritual successor to the [p5.js][] and [Processing Java][] graphics libraries.
3
+ ## Visit [q5js.org](https://q5js.org)! 🌟
4
4
 
5
- q5 was designed to make creative coding even more fun and accessible for a new generation of artists, educators, and beginners!
5
+ [q5.js](https://q5js.org) is a spiritual successor to the [p5.js][] and [Processing Java][] graphics libraries.
6
6
 
7
- If you're already familiar with p5, you'll find yourself right at home with q5. It's also compatible with popular addons, including [p5.sound][] and [p5play][].
7
+ - performance optimized for interactive art 🚀
8
+ - includes a brand new renderer powered by WebGPU 💪
9
+ - up to 32x faster than p5.js 🏎️
10
+ - HDR color support 🌈
11
+ - compatible with popular addons, including [p5.sound][] and [p5play][] 🎮
12
+ - no dependencies, less than 100kb minified 📦
13
+ - LGPL licensed (just like p5.js) 🆓
14
+
15
+ q5.js was designed to make creative coding fun and accessible for a new generation of artists, designers, educators, and beginners. 🤝
16
+
17
+ If you're already familiar with p5, you'll find yourself right at home with q5. 🏡
8
18
 
9
19
  ```js
10
20
  function setup() {
@@ -13,40 +23,11 @@ function setup() {
13
23
  }
14
24
  ```
15
25
 
16
- ## No Installation Required
17
-
18
- Try out the [q5.js template sketch](https://aijs.io/editor?user=quinton-ashley&project=logoSpin) for the Aijs online code editor.
19
-
20
- Use q5.js in your own project by adding this line to your HTML file:
21
-
22
- ```html
23
- <script src="https://q5js.org/q5.js"></script>
24
- ```
25
-
26
- q5 is also available on [npm](https://www.npmjs.com/package/q5)!
27
-
28
- ```bash
29
- npm install q5
30
- ```
31
-
32
- ## Using p5 Addon Libraries
33
-
34
- q5 is compatible with popular p5 addons and projects that use p5, such as [p5play][], because it aliases `Q5` to `p5`.
35
-
36
- To use addons, simply load them after q5.js:
37
-
38
- ```html
39
- <script src="https://q5js.org/q5.js"></script>
40
- <!-- load p5 addons after q5 -->
41
- <script src="https://p5play.org/v3/planck.min.js"></script>
42
- <script src="https://p5play.org/v3/p5play.js"></script>
43
- ```
44
-
45
26
  ## Documentation
46
27
 
47
28
  Browse the [q5 reference pages](https://q5js.org/learn) to learn how to use q5.js.
48
29
 
49
- See the [wiki](https://github.com/q5js/q5.js/wiki) for extended documentation of q5's exclusive features.
30
+ See the [wiki](https://github.com/q5js/q5.js/wiki) for extended documentation.
50
31
 
51
32
  Use the [q5.d.ts](q5.d.ts) file in Visual Studio Code to get autocompletion and inline hover-over documentation. Simply add this `jsconfig.json` file to your project folder:
52
33
 
@@ -59,27 +40,21 @@ Use the [q5.d.ts](q5.d.ts) file in Visual Studio Code to get autocompletion and
59
40
  }
60
41
  ```
61
42
 
62
- ## Support this project 🤝
43
+ ## Support q5 💙
63
44
 
64
45
  q5 is open source and anyone can use it for free under the terms of the LGPL (just like p5.js). 🎉
65
46
 
66
47
  We need your support though! If you enjoy using q5.js, please donate via [GitHub Sponsors](https://github.com/sponsors/quinton-ashley) or [Patreon](https://www.patreon.com/p5play).
67
48
 
68
- ## Modular Use
69
-
70
- q5 has no dependencies and the default bundle is just 126kb unminified.
71
-
72
- But for extremely lightweight use, you can load a subset of scripts from the `src` folder. See the [src/readme.md](src/readme.md) for more info on modular use.
73
-
74
49
  ## Contributing
75
50
 
76
- Please report issues or comment on existing issues before working on a pull request.
51
+ Are you interested in volunteering to write code for q5.js or improve the q5 ecosystem? Contributions are welcome!
77
52
 
78
- Check out the [q5 planning board](https://github.com/orgs/q5js/projects/1/views/1).
53
+ Please report issues or comment on existing issues before working on a pull request. Check out the [q5 planning board](https://github.com/orgs/q5js/projects/1/views/1).
79
54
 
80
- If the q5 project is successful, all contributing developers will be paid for their work. The project will be run as a [worker co-op](https://en.wikipedia.org/wiki/Worker_cooperative).
55
+ All contributors must agree to the [code of conduct](CODE_OF_CONDUCT.md).
81
56
 
82
- Contributors must agree to the [code of conduct](CODE_OF_CONDUCT.md).
57
+ If the q5 project becomes as successful as The Processing Foundation, all contributing developers will be fairly paid for their work. The project will be run as a [worker co-op](https://en.wikipedia.org/wiki/Worker_cooperative).
83
58
 
84
59
  ## Licensing
85
60
 
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "2.12.0",
3
+ "version": "2.15.0",
4
4
  "license": "LGPL-3.0",
5
5
  "description": "A sequel to p5.js that's optimized for interactive art",
6
6
  "author": "quinton-ashley",
@@ -19,6 +19,7 @@
19
19
  ".vscode",
20
20
  "assets",
21
21
  "dev",
22
+ "src",
22
23
  "fonts",
23
24
  "home",
24
25
  "lang",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.14.4",
3
+ "version": "2.15.0",
4
4
  "description": "A sequel to p5.js that's optimized for interactive art",
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-canvas.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 src/q5-webgpu-canvas.js src/q5-webgpu-drawing.js src/q5-webgpu-image.js src/q5-webgpu-text.js > q5.js",
14
+ "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-c2d-canvas.js src/q5-c2d-drawing.js src/q5-c2d-image.js src/q5-c2d-soft-filters.js src/q5-c2d-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 src/q5-webgpu-canvas.js src/q5-webgpu-drawing.js src/q5-webgpu-image.js src/q5-webgpu-text.js > q5.js",
15
15
  "min": "terser q5.js --compress ecma=2024 --mangle > q5.min.js",
16
16
  "dist": "bun bundle && bun min",
17
17
  "dist-p5play": "bun dist && cp q5.js ../../web/p5play-web/v3/q5.js && cp q5.min.js ../../web/p5play-web/v3/q5.min.js",
package/q5.d.ts CHANGED
@@ -243,7 +243,7 @@ function draw() {
243
243
  * anywhere in your code. You can also start Q5 in global mode by
244
244
  * running [`createCanvas`](https://q5js.org/learn/#canvas-createCanvas).
245
245
  *
246
- * By default q5 uses the CanvasRenderingContext2D based q2d renderer.
246
+ * By default q5 uses the CanvasRenderingContext2D based c2d renderer.
247
247
  *
248
248
  * To use the q5 WebGPU renderer, run `Q5.webgpu()` after the creation of file level variables. For more information read the [q5-webgpu modules documentation](https://github.com/q5js/q5.js/blob/main/src/readme.md#webgpu-canvas).
249
249
  * @param {string | Function} [scope]
@@ -1389,7 +1389,7 @@ text(info, 12, 30, 20, 6);
1389
1389
  * Loads a font from a URL and optionally runs a callback function
1390
1390
  * with the font name once it's loaded.
1391
1391
  *
1392
- * In q5 q2d, you can load fonts in any format accepted in CSS, such as
1392
+ * In q5 c2d, you can load fonts in any format accepted in CSS, such as
1393
1393
  * .ttf and .otf files.
1394
1394
  *
1395
1395
  * The example below loads "Robotica.ttf" created by Courtney Novits:
@@ -1422,7 +1422,7 @@ function setup() {
1422
1422
  * By default, the font is set to "sans-serif" or the last font
1423
1423
  * loaded.
1424
1424
  *
1425
- * In q5 q2d, you can set the font to any font accepted in CSS,
1425
+ * In q5 c2d, you can set the font to any font accepted in CSS,
1426
1426
  * such as "serif" or "monospace".
1427
1427
  * https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
1428
1428
  * @param {string} fontName name of the font or font family
@@ -1664,7 +1664,7 @@ function draw() {
1664
1664
  /** 🎨
1665
1665
  * Sets the color mode for the sketch. Changes the type of color object created by color functions.
1666
1666
  *
1667
- * In q2d, the default color mode is RGB in legacy integer format.
1667
+ * In c2d, the default color mode is RGB in legacy integer format.
1668
1668
  *
1669
1669
  * In WebGPU, the default color mode is RGB in float format.
1670
1670
  *
package/q5.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * q5.js
3
- * @version 2.14
3
+ * @version 2.15
4
4
  * @author quinton-ashley, Tezumie, and LingDong-
5
5
  * @license LGPL-3.0
6
6
  * @class Q5
@@ -11,7 +11,7 @@ function Q5(scope, parent, renderer) {
11
11
  $._parent = parent;
12
12
  if (renderer == 'webgpu-fallback') {
13
13
  $._webgpuFallback = true;
14
- $._renderer = 'q2d';
14
+ $._renderer = 'c2d';
15
15
  } else {
16
16
  $._renderer = renderer || Q5.render;
17
17
  }
@@ -275,7 +275,7 @@ function Q5(scope, parent, renderer) {
275
275
  else setTimeout(_start, 32);
276
276
  }
277
277
 
278
- Q5.render = 'q2d';
278
+ Q5.render = 'c2d';
279
279
 
280
280
  Q5.renderers = {};
281
281
  Q5.modules = {};
@@ -310,7 +310,7 @@ function createCanvas(w, h, opt) {
310
310
  }
311
311
  }
312
312
 
313
- Q5.version = Q5.VERSION = '2.14';
313
+ Q5.version = Q5.VERSION = '2.15';
314
314
 
315
315
  if (typeof document == 'object') {
316
316
  document.addEventListener('DOMContentLoaded', () => {
@@ -684,9 +684,9 @@ Q5.canvasOptions = {
684
684
  if (!window.matchMedia || !matchMedia('(dynamic-range: high) and (color-gamut: p3)').matches) {
685
685
  Q5.canvasOptions.colorSpace = 'srgb';
686
686
  } else Q5.supportsHDR = true;
687
- Q5.renderers.q2d = {};
687
+ Q5.renderers.c2d = {};
688
688
 
689
- Q5.renderers.q2d.canvas = ($, q) => {
689
+ Q5.renderers.c2d.canvas = ($, q) => {
690
690
  let c = $.canvas;
691
691
 
692
692
  if ($.colorMode) {
@@ -886,7 +886,7 @@ Q5.renderers.q2d.canvas = ($, q) => {
886
886
  return vid;
887
887
  };
888
888
  };
889
- Q5.renderers.q2d.drawing = ($) => {
889
+ Q5.renderers.c2d.drawing = ($) => {
890
890
  $._doStroke = true;
891
891
  $._doFill = true;
892
892
  $._strokeSet = false;
@@ -1285,7 +1285,7 @@ Q5.renderers.q2d.drawing = ($) => {
1285
1285
  return $.ctx.isPointInStroke(x * pd, y * pd);
1286
1286
  };
1287
1287
  };
1288
- Q5.renderers.q2d.image = ($, q) => {
1288
+ Q5.renderers.c2d.image = ($, q) => {
1289
1289
  class Q5Image {
1290
1290
  constructor(w, h, opt) {
1291
1291
  let $ = this;
@@ -1293,7 +1293,7 @@ Q5.renderers.q2d.image = ($, q) => {
1293
1293
  $.canvas = $.ctx = $.drawingContext = null;
1294
1294
  $.pixels = [];
1295
1295
  Q5.modules.canvas($, $);
1296
- let r = Q5.renderers.q2d;
1296
+ let r = Q5.renderers.c2d;
1297
1297
  for (let m of ['canvas', 'image', 'soft_filters']) {
1298
1298
  if (r[m]) r[m]($, $);
1299
1299
  }
@@ -1616,7 +1616,7 @@ Q5.renderers.q2d.image = ($, q) => {
1616
1616
  $.noTint = () => ($._tint = null);
1617
1617
  };
1618
1618
  /* software implementation of image filters */
1619
- Q5.renderers.q2d.soft_filters = ($) => {
1619
+ Q5.renderers.c2d.soft_filters = ($) => {
1620
1620
  let u = null; // uint8 temporary buffer
1621
1621
 
1622
1622
  function ensureBuf() {
@@ -1760,7 +1760,7 @@ Q5.renderers.q2d.soft_filters = ($) => {
1760
1760
  $.ctx.putImageData(imgData, 0, 0);
1761
1761
  };
1762
1762
  };
1763
- Q5.renderers.q2d.text = ($, q) => {
1763
+ Q5.renderers.c2d.text = ($, q) => {
1764
1764
  $._textAlign = 'left';
1765
1765
  $._textBaseline = 'alphabetic';
1766
1766
  $._textSize = 12;
@@ -2180,10 +2180,13 @@ Q5.modules.color = ($, q) => {
2180
2180
  } else if ($._namedColors[c0]) {
2181
2181
  [c0, c1, c2, c3] = $._namedColors[c0];
2182
2182
  } else {
2183
- console.error(
2184
- "q5 can't parse color: " + c0 + '\nOnly numeric input, hex, and common named colors are supported.'
2185
- );
2186
- return new C(0, 0, 0);
2183
+ // css color string not parsed
2184
+ let c = new C(0, 0, 0);
2185
+ c._css = c0;
2186
+ c.toString = function () {
2187
+ return this._css;
2188
+ };
2189
+ return c;
2187
2190
  }
2188
2191
 
2189
2192
  if ($._colorFormat == 1) {
@@ -3598,7 +3601,7 @@ Q5.renderers.webgpu.canvas = ($, q) => {
3598
3601
  c.width = $.width = 500;
3599
3602
  c.height = $.height = 500;
3600
3603
 
3601
- // q2d graphics context
3604
+ // c2d graphics context
3602
3605
  $._g = $.createGraphics(1, 1);
3603
3606
 
3604
3607
  if ($.colorMode) $.colorMode('rgb', 1);
@@ -3919,6 +3922,12 @@ Q5.renderers.webgpu.canvas = ($, q) => {
3919
3922
  $._matrixDirty = false;
3920
3923
  };
3921
3924
 
3925
+ let _pushStyles = $.pushStyles;
3926
+ $.pushStyles = () => {
3927
+ _pushStyles();
3928
+ $.strokeWeight($._strokeWeight);
3929
+ };
3930
+
3922
3931
  $.push = () => {
3923
3932
  $.pushMatrix();
3924
3933
  $.pushStyles();
@@ -4746,26 +4755,19 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
4746
4755
  };
4747
4756
 
4748
4757
  $.background = (r, g, b, a) => {
4749
- let mi = $._matrixIndex;
4750
- $._matrixIndex = 0;
4751
- $._doStroke = false;
4758
+ $.push();
4759
+ $.resetMatrix();
4752
4760
  if (r.src) {
4753
4761
  let img = r;
4754
- let im = $._imageMode;
4755
4762
  $._imageMode = 'corner';
4756
4763
  $.image(img, -c.hw, -c.hh, c.w, c.h);
4757
- $._imageMode = im;
4758
4764
  } else {
4759
- let rm = $._rectMode;
4760
4765
  $._rectMode = 'corner';
4761
- let fill = $._fill;
4762
4766
  $.fill(r, g, b, a);
4767
+ $._doStroke = false;
4763
4768
  $.rect(-c.hw, -c.hh, c.w, c.h);
4764
- $._rectMode = rm;
4765
- $._fill = fill;
4766
4769
  }
4767
- $._doStroke = true;
4768
- $._matrixIndex = mi;
4770
+ $.pop();
4769
4771
  };
4770
4772
 
4771
4773
  $._hooks.preRender.push(() => {