Giter Club home page Giter Club logo

Comments (10)

ehartford avatar ehartford commented on July 2, 2024

or a javascript library, then you could always just spawn a node process that generates your pallette from command line arguments.

from iwanthue.

geotheory avatar geotheory commented on July 2, 2024

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.

ehartford avatar ehartford commented on July 2, 2024

I think I could take a crack at answering this on StackOverflow if you would like to ask it there.

from iwanthue.

geotheory avatar geotheory commented on July 2, 2024

That's jolly helpful Eric, thanks I'll do that tomorrow

from iwanthue.

ehartford avatar ehartford commented on July 2, 2024

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.

ehartford avatar ehartford commented on July 2, 2024

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.

hoesler avatar hoesler commented on July 2, 2024

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.

geotheory avatar geotheory commented on July 2, 2024

(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.

hoesler avatar hoesler commented on July 2, 2024

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.

andrewliebchen avatar andrewliebchen commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.