/** chroma.palette-gen.js - a palette generator for data scientists based on Chroma.js HCL color space Copyright (C) 2012 Mathieu Jacomy The JavaScript code in this page is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License (GNU GPL) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The code is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. As additional permission under GNU GPL version 3 section 7, you may distribute non-source (e.g., minimized or compacted) forms of that code without the copy of the GNU GPL normally required by section 4, provided you include this license notice and a URL through which recipients can access the Corresponding Source. */ // v0.1 var paletteGenerator={generate:function(e,t,n,r){if(e===undefined)e=8;if(t===undefined)t=function(e){return true};if(n===undefined)n=false;if(r===undefined)r=50;if(n){var s=[];function o(e){var n=chroma.lab(e[0],e[1],e[2]);return!isNaN(n.rgb[0])&&n.rgb[0]>=0&&n.rgb[1]>=0&&n.rgb[2]>=0&&n.rgb[0]<256&&n.rgb[1]<256&&n.rgb[2]<256&&t(n)}var u={};for(i=0;i0){for(i=0;i0){var E=c/Math.pow(w,2);u[i].dl+=m*E/w;u[i].da+=g*E/w;u[i].db+=y*E/w;u[j].dl-=m*E/w;u[j].da-=g*E/w;u[j].db-=y*E/w}else{u[j].dl+=.02-.04*Math.random();u[j].da+=.02-.04*Math.random();u[j].db+=.02-.04*Math.random()}}}for(i=0;i0){var x=h*Math.min(.1,S)/S;candidateLab=[f[0]+u[i].dl*x,f[1]+u[i].da*x,f[2]+u[i].db*x];if(o(candidateLab)){s[i]=candidateLab}}}}return s.map(function(e){return chroma.lab(e[0],e[1],e[2])})}else{function T(e){var n=e.lab();var r=e.hcl();return!isNaN(e.rgb[0])&&e.rgb[0]>=0&&e.rgb[1]>=0&&e.rgb[2]>=0&&e.rgb[0]<256&&e.rgb[1]<256&&e.rgb[2]<256&&t(e)}var N=[];for(i=0;i0){for(i=0;i0){var A=1e10;var H=-1;for(i=0;i<_.length;i++){var M=Math.sqrt(Math.pow(_[i][0]-P[0],2)+Math.pow(_[i][1]-P[1],2)+Math.pow(_[i][2]-P[2],2));if(M0){var n=-1;var r=-1;for(candidate_index=0;candidate_indexr){r=s;n=candidate_index}}var c=e[n];t.push(c);e=e.filter(function(e,t){return t!=n})}return t}}