Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
Created October 27, 2016 16:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nataliefreed/c9eac362817fcedcdc9b9a395ba88845 to your computer and use it in GitHub Desktop.
OpenJSCAD Color Picker example
function getParameterDefinitions() {
return [{ name: 'color', type: 'color', initial: '#FFB431', caption: 'Color?' }];
}
function main(params) {
var box = cube();
box = box.setColor(hexToRGB(params.color));
return box;
}
//based on OpenJSCAD balloon example by Z3 Dev
function hexToRGB(hexColor) {
if(hexColor.length === 7) {
var r = parseInt('0x'+hexColor.slice(1,3))/255;
var g = parseInt('0x'+hexColor.slice(3,5))/255;
var b = parseInt('0x'+hexColor.slice(5,7))/255;
return [r,g,b];
}
else return [0,0,0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment