JuliaAttic / Color.jl

Basic color manipulation utilities.
Other
47 stars 21 forks source link

Expose continuous analogues of colormaps #69

Open jwmerrill opened 9 years ago

jwmerrill commented 9 years ago

It's currently easy to get a beautiful red-blue diverging colormap with, e.g. 20 colors by calling

colormap("RdBu", 20)

I would like to be able to map a continuous variable (for definiteness, say it ranges from -1.0 to 1.0) into this map, but I don't currently see an easy way to do this. Basically what I'm asking for is the N → ∞ limit of

function (x)
    colormap("RdBu", N)[1 + ifloor((x + 1.0)/2.0*N)]
end

I haven't gotten completely to the bottom of the way things are currently implemented, but given that you can already specify different values for N, it seems like something close to such a function must already exist privately somewhere inside the implementation, and it would be nice to expose it.

natj commented 9 years ago

Under the hood colormaps are just Bezier splines in LCHuv colorspace from one color to other so what you are asking is completely possible. Instead of using the colormap function that splices the continuous representation into parts, you can use the underlying functions and call the splines directly with what ever value you want.