Skip to content

Commit

Permalink
fix color wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
mck committed Jun 10, 2024
1 parent 4f06181 commit f5cfce4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-items-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/graph-engine": patch
---

Fix color wheel outputs and change lib to colorjs.io
21 changes: 12 additions & 9 deletions packages/graph-engine/src/nodes/color/wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INodeDefinition } from "../../index.js";
import { NodeTypes } from "../../types.js";
import { Node } from "../../programmatic/node.js";
import { ColorSchema, NumberSchema } from "../../schemas/index.js";
import chroma from "chroma-js";
import Color from "colorjs.io";
import { arrayOf } from "../../schemas/utils.js";

export default class NodeDefinition extends Node {
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class NodeDefinition extends Node {
this.addInput("lightness", {
type: {
...NumberSchema,
default: 50,
default: 80,
},
visible: true,
});
Expand All @@ -55,17 +55,20 @@ export default class NodeDefinition extends Node {
}

execute(): void | Promise<void> {
const { colors, hueAngle, hueAmount, saturation, lightness } =
this.getAllInputs();
const { colors, hueAngle, hueAmount, saturation, lightness } = this.getAllInputs();

const colorList: string[] = [];

let step;
for (step = 0; step < colors; step++) {
const hue = hueAngle + (((step * hueAmount) / colors) % 360);
const color = chroma.hsl(hue, saturation, lightness);
colorList.push(color.hex());
for (let step = 0; step < colors; step++) {
const hue = (hueAngle + ((step * hueAmount) / colors)) % 360;

// Color Generation with colorjs.io
const color = new Color("hsl", [hue, saturation, lightness]);
const srgbColor = color.to("srgb");

colorList.push(srgbColor.toString({ format: "hex" }));
}

this.setOutput("value", colorList);
}
}

0 comments on commit f5cfce4

Please sign in to comment.