Skip to content

Commit

Permalink
Fix color wheel (#300)
Browse files Browse the repository at this point in the history
* fix color wheel calculation

* add changeset
  • Loading branch information
mck authored Jun 18, 2024
1 parent bcfcd55 commit 20242b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-dancers-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/graph-engine": patch
---

Fixes the color wheel calculation.
11 changes: 7 additions & 4 deletions packages/graph-engine/src/nodes/color/wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export default class NodeDefinition extends Node {
constructor(props: INodeDefinition) {
super(props);

this.addInput("hueAmount", {
this.addInput("baseHue", {
type: {
...NumberSchema,
default: 360,
},
visible: true,
});
this.addInput("hueAngle", {
this.addInput("angle", {
type: {
...NumberSchema,
default: 180,
Expand Down Expand Up @@ -54,12 +55,14 @@ export default class NodeDefinition extends Node {
}

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

const colorList: string[] = [];

for (let step = 0; step < colors; step++) {
const hue = (hueAngle + ((step * hueAmount) / colors)) % 360;
// Hue Calculation
const hueIncrement = (colors > 1) ? (angle / (colors - 1)) * step : 0;
const hue = (baseHue + hueIncrement) % 360;

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

0 comments on commit 20242b4

Please sign in to comment.