painbrush
1.0.21.1.0
src/color/utils.js+
src/color/utils.jsNew file+35
Index: package/src/color/utils.js
===================================================================
--- package/src/color/utils.js
+++ package/src/color/utils.js
@@ -0,0 +1,35 @@
+export const COLOR_ALPHA = [-1, -1, -1];
+export const COLOR_WHITE = [255, 255, 255];
+export const COLOR_BLACK = [0, 0, 0];
+/**
+ * Alphas are a cursed implementation detail that gets treated differently at blending, rn its just -1,-1,-1 but maybe in the future this can be loaded with alpha depth? or not. lol that sounds cursed.
+ */
+export const isAlphaColor = (color) => {
+ return color[0] === -1;
+};
+export const isColorMatch = (color1, color2) => {
+ return (color1[0] === color2[0] &&
+ color1[1] === color2[1] &&
+ color1[2] === color2[2]);
+};
+/**
+ * Layers use this to mix two colors together. this is where the alpha magic happens and where blend modes can go
+ */
+export const blendColor = (top, bottom) => {
+ if (top == null) {
+ return bottom;
+ }
+ if (isAlphaColor(top)) {
+ return bottom;
+ }
+ return top;
+};
+export const makeRandomColor = (r) => {
+ const next = (seed) => {
+ seed = Math.sin(seed) * 10000;
+ return seed - ~~seed;
+ };
+ const g = next(r);
+ const b = next(g);
+ return [r, g, b].map((c) => c * 255);
+};