Skip to content

Instantly share code, notes, and snippets.

@eromanc
Created March 9, 2023 23:41
Show Gist options
  • Save eromanc/d593b7e57ff617575d43716072eda619 to your computer and use it in GitHub Desktop.
Save eromanc/d593b7e57ff617575d43716072eda619 to your computer and use it in GitHub Desktop.
HSL to HSV Origami JS Patch
//==============================================================================
// Welcome to scripting in Origami! Helpful links:
//
// Scripting Basics - https://origami.design/documentation/concepts/scriptingbasics
// Scripting API - https://origami.design/documentation/concepts/scriptingapi
//
// Script ID: AAF8D4A5-DB15-4F56-8650-8A6B8C22D703
//==============================================================================
var patch = new Patch();
// Patches are always being evaluated when inputs change of values. If you need your patch to run every frame set this to true
// Setting this to true makes scripts very inefficient and should be avoided at all cost.
patch.alwaysNeedsToEvaluate = false;
// Set Inputs and Outputs.
patch.inputs = [
new PatchInput("h", types.NUMBER, 0),
new PatchInput("s", types.NUMBER, 0),
new PatchInput("l", types.NUMBER, 0),
];
patch.outputs = [
new PatchOutput("h", types.NUMBER),
new PatchOutput("s", types.NUMBER),
new PatchOutput("v", types.NUMBER),
];
function hsl_to_hsv(h, s, l) {
const hsv1 = s * (l < .5 ? l : 1. - l) / 1.0;
const hsvS = hsv1 === 0 ? 0 : 2 * hsv1 / (l + hsv1);
const hsvV = l + hsv1;
return [ h, hsvS, hsvV ];
}
// Add your logic in this function.
patch.evaluate = function() {
let hsv = hsl_to_hsv(
patch.inputs[0].value,
patch.inputs[1].value,
patch.inputs[2].value
);
patch.outputs[0].value = hsv[0];
patch.outputs[1].value = hsv[1];
patch.outputs[2].value = hsv[2];
}
return patch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment