Comments (10)
or a javascript library, then you could always just spawn a node process that generates your pallette from command line arguments.
from iwanthue.
I see what you did there. You are of course right and I'm certainly being lazy, but I haven't yet cracked calling javascript from R. I also did look at the source code but it seemed a bit too complicated to port..
from iwanthue.
I think I could take a crack at answering this on StackOverflow if you would like to ask it there.
from iwanthue.
That's jolly helpful Eric, thanks I'll do that tomorrow
from iwanthue.
My curiosity got the better of me.
First, copy chroma.js and chroma.palette-gen.js into a directory.
You need to modify chroma.js and remove the first and last line. "(function(){" and "}).call(this);"
Then, make a new file called something like "generatePalette.js" like this:
var fs = require('fs');
eval(fs.readFileSync('./chroma.js', 'utf8'));
eval(fs.readFileSync('./chroma.palette-gen.js', 'utf8'));
// defaults
var hmin = 0,
hmax = 360,
cmin = 0,
cmax = 3,
lmin = 0,
lmax = 1.5,
q = 50,
useFV = false, // Force vector or kMeans
colorsCount = 7;
// if you want to set more variables from the command line arguments, this is where you'd do it.
// I will just set the colorsCount.
if(process.argv.length > 2) {
colorsCount = parseInt(process.argv[2], 10);
}
var hcondition = hmin < hmax ?
function(hcl){return hcl[0]>=hmin && hcl[0]<=hmax} :
function(hcl){return hcl[0]>=hmin || hcl[0]<=hmax};
var ccondition = function(hcl){return hcl[1]>=cmin && hcl[1]<=cmax};
var lcondition = function(hcl){return hcl[2]>=lmin && hcl[2]<=lmax};
function colorspaceSelector(color) {
var hcl = color.hcl();
return hcondition(hcl) && ccondition(hcl) && lcondition(hcl);
};
var colors = paletteGenerator.generate(colorsCount, colorspaceSelector, useFV, q);
colors = paletteGenerator.diffSort(colors);
colors = colors.map( function( color ){
return { color:color, hex:color.hex(), hcl:color.hcl(), lab:color.lab() }
});
colors.forEach(function(color){
console.log(color.hex);
});
Now you can run it like node generatePalette.js 4
and it will make 4 colors.
harte037$ node ./genpallette.js 4
#A25540
#95BD55
#9E5EAB
#7F9C9A
So the second part is to run this from R or Python, then you can use the output.
http://stat.ethz.ch/R-manual/R-devel/library/base/html/system.html
http://sweetme.at/2014/02/17/a-simple-approach-to-execute-a-node.js-script-from-python/
from iwanthue.
Btw this is slow so for perf you should pre-generate your palettes and store them as constants. I plan to generate sets of size 1 to 20. I don't imagine I'll ever have more than 20 series' in a chart. And if you are running this script by hand then you don't really need the R / Python integration right?
from iwanthue.
I created a simple package to generate an Iwanthue palette in R: https://github.com/hoesler/rwantshue
Maybe someone wants to try it out.
Cheers
from iwanthue.
(edited) Very nice work guys. Eric, I now see your method to implement arguments as per colorsCount..
@hoesler does your library implement arguments for hue, chomra or lightness? IWantHue-class page makes no mention. Do you need an updated generatePalette.js
?
from iwanthue.
Indeed, the feature was missing. I added a color_space argument and the list of presets as defined on the iwanthue webpage.
Am 22.01.2015 um 13:01 schrieb Robin Edwards [email protected]:
Very nice work guys. Please forgive me however I can't figure out how to input hue, chomra or lightness arguments using either method. Have I missed something in the documentation? hoesler's IWantHue-class page makes no mention or arguments.
—
Reply to this email directly or view it on GitHub.
from iwanthue.
Forked this project and stripped it down to the color palette generator. You can find the package on npm.
If you use npm and require.js in your project, using iWantHueAPI is pretty easy. From your command line:
npm install iwanthue-api
Then include it in your project:
var iwanthue = require('iwanthue-api');
More documentation is on the Github repo.
from iwanthue.
Related Issues (20)
- build palette around pre-selected colours? HOT 1
- Theory page JavaScript seems to get stuck in a loop
- Getting many visually distinct colors with the same saturation and lightness is hard
- Edit manipulates wrong colour after ordering them
- Sort by multiple keys
- Not working at all on os/x sierra (chrome or safari) ? HOT 2
- Are we still maintained HOT 3
- Theory page seems to cause browser hang HOT 2
- "I Want Hue" online tool "diff" mode bug
- We really need to create a npm package for this
- Add presets & filters to npm package
- Check bugfix for diffSort
- NaN bug in Protanope distance calculations for RGB color 9549d0
- Recreating same palette again with same parameters - what is the seed for palette? HOT 5
- Suggestion: Add "Steps" and "Ultra Precision" to GUI
- Locks position not changed after changing sorting
- Add HSL values to each color.
- Suggestion: Incorporate background color and WCAG contrast annotations. HOT 1
- Accompanying paper HOT 3
- Color space: boundaries for C HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iwanthue.