q5 2.21.5 → 2.22.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
@@ -68,6 +68,16 @@ https://webgpu.github.io/webgpu-samples/?sample=textRenderingMsdf
68
68
  WebGPU blendMode:
69
69
  https://webgpufundamentals.org/webgpu/lessons/webgpu-transparency.html
70
70
 
71
+ HSLtoRGB:
72
+ https://stackoverflow.com/a/64090995/3792062
73
+
74
+ HSBtoHSL:
75
+ https://stackoverflow.com/a/66469632/3792062
76
+
77
+ OKLCHtoRGB:
78
+ https://gist.github.com/dkaraush/65d19d61396f5f3cd8ba7d1b4b3c9432
79
+ https://github.com/color-js/color.js/blob/main/src/spaces/oklch.js
80
+
71
81
  A JS Implementation of Ziggurat Algorithm:
72
82
  http://ziggurat.glitch.me/
73
83
 
package/deno.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@q5/q5",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "license": "LGPL-3.0",
5
- "description": "A sequel to p5.js that's optimized for interactive art",
5
+ "description": "Beginner friendly graphics powered by WebGPU and optimized for interactive art!",
6
6
  "author": "quinton-ashley",
7
7
  "exports": "./q5-deno-server.js",
8
8
  "types": "./q5-deno-server.d.ts",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "q5",
3
- "version": "2.21.5",
4
- "description": "Beginner friendly graphics framework that's powered by WebGPU and optimized for interactive art!",
3
+ "version": "2.22.0",
4
+ "description": "Beginner friendly graphics powered by WebGPU and optimized for interactive art!",
5
5
  "author": "quinton-ashley",
6
6
  "contributors": [
7
7
  "Tezumie",
package/q5.d.ts CHANGED
@@ -8,17 +8,12 @@ declare global {
8
8
  // ⭐️ core
9
9
 
10
10
  /** ⭐️
11
- * Welcome to q5's documentation! ☺️
11
+ * Welcome to q5's documentation! 🤩
12
12
  *
13
13
  * First time coding? Check out the [q5 Beginner's Brief](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Brief).
14
14
  *
15
- * On these Learn pages you'll find concise descriptions for
16
- * q5's functions and variables. Scroll through entire topics without
17
- * needing to click between separate pages.
18
- *
19
- * Experiment with editing the code in the interactive mini examples,
20
- * which are often only 8 lines or less. They automatically
21
- * update as you type, so you can see results right away.
15
+ * On these Learn pages, you can experiment with editing the
16
+ * interactive mini examples. Have fun! 😎
22
17
  */
23
18
 
24
19
  /** ⭐️
@@ -905,15 +900,18 @@ function draw() {
905
900
  function color(c0: string | number | Color | number[], c1?: number, c2?: number, c3?: number): Color;
906
901
 
907
902
  /** 🎨
908
- * Sets the color mode for the sketch. Changes the type of color object created by color functions.
903
+ * Sets the color mode for the sketch, which changes how colors are
904
+ * interpreted and displayed.
909
905
  *
910
- * In c2d, the default color mode is RGB in legacy integer format.
906
+ * The default color mode is RGB in legacy integer format.
911
907
  *
912
- * In WebGPU, the default color mode is RGB in float format.
908
+ * In WebGPU, the default is RGB in float format (best performance).
909
+ *
910
+ * Color gamut is 'display-p3' by default, if the device supports HDR.
913
911
  *
914
- * See the documentation for q5's color constants below for more info.
915
- * @param {'rgb' | 'srgb' | 'oklch'} mode color mode
912
+ * @param {'rgb' | 'oklch' | 'hsl' | 'hsb'} mode color mode
916
913
  * @param {1 | 255} format color format (1 for float, 255 for integer)
914
+ * @param {'srgb' | 'display-p3'} [gamut] color gamut
917
915
  * @example
918
916
  createCanvas(200);
919
917
 
@@ -935,82 +933,176 @@ rect(0, 0, 100, 200);
935
933
  fill(0.75, 0.15, 0)
936
934
  rect(100, 0, 100, 200);
937
935
  */
938
- function colorMode(mode: 'rgb' | 'srgb' | 'oklch', format: 1 | 255): void;
936
+ function colorMode(mode: 'rgb' | 'oklch', format: 1 | 255, gamut: 'srgb' | 'display-p3'): void;
939
937
 
940
938
  /** 🎨
941
939
  * RGB colors have components `r`/`red`, `g`/`green`, `b`/`blue`,
942
940
  * and `a`/`alpha`.
943
941
  *
944
- * By default when a canvas is using the HDR `display-p3` color space,
942
+ * By default when a canvas is using the HDR "display-p3" color space,
945
943
  * rgb colors are mapped to the full P3 gamut, even when they use the
946
944
  * legacy integer 0-255 format.
947
945
  * @example
948
946
  createCanvas(200, 100);
949
947
 
950
- colorMode(RGB, 255);
948
+ colorMode(RGB);
951
949
 
952
950
  background(255, 0, 0);
953
951
  */
954
952
  const RGB: 'rgb';
955
953
 
956
954
  /** 🎨
957
- * This color mode limits the gamut of rgb colors to sRGB.
955
+ * OKLCH colors have components `l`/`lightness`, `c`/`chroma`,
956
+ * `h`/`hue`, and `a`/`alpha`. It's more intuitive for humans
957
+ * to work with color in these terms than RGB.
958
+ *
959
+ * OKLCH is perceptually uniform, meaning colors at the
960
+ * same lightness and chroma (colorfulness) will appear to
961
+ * have equal luminance, regardless of the hue.
962
+ *
963
+ * OKLCH can accurately represent all colors visible to the
964
+ * human eye, unlike many other color spaces that are bounded
965
+ * to a gamut. The maximum lightness and chroma values that
966
+ * correspond to sRGB or P3 gamut limits vary depending on
967
+ * the hue. Colors that are out of gamut will be clipped to
968
+ * the nearest in-gamut color.
969
+ *
970
+ * Use the [OKLCH color picker](https://oklch.com) to find
971
+ * in-gamut colors.
958
972
  *
959
- * If your display is HDR capable, take a look at the following
960
- * example, note that full red appears less saturated, as it would
961
- * on an SDR display.
973
+ * - `lightness`: 0 to 1
974
+ * - `chroma`: 0 to ~0.4
975
+ * - `hue`: 0 to 360
976
+ * - `alpha`: 0 to 1
962
977
  * @example
963
978
  createCanvas(200, 100);
964
979
 
965
- colorMode(SRGB, 255);
980
+ colorMode(OKLCH);
966
981
 
967
- background(255, 0, 0);
982
+ background(0.64, 0.3, 30);
983
+ * @example
984
+ createCanvas(200);
985
+ colorMode(OKLCH);
986
+
987
+ function draw() {
988
+ background(0.7, 0.16, frameCount % 360);
989
+ }
968
990
  */
969
- const SRGB: 'srgb';
991
+ const OKLCH: 'oklch';
970
992
 
971
993
  /** 🎨
972
- * OKLCH colors have components `l`/`lightness`, `c`/`chroma`,
973
- * `h`/`hue`, and `a`/`alpha`.
994
+ * HSL colors have components `h`/`hue`, `s`/`saturation`,
995
+ * `l`/`lightness`, and `a`/`alpha`.
974
996
  *
975
- * You may be familiar with the outdated HSL/HSV color formats,
976
- * which were created in the 1970s to be more intuitive for humans
977
- * to work with than RGB. But due to technical limitations of that
978
- * time, they're not perceptually uniform, meaning colors at the same
979
- * brightness values may appear lighter or darker depending on the hue.
997
+ * HSL was created in the 1970s to approximate human perception
998
+ * of color, trading accuracy for simpler computations. It's
999
+ * not perceptually uniform, so colors with the same lightness
1000
+ * can appear darker or lighter, depending on their hue
1001
+ * and saturation. Yet, the lightness and saturation values that
1002
+ * correspond to gamut limits are always 100, regardless of the
1003
+ * hue. This can make HSL easier to work with than OKLCH.
980
1004
  *
981
- * The OKLCH format is similar to HSL/HSV but it's perceptually
982
- * uniform and supports HDR colors. Use this oklch color picker to
983
- * explore the color space: https://oklch.com
1005
+ * HSL colors are mapped to the full P3 gamut when
1006
+ * using the "display-p3" color space.
984
1007
  *
985
- * `lightness`: 0 to 1
1008
+ * - `hue`: 0 to 360
1009
+ * - `saturation`: 0 to 100
1010
+ * - `lightness`: 0 to 100
1011
+ * - `alpha`: 0 to 1
1012
+ * @example
1013
+ createCanvas(200, 100);
1014
+
1015
+ colorMode(HSL);
1016
+
1017
+ background(0, 100, 50);
1018
+ * @example
1019
+ createCanvas(200, 220);
1020
+ noStroke();
1021
+
1022
+ colorMode(HSL);
1023
+ for (let h = 0; h < 360; h += 10) {
1024
+ for (let l = 0; l <= 100; l += 10) {
1025
+ fill(h, 100, l);
1026
+ rect(h * (11/20), l * 2, 6, 20);
1027
+ }
1028
+ }
1029
+ */
1030
+ const HSL: 'hsl';
1031
+
1032
+ /** 🎨
1033
+ * HSB colors have components `h`/`hue`, `s`/`saturation`,
1034
+ * `b`/`brightness` (aka `v`/`value`), and `a`/`alpha`.
986
1035
  *
987
- * `chroma`: 0 to 0.3
1036
+ * HSB is similar to HSL, but instead of lightness
1037
+ * (black to white), it uses brightness (black to
1038
+ * full color). To produce white, set brightness
1039
+ * to 100 and saturation to 0.
988
1040
  *
989
- * `hue`: 0 to 360
1041
+ * - `hue`: 0 to 360
1042
+ * - `saturation`: 0 to 100
1043
+ * - `brightness`: 0 to 100
1044
+ * - `alpha`: 0 to 1
1045
+ * @example
1046
+ createCanvas(200, 100);
1047
+
1048
+ colorMode(HSB);
1049
+
1050
+ background(0, 100, 100);
1051
+ * @example
1052
+ createCanvas(200, 220);
1053
+ noStroke();
1054
+
1055
+ colorMode(HSB);
1056
+ for (let h = 0; h < 360; h += 10) {
1057
+ for (let b = 0; b <= 100; b += 10) {
1058
+ fill(h, 100, b);
1059
+ rect(h * (11/20), b * 2, 6, 20);
1060
+ }
1061
+ }
1062
+ */
1063
+ const HSB: 'hsb';
1064
+
1065
+ /** 🎨
1066
+ * Limits the color gamut to the sRGB color space.
990
1067
  *
991
- * `alpha`: 0 to 1
1068
+ * If your display is HDR capable, note that full red appears
1069
+ * less saturated and darker in this example, as it would on
1070
+ * an SDR display.
1071
+ * @example
1072
+ createCanvas(200, 100);
1073
+
1074
+ colorMode(RGB, 255, SRGB);
1075
+
1076
+ background(255, 0, 0);
1077
+ */
1078
+ const SRGB: 'srgb';
1079
+
1080
+ /** 🎨
1081
+ * Expands the color gamut to the P3 color space.
1082
+ *
1083
+ * This is the default color gamut on devices that support HDR.
992
1084
  *
993
- * Note how seamless the hue transitions are in the following example.
1085
+ * If your display is HDR capable, note that full red appears
1086
+ * fully saturated and bright in the following example.
994
1087
  * @example
995
- createCanvas(200);
996
- colorMode(OKLCH);
1088
+ createCanvas(200, 100);
997
1089
 
998
- function draw() {
999
- background(0.7, 0.16, frameCount % 360);
1000
- }
1090
+ colorMode(RGB, 255, DISPLAY_P3);
1091
+
1092
+ background(255, 0, 0);
1001
1093
  */
1002
- const OKLCH: 'oklch';
1094
+ const DISPLAY_P3: 'display-p3';
1003
1095
 
1004
1096
  class Color {
1005
1097
  /** 🎨
1098
+ * This constructor strictly accepts 4 numbers, which are the color
1099
+ * components.
1100
+ *
1006
1101
  * Use the `color` function for greater flexibility, it runs
1007
1102
  * this constructor internally.
1008
1103
  *
1009
- * This constructor only accepts 4 numbers, which are the color
1010
- * components.
1011
- *
1012
1104
  * `Color` is not actually a class itself, it's a reference to a
1013
- * Q5 color class based on the color mode and format.
1105
+ * Q5 color class based on the color mode, format, and gamut.
1014
1106
  */
1015
1107
  constructor(c0: number, c1: number, c2: number, c3: number);
1016
1108
  }