diff --git a/src/graph/nodes/effects/RotateNode.ts b/src/graph/nodes/effects/RotateNode.ts new file mode 100644 index 0000000..343a25c --- /dev/null +++ b/src/graph/nodes/effects/RotateNode.ts @@ -0,0 +1,25 @@ +import { defineNode } from "baklavajs"; +import { scaleColorArray } from "@/utils"; +import { ColorArrayInterface, NumberInterface } from "../../interfaces"; +import { LmsCalculationContext } from "../../types"; +import { Color } from "../../colors"; + +export const RotateNode = defineNode({ + type: "Rotate", + inputs: { + colorsIn: () => new ColorArrayInterface("Colors", []), + rotation: () => new NumberInterface("Rotation", 0, 0, 1), + }, + outputs: { + colorsOut: () => new ColorArrayInterface("Colors", []), + }, + calculate: ({ colorsIn, rotation }, ctx: LmsCalculationContext) => { + const scaledColors = scaleColorArray(colorsIn, ctx.globalValues.resolution); + const absoluteRotation = Math.round(rotation * ctx.globalValues.resolution); + const colorsOut: Color[] = []; + for (let i = 0; i < ctx.globalValues.resolution; i++) { + colorsOut.push(scaledColors.at(i - absoluteRotation)!); + } + return { colorsOut }; + }, +}); diff --git a/src/graph/nodes/effects/index.ts b/src/graph/nodes/effects/index.ts index 07d05cb..00bcd9b 100644 --- a/src/graph/nodes/effects/index.ts +++ b/src/graph/nodes/effects/index.ts @@ -1,2 +1,3 @@ export * from "./AfterglowNode"; export * from "./MirrorNode"; +export * from "./RotateNode";