q5 2.4.10 → 2.5.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/README.md CHANGED
@@ -339,13 +339,13 @@ Unminified:
339
339
 
340
340
  - p5.js **5112kb** ⚠️
341
341
  - p5.sound.js 488kb
342
- - q5.js 93kb
342
+ - q5.js 110kb
343
343
 
344
344
  Minified:
345
345
 
346
346
  - p5.min.js 1034kb ⚠️
347
347
  - p5.sound.min.js 200kb
348
- - q5.min.js **61kb** 🎉
348
+ - q5.min.js **70kb** 🎉
349
349
 
350
350
  ## Benchmarks
351
351
 
@@ -404,6 +404,9 @@ p5.js is licensed under the LGPLv2, the two small sections of p5' code directly
404
404
 
405
405
  ## Credits
406
406
 
407
+ q5-webgpu msdf text rendering:
408
+ https://webgpu.github.io/webgpu-samples/?sample=textRenderingMsdf
409
+
407
410
  q5-webgpu blendMode:
408
411
  https://webgpufundamentals.org/webgpu/lessons/webgpu-transparency.html
409
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.4.10",
3
+ "version": "2.5.1",
4
4
  "description": "A sequel to p5.js that's smaller and faster",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
package/q5.d.ts CHANGED
@@ -86,6 +86,22 @@ declare global {
86
86
  */
87
87
  var deviceOrientation: string | null;
88
88
 
89
+ /** ⭐️
90
+ * Use preload to load assets before the sketch starts and the
91
+ * setup function is run.
92
+ */
93
+ function preload(): void;
94
+
95
+ /** ⭐️
96
+ * The setup function is called once when the program starts.
97
+ */
98
+ function setup(): void;
99
+
100
+ /** ⭐️
101
+ * The draw function is run 60 times per second by default.
102
+ */
103
+ function draw(): void;
104
+
89
105
  /** ⭐️
90
106
  * Stops the draw loop.
91
107
  */
@@ -312,6 +328,8 @@ declare global {
312
328
 
313
329
  /** ⬜️
314
330
  * Saves the current drawing style settings.
331
+ *
332
+ * This includes the fill, stroke, stroke weight, tint, image mode, rect mode, ellipse mode, text size, text align, and text baseline.
315
333
  */
316
334
  function pushStyles(): void;
317
335
 
@@ -565,9 +583,11 @@ declare global {
565
583
  function resize(w: number, h: number): void;
566
584
 
567
585
  /** 🌆
568
- * Trims the image, cropping out transparent pixels from the edges.
586
+ * Returns a trimmed image, cropping out transparent pixels
587
+ * from the edges.
588
+ * @returns {Image}
569
589
  */
570
- function trim(): void;
590
+ function trim(): Image;
571
591
 
572
592
  /** 🌆
573
593
  * Masks the image with another image
@@ -584,29 +604,61 @@ declare global {
584
604
  function save(a: string, b: string, c?: number): void;
585
605
 
586
606
  /** 🌆
587
- * Retrieves pixel data from an image.
607
+ * Displays a region of the image on another region of the image.
608
+ *
609
+ * Can be used to create a detail inset, aka a magnifying glass effect.
610
+ *
611
+ * @param srcX - x-coordinate of the source region
612
+ * @param srcY - y-coordinate of the source region
613
+ * @param srcW - width of the source region
614
+ * @param srcH - height of the source region
615
+ * @param dstX - x-coordinate of the destination region
616
+ * @param dstY - y-coordinate of the destination region
617
+ * @param dstW - width of the destination region
618
+ * @param dstH - height of the destination region
619
+ */
620
+ function inset(srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH): void;
621
+
622
+ /** 🌆
623
+ * Returns a copy of the image.
624
+ * @returns {Image}
625
+ */
626
+ function copy(): Image;
627
+
628
+ /** 🌆
629
+ * Retrieves a subsection of an image or canvas, as a q5 Image.
630
+ *
631
+ * Or if width and height are both 1, returns the color of the pixel at
632
+ * the given coordinates in `[R, G, B, A]` array format.
633
+ *
634
+ * To edit the color value of multiple pixels, it's faster to use
635
+ * `loadPixels` and `updatePixels`.
588
636
  * @param x
589
637
  * @param y
590
638
  * @param w - width of the area
591
639
  * @param h - height of the area
640
+ * @returns {Image}
592
641
  */
593
642
  function get(x: number, y: number, w?: number, h?: number): any;
594
643
 
595
644
  /** 🌆
596
- * Sets pixel data in the image.
645
+ * Sets a pixel's color in the image or canvas.
646
+ *
647
+ * Or if a canvas or image is provided, it's drawn on top of the
648
+ * destination image or canvas ignoring its tint setting.
597
649
  * @param x
598
650
  * @param y
599
- * @param c - color or pixel data
651
+ * @param c - color, canvas, or image
600
652
  */
601
653
  function set(x: number, y: number, c: any): void;
602
654
 
603
655
  /** 🌆
604
- * Loads pixel data into the image's pixel array.
656
+ * Loads pixel data into the image's `pixels` array.
605
657
  */
606
658
  function loadPixels(): void;
607
659
 
608
660
  /** 🌆
609
- * Updates the image's pixels array to the canvas.
661
+ * Updates the image's `pixels` array to the canvas.
610
662
  */
611
663
  function updatePixels(): void;
612
664
 
@@ -775,6 +827,11 @@ declare global {
775
827
 
776
828
  /** ✍️
777
829
  * Loads a font from a URL and optionally runs a callback function with the font name once it's loaded
830
+ *
831
+ * WebGPU: Fonts must be in MSDF format with the file ending
832
+ * "-msdf.json". If no font is loaded before `text` is run, then
833
+ * the default font is loaded:
834
+ * https://q5js.org/fonts/YaHei-msdf.json
778
835
  * @param url - URL of the font to load
779
836
  * @param cb - Optional callback function that receives the font name as an argument once the font is loaded
780
837
  * @returns name of the loaded font
@@ -782,7 +839,7 @@ declare global {
782
839
  function loadFont(url: string, cb?: (fontName: string) => void): string;
783
840
 
784
841
  /** ✍️
785
- * Sets the current font to be used for text elements
842
+ * Sets the current font to be used for rendering text
786
843
  * @param fontName - name of the font
787
844
  */
788
845
  function textFont(fontName: string): void;
@@ -812,7 +869,7 @@ declare global {
812
869
  * @param horiz - horizontal alignment ('left', 'center', 'right')
813
870
  * @param vert - vertical alignment ('top', 'middle', 'bottom', 'alphabetic')
814
871
  */
815
- function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'middle' | 'bottom' | 'alphabetic'): void;
872
+ function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'center' | 'bottom' | 'alphabetic'): void;
816
873
 
817
874
  /** ✍️
818
875
  * Calculates and returns the width of a given string of text
@@ -894,7 +951,7 @@ declare global {
894
951
 
895
952
  /** 🎨
896
953
  * Sets the color mode for the sketch. Changes the type of color object created by color functions.
897
- *
954
+ *
898
955
  * In WebGPU, the default color mode is 'rgb' in float format.
899
956
  * @param mode - color mode ('rgb', 'srgb', or 'oklch')
900
957
  * @param format - color format (1 or 255) for floating point or legacy 8-bit integer representation
@@ -1145,7 +1202,7 @@ declare global {
1145
1202
  */
1146
1203
  function noiseDetail(lod: number, falloff: number): void;
1147
1204
 
1148
- // 🔊 q5-sound
1205
+ // 🔊 sound
1149
1206
 
1150
1207
  /** 🔊
1151
1208
  * Represents a sound object, extending the native `Audio` to