q5 2.27.8 → 2.28.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.
Files changed (5) hide show
  1. package/deno.json +1 -1
  2. package/package.json +2 -2
  3. package/q5.d.ts +53 -12
  4. package/q5.js +521 -455
  5. package/q5.min.js +2 -2
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "2.27.6",
3
+ "version": "2.28.0",
4
4
  "license": "LGPL-3.0",
5
5
  "description": "Beginner friendly graphics powered by WebGPU and optimized for interactive art!",
6
6
  "author": "quinton-ashley",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.27.8",
3
+ "version": "2.28.0",
4
4
  "description": "Beginner friendly graphics powered by WebGPU and optimized for interactive art!",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
@@ -12,7 +12,7 @@
12
12
  "main": "q5-server.js",
13
13
  "types": "q5.d.ts",
14
14
  "scripts": {
15
- "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-c2d-canvas.js src/q5-c2d-shapes.js src/q5-c2d-image.js src/q5-c2d-soft-filters.js src/q5-c2d-text.js src/q5-color.js src/q5-display.js src/q5-dom.js src/q5-fes.js src/q5-input.js src/q5-math.js src/q5-record.js src/q5-sound.js src/q5-util.js src/q5-vector.js src/q5-webgpu-canvas.js src/q5-webgpu-shapes.js src/q5-webgpu-image.js src/q5-webgpu-text.js src/q5-webgpu-shaders.js > q5.js",
15
+ "bundle": "cat src/q5-core.js src/q5-canvas.js src/q5-c2d-canvas.js src/q5-c2d-shapes.js src/q5-c2d-image.js src/q5-c2d-soft-filters.js src/q5-c2d-text.js src/q5-color.js src/q5-display.js src/q5-dom.js src/q5-fes.js src/q5-input.js src/q5-math.js src/q5-record.js src/q5-sound.js src/q5-util.js src/q5-vector.js src/q5-webgpu.js > q5.js",
16
16
  "min": "terser q5.js --compress ecma=2025 --mangle > q5.min.js",
17
17
  "dist": "bun bundle && bun min",
18
18
  "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
@@ -368,6 +368,29 @@ q.draw = () => {
368
368
  */
369
369
  static WebGPU(): Q5;
370
370
 
371
+ /** ⭐️
372
+ * ___Experimental! Might be changed.___
373
+ *
374
+ * Registers an addon with q5.js.
375
+ *
376
+ * Addons can augment q5 with new functionality and register
377
+ * functions to be executed at specific points in the q5 lifecycle:
378
+ * init, presetup, postsetup, predraw, postdraw, and remove.
379
+ *
380
+ * @param {Function} addon A function that receives `Q5`, `Q5.prototype`, and a `lifecycles` object.
381
+ * @example
382
+ // addon.js
383
+ Q5.registerAddon((Q5, proto, lifecycles) => {
384
+ lifecycles.postsetup = function () {
385
+ this.background('blue');
386
+ };
387
+ });
388
+
389
+ // sketch.js
390
+ createCanvas(200);
391
+ */
392
+ static registerAddon(addon: Function): void; //-
393
+
371
394
  /** ⭐️
372
395
  * The draw function is run 60 times per second by default.
373
396
  */
@@ -2184,7 +2207,7 @@ text('Hello, world!', 100, 100);
2184
2207
  */
2185
2208
  function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'middle' | 'bottom' | 'alphabetic'): void;
2186
2209
 
2187
- /**
2210
+ /** ✍️
2188
2211
  * Sets the text weight.
2189
2212
  *
2190
2213
  * - 100: thin
@@ -2741,9 +2764,7 @@ function draw() {
2741
2764
  */
2742
2765
  function random(low?: number | any[], high?: number): number | any;
2743
2766
 
2744
- /**
2745
- * ___Experimental! May be renamed or removed in the future.___
2746
- *
2767
+ /** 🧮
2747
2768
  * Generates a random number within a symmetric range around zero.
2748
2769
  *
2749
2770
  * Can be used to create a jitter effect (random displacement).
@@ -3129,7 +3150,7 @@ function mousePressed() {
3129
3150
  */
3130
3151
  function loadSound(url: string): Sound | Promise<Sound>;
3131
3152
 
3132
- /**
3153
+ /** 🔊
3133
3154
  * Loads audio data from a file and returns an [HTMLAudioElement](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement).
3134
3155
  *
3135
3156
  * Audio is considered loaded when the [canplaythrough event](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplaythrough_event) is fired.
@@ -4070,8 +4091,7 @@ plane(0, 0, 100);
4070
4091
  function shader(shaderModule: GPUShaderModule): void;
4071
4092
 
4072
4093
  /** ⚡️
4073
- * Makes q5 use a default shader.
4074
- * @param {string} [type] can be "shapes" (default), "image", "video", or "text"
4094
+ * Make q5 use the default shapes shader.
4075
4095
  * @example
4076
4096
  let q = await Q5.WebGPU();
4077
4097
 
@@ -4090,10 +4110,30 @@ q.draw = () => {
4090
4110
  triangle(-50, -50, 0, 50, 50, -50);
4091
4111
  };
4092
4112
  */
4093
- function resetShader(type?: string): void;
4113
+ function resetShader(): void;
4094
4114
 
4095
4115
  /** ⚡️
4096
- * Makes q5 use default shaders.
4116
+ * Make q5 use the default frame shader.
4117
+ */
4118
+ function resetFrameShader(): void;
4119
+
4120
+ /** ⚡️
4121
+ * Make q5 use the default image shader.
4122
+ */
4123
+ function resetImageShader(): void;
4124
+
4125
+ /** ⚡️
4126
+ * Make q5 use the default video shader.
4127
+ */
4128
+ function resetVideoShader(): void;
4129
+
4130
+ /** ⚡️
4131
+ * Make q5 use the default text shader.
4132
+ */
4133
+ function resetTextShader(): void;
4134
+
4135
+ /** ⚡️
4136
+ * Make q5 use all default shaders.
4097
4137
  */
4098
4138
  function resetShaders(): void;
4099
4139
 
@@ -4174,7 +4214,8 @@ let flipper = createVideoShader(`
4174
4214
  fn vertexMain(v: VertexParams) -> FragParams {
4175
4215
  var vert = transformVertex(v.pos, v.matrixIndex);
4176
4216
 
4177
- vert.y *= cos((q.frameCount + f32(v.vertexIndex) * 10) * 0.03);
4217
+ var vi = f32(v.vertexIndex);
4218
+ vert.y *= cos((q.frameCount + vi * 10) * 0.03);
4178
4219
 
4179
4220
  var f: FragParams;
4180
4221
  f.position = vert;
@@ -4184,7 +4225,8 @@ fn vertexMain(v: VertexParams) -> FragParams {
4184
4225
 
4185
4226
  @fragment
4186
4227
  fn fragMain(f: FragParams) -> @location(0) vec4f {
4187
- var texColor = textureSampleBaseClampToEdge(tex, samp, f.texCoord);
4228
+ var texColor =
4229
+ textureSampleBaseClampToEdge(tex, samp, f.texCoord);
4188
4230
  texColor.r = 0;
4189
4231
  texColor.b *= 2;
4190
4232
  return texColor;
@@ -4196,7 +4238,6 @@ q.draw = () => {
4196
4238
  shader(flipper);
4197
4239
  image(vid, -100, 150, 200, 150);
4198
4240
  };
4199
- //
4200
4241
  */
4201
4242
  function createVideoShader(code: string): GPUShaderModule;
4202
4243