q5 4.0.1 → 4.1.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
@@ -2,17 +2,13 @@
2
2
 
3
3
  ## Visit [q5js.org](https://q5js.org)! 💫
4
4
 
5
- - inspired by [p5.js][] and [Processing][] ⭐️
6
- - performance optimized for interactive art 🚀
7
- - lightning fast [WebGPU renderer](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer) ⚡️
5
+ q5 was designed to make creative coding fun and accessible for educators, artists, designers, and beginners. 🤝
6
+
7
+ - 100x faster than [p5.js][] ⚡️
8
8
  - beginner friendly [documentation](https://q5js.org/learn) 📚
9
9
  - compatible with popular addons, including [p5.sound][], [ml5.js][], and [p5play][] 🎮
10
10
  - no dependencies, ~140kb minified 📦
11
- - free to use under the LGPL 🆓
12
-
13
- q5 was designed to make creative coding fun and accessible for educators, artists, designers, and beginners. 🤝
14
-
15
- Familiar with p5? You'll be right at home with q5. It's like getting a free computer upgrade! 🖥️
11
+ - free and open source 🆓
16
12
 
17
13
  ```js
18
14
  await Canvas(200);
@@ -21,7 +17,7 @@ circle(0, 0, 80);
21
17
 
22
18
  ## Documentation
23
19
 
24
- Browse the [q5 reference pages](https://q5js.org/learn) to learn how to use q5.js.
20
+ The [q5 learn pages](https://q5js.org/learn) are organized into sections with interactive mini-examples.
25
21
 
26
22
  See the [wiki](https://github.com/q5js/q5.js/wiki) for extended documentation.
27
23
 
@@ -54,7 +50,7 @@ All contributors must agree to the [code of conduct](CODE_OF_CONDUCT.md).
54
50
 
55
51
  ## Licensing
56
52
 
57
- q5.js was created by [Quinton Ashley](https://github.com/quinton-ashley) and [contributors](https://github.com/q5js/q5.js/graphs/contributors). It is open source licensed under the LGPLv3.
53
+ q5.js was created by [Quinton Ashley](https://github.com/quinton-ashley) and [contributors](https://github.com/q5js/q5.js/graphs/contributors). It is free to use and open source licensed under the LGPLv3.
58
54
 
59
55
  @LingDong- created the original q5xjs library which is Unlicense (public domain) licensed.
60
56
 
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "Beginner friendly graphics powered by WebGPU, 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": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Beginner friendly graphics powered by WebGPU, optimized for interactive art!",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
package/q5.d.ts CHANGED
@@ -3070,7 +3070,7 @@ declare global {
3070
3070
  * @example
3071
3071
  * await Canvas(200, 100);
3072
3072
  *
3073
- * let img = createImg('/assets/p5play_logo.webp');
3073
+ * let img = createImg('/assets/q5play_logo.avif');
3074
3074
  * img.position(0, 0).size(100, 100);
3075
3075
  */
3076
3076
  function createImg(src: string): HTMLImageElement;
@@ -3874,22 +3874,22 @@ declare global {
3874
3874
  */
3875
3875
 
3876
3876
  /** ⚡
3877
- * Creates a shader that q5 can use to draw shapes.
3877
+ * Creates a shader that q5's WebGPU renderer can use.
3878
+ *
3879
+ * If `type` is not specified, this function customizes a copy of the [default shapes shader](https://github.com/q5js/q5.js/blob/main/src/shaders/shapes.wgsl), which affects the following functions:
3878
3880
  *
3879
- * Affects the following functions:
3880
3881
  * `triangle`, `quad`, `plane`,
3881
3882
  * `curve`, `bezier`, `beginShape`/`endShape`,
3882
3883
  * and `background` (unless an image is used).
3883
3884
  *
3884
- * Use this function to customize a copy of the
3885
- * [default shapes shader](https://github.com/q5js/q5.js/blob/main/src/shaders/shapes.wgsl).
3886
- *
3887
3885
  * For more information on the vertex and fragment function
3888
3886
  * input parameters, data, and helper functions made available for use
3889
3887
  * in your custom shader code, read the
3890
3888
  * ["Custom Shaders in q5 WebGPU"](https://github.com/q5js/q5.js/wiki/Custom-Shaders-in-q5-WebGPU)
3891
3889
  * wiki page.
3892
3890
  * @param {string} code WGSL shader code excerpt
3891
+ * @param {string} [type] defaults to "shapes"
3892
+ * @param {Float32Array} [data] only for use with [fully custom shaders](https://github.com/q5js/q5.js/wiki/Custom-Shaders-in-q5-WebGPU#fully-custom-shaders)
3893
3893
  * @returns {GPUShaderModule} a shader program
3894
3894
  * @example
3895
3895
  * await Canvas(200);
@@ -3928,7 +3928,7 @@ declare global {
3928
3928
  * triangle(-50, -50, 0, 50, 50, -50);
3929
3929
  * };
3930
3930
  */
3931
- function createShader(code: string): GPUShaderModule;
3931
+ function createShader(code: string, type?: string, data?: Float32Array | {}): GPUShaderModule;
3932
3932
 
3933
3933
  /** ⚡
3934
3934
  * A plane is a centered rectangle with no stroke.
@@ -4049,6 +4049,7 @@ declare global {
4049
4049
  * shader(grate);
4050
4050
  * image(logo, 0, 0, 180, 180);
4051
4051
  * };
4052
+ * //
4052
4053
  */
4053
4054
  function createImageShader(code: string): GPUShaderModule;
4054
4055
 
@@ -4206,7 +4207,7 @@ declare global {
4206
4207
  * A WebGPU memory allocation limit.
4207
4208
  *
4208
4209
  * The maximum number of transformation matrixes
4209
- * that can be used in a single draw call.
4210
+ * that can be used per frame.
4210
4211
  */
4211
4212
  static MAX_TRANSFORMS: number;
4212
4213
 
@@ -4215,7 +4216,7 @@ declare global {
4215
4216
  *
4216
4217
  * The maximum number of rectangles
4217
4218
  * (calls to `rect`, `square`, `capsule`)
4218
- * that can be drawn in a single draw call.
4219
+ * that can be drawn per frame.
4219
4220
  */
4220
4221
  static MAX_RECTS: number;
4221
4222
 
@@ -4224,7 +4225,7 @@ declare global {
4224
4225
  *
4225
4226
  * The maximum number of ellipses
4226
4227
  * (calls to `ellipse`, `circle`, and `arc`)
4227
- * that can be drawn in a single draw call.
4228
+ * that can be drawn per frame.
4228
4229
  */
4229
4230
  static MAX_ELLIPSES: number;
4230
4231
 
@@ -4232,7 +4233,7 @@ declare global {
4232
4233
  * A WebGPU memory allocation limit.
4233
4234
  *
4234
4235
  * The maximum number of text characters
4235
- * that can be drawn in a single draw call.
4236
+ * that can be drawn per frame.
4236
4237
  */
4237
4238
  static MAX_CHARS: number;
4238
4239
 
@@ -4240,7 +4241,7 @@ declare global {
4240
4241
  * A WebGPU memory allocation limit.
4241
4242
  *
4242
4243
  * The maximum number of separate calls to `text`
4243
- * that can be drawn in a single draw call.
4244
+ * that can be drawn per frame.
4244
4245
  */
4245
4246
  static MAX_TEXTS: number;
4246
4247
 
@@ -4264,14 +4265,6 @@ declare global {
4264
4265
  * Inside the function, `this` refers to the Q5 instance.
4265
4266
  * @param {string} lifecycle 'init', 'presetup', 'postsetup', 'predraw', 'postdraw', or 'remove'
4266
4267
  * @param {Function} fn The function to be run at the specified lifecycle phase.
4267
- * @example
4268
- * Q5.addHook('predraw', function () {
4269
- * this.background('cyan');
4270
- * });
4271
- *
4272
- * q5.draw = function () {
4273
- * circle(mouseX, mouseY, 80);
4274
- * };
4275
4268
  */
4276
4269
  static addHook(lifecycle: string, fn: Function): void;
4277
4270
 
@@ -4294,7 +4287,7 @@ declare global {
4294
4287
  /** ⚙
4295
4288
  * The q5 draw function is run 60 times per second by default.
4296
4289
  */
4297
- draw(): void;
4290
+ static draw(): void;
4298
4291
 
4299
4292
  /** ⚙
4300
4293
  * Runs after each `draw` function call and post-draw q5 addon processes, if any.
@@ -4304,13 +4297,199 @@ declare global {
4304
4297
  * addons like p5play that auto-draw to the canvas after the `draw`
4305
4298
  * function is run.
4306
4299
  */
4307
- postProcess(): void;
4308
- update(): void; //-
4309
-
4310
- drawFrame(): void; //-
4311
-
4312
- static Image: {
4313
- new (w: number, h: number, opt?: any): Q5.Image;
4300
+ static postProcess(): void;
4301
+ //-
4302
+ static update(): void;
4303
+ update(): void;
4304
+ draw(): void;
4305
+ postProcess(): void;
4306
+ Canvas: typeof Canvas;
4307
+ log: typeof log;
4308
+ circle: typeof circle;
4309
+ ellipse: typeof ellipse;
4310
+ rect: typeof rect;
4311
+ square: typeof square;
4312
+ point: typeof point;
4313
+ line: typeof line;
4314
+ capsule: typeof capsule;
4315
+ rectMode: typeof rectMode;
4316
+ ellipseMode: typeof ellipseMode;
4317
+ loadImage: typeof loadImage;
4318
+ image: typeof image;
4319
+ imageMode: typeof imageMode;
4320
+ defaultImageScale: typeof defaultImageScale;
4321
+ resize: typeof resize;
4322
+ trim: typeof trim;
4323
+ smooth: typeof smooth;
4324
+ noSmooth: typeof noSmooth;
4325
+ tint: typeof tint;
4326
+ noTint: typeof noTint;
4327
+ mask: typeof mask;
4328
+ copy: typeof copy;
4329
+ inset: typeof inset;
4330
+ get: typeof get;
4331
+ set: typeof set;
4332
+ loadPixels: typeof loadPixels;
4333
+ updatePixels: typeof updatePixels;
4334
+ filter: typeof filter;
4335
+ createImage: typeof createImage;
4336
+ createGraphics: typeof createGraphics;
4337
+ text: typeof text;
4338
+ loadFont: typeof loadFont;
4339
+ textFont: typeof textFont;
4340
+ textSize: typeof textSize;
4341
+ textLeading: typeof textLeading;
4342
+ textStyle: typeof textStyle;
4343
+ textAlign: typeof textAlign;
4344
+ textWeight: typeof textWeight;
4345
+ textWidth: typeof textWidth;
4346
+ textAscent: typeof textAscent;
4347
+ textDescent: typeof textDescent;
4348
+ createTextImage: typeof createTextImage;
4349
+ textImage: typeof textImage;
4350
+ textToPoints: typeof textToPoints;
4351
+ nf: typeof nf;
4352
+ mousePressed: typeof mousePressed;
4353
+ mouseReleased: typeof mouseReleased;
4354
+ mouseMoved: typeof mouseMoved;
4355
+ mouseDragged: typeof mouseDragged;
4356
+ doubleClicked: typeof doubleClicked;
4357
+ keyIsDown: typeof keyIsDown;
4358
+ keyPressed: typeof keyPressed;
4359
+ keyReleased: typeof keyReleased;
4360
+ touchStarted: typeof touchStarted;
4361
+ touchEnded: typeof touchEnded;
4362
+ touchMoved: typeof touchMoved;
4363
+ cursor: typeof cursor;
4364
+ noCursor: typeof noCursor;
4365
+ mouseWheel: typeof mouseWheel;
4366
+ pointerLock: typeof pointerLock;
4367
+ color: typeof color;
4368
+ colorMode: typeof colorMode;
4369
+ background: typeof background;
4370
+ fill: typeof fill;
4371
+ stroke: typeof stroke;
4372
+ noFill: typeof noFill;
4373
+ noStroke: typeof noStroke;
4374
+ strokeWeight: typeof strokeWeight;
4375
+ opacity: typeof opacity;
4376
+ shadow: typeof shadow;
4377
+ noShadow: typeof noShadow;
4378
+ shadowBox: typeof shadowBox;
4379
+ blendMode: typeof blendMode;
4380
+ strokeCap: typeof strokeCap;
4381
+ strokeJoin: typeof strokeJoin;
4382
+ erase: typeof erase;
4383
+ noErase: typeof noErase;
4384
+ pushStyles: typeof pushStyles;
4385
+ popStyles: typeof popStyles;
4386
+ clear: typeof clear;
4387
+ inFill: typeof inFill;
4388
+ inStroke: typeof inStroke;
4389
+ translate: typeof translate;
4390
+ rotate: typeof rotate;
4391
+ scale: typeof scale;
4392
+ shearX: typeof shearX;
4393
+ shearY: typeof shearY;
4394
+ applyMatrix: typeof applyMatrix;
4395
+ resetMatrix: typeof resetMatrix;
4396
+ pushMatrix: typeof pushMatrix;
4397
+ popMatrix: typeof popMatrix;
4398
+ push: typeof push;
4399
+ pop: typeof pop;
4400
+ displayMode: typeof displayMode;
4401
+ fullscreen: typeof fullscreen;
4402
+ resizeCanvas: typeof resizeCanvas;
4403
+ noLoop: typeof noLoop;
4404
+ redraw: typeof redraw;
4405
+ loop: typeof loop;
4406
+ frameRate: typeof frameRate;
4407
+ getTargetFrameRate: typeof getTargetFrameRate;
4408
+ getFPS: typeof getFPS;
4409
+ pixelDensity: typeof pixelDensity;
4410
+ displayDensity: typeof displayDensity;
4411
+ random: typeof random;
4412
+ jit: typeof jit;
4413
+ noise: typeof noise;
4414
+ dist: typeof dist;
4415
+ map: typeof map;
4416
+ angleMode: typeof angleMode;
4417
+ radians: typeof radians;
4418
+ degrees: typeof degrees;
4419
+ lerp: typeof lerp;
4420
+ constrain: typeof constrain;
4421
+ norm: typeof norm;
4422
+ abs: typeof abs;
4423
+ round: typeof round;
4424
+ ceil: typeof ceil;
4425
+ floor: typeof floor;
4426
+ min: typeof min;
4427
+ max: typeof max;
4428
+ sin: typeof sin;
4429
+ cos: typeof cos;
4430
+ tan: typeof tan;
4431
+ mag: typeof mag;
4432
+ asin: typeof asin;
4433
+ acos: typeof acos;
4434
+ atan: typeof atan;
4435
+ atan2: typeof atan2;
4436
+ pow: typeof pow;
4437
+ fract: typeof fract;
4438
+ sq: typeof sq;
4439
+ sqrt: typeof sqrt;
4440
+ loge: typeof loge;
4441
+ exp: typeof exp;
4442
+ randomSeed: typeof randomSeed;
4443
+ randomGenerator: typeof randomGenerator;
4444
+ randomGaussian: typeof randomGaussian;
4445
+ randomExponential: typeof randomExponential;
4446
+ noiseMode: typeof noiseMode;
4447
+ noiseSeed: typeof noiseSeed;
4448
+ noiseDetail: typeof noiseDetail;
4449
+ loadSound: typeof loadSound;
4450
+ loadAudio: typeof loadAudio;
4451
+ getAudioContext: typeof getAudioContext;
4452
+ userStartAudio: typeof userStartAudio;
4453
+ createEl: typeof createEl;
4454
+ createA: typeof createA;
4455
+ createButton: typeof createButton;
4456
+ createCheckbox: typeof createCheckbox;
4457
+ createColorPicker: typeof createColorPicker;
4458
+ createImg: typeof createImg;
4459
+ createInput: typeof createInput;
4460
+ createP: typeof createP;
4461
+ createRadio: typeof createRadio;
4462
+ createSelect: typeof createSelect;
4463
+ createSlider: typeof createSlider;
4464
+ createVideo: typeof createVideo;
4465
+ createCapture: typeof createCapture;
4466
+ findEl: typeof findEl;
4467
+ findEls: typeof findEls;
4468
+ createRecorder: typeof createRecorder;
4469
+ record: typeof record;
4470
+ pauseRecording: typeof pauseRecording;
4471
+ deleteRecording: typeof deleteRecording;
4472
+ saveRecording: typeof saveRecording;
4473
+ load: typeof load;
4474
+ save: typeof save;
4475
+ loadText: typeof loadText;
4476
+ loadJSON: typeof loadJSON;
4477
+ loadCSV: typeof loadCSV;
4478
+ loadXML: typeof loadXML;
4479
+ loadAll: typeof loadAll;
4480
+ disablePreload: typeof disablePreload;
4481
+ shuffle: typeof shuffle;
4482
+ storeItem: typeof storeItem;
4483
+ getItem: typeof getItem;
4484
+ removeItem: typeof removeItem;
4485
+ clearStorage: typeof clearStorage;
4486
+ year: typeof year;
4487
+ day: typeof day;
4488
+ hour: typeof hour;
4489
+ minute: typeof minute;
4490
+ second: typeof second;
4491
+ static Image: {
4492
+ new (w: number, h: number, opt?: any): Q5.Image;
4314
4493
  };
4315
4494
 
4316
4495
  }
@@ -4319,7 +4498,20 @@ declare global {
4319
4498
  interface Image {
4320
4499
  width: number;
4321
4500
  height: number;
4501
+ copy(): Q5.Image;
4502
+ get(x: number, y: number, w?: number, h?: number): Q5.Image | number[];
4503
+ set(x: number, y: number, val: any): void;
4504
+ resize(w: number, h: number): void;
4505
+ mask(img: Q5.Image): void;
4506
+ trim(): Q5.Image;
4507
+ filter(type: string, value?: number): void;
4508
+ loadPixels(): void;
4509
+ updatePixels(): void;
4510
+ save(fileName?: string): void;
4322
4511
  }
4512
+
4513
+ export import Color = globalThis.Color;
4514
+ export import Vector = globalThis.Vector;
4323
4515
  }
4324
4516
 
4325
4517
  }