Created
October 27, 2016 16:19
-
-
Save nataliefreed/c9eac362817fcedcdc9b9a395ba88845 to your computer and use it in GitHub Desktop.
OpenJSCAD Color Picker example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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