Initial commit
This commit is contained in:
82
Cubehelix.js
Normal file
82
Cubehelix.js
Normal file
@@ -0,0 +1,82 @@
|
||||
// Cubehelix color scheme for Max/MSP/Jitter
|
||||
// By Théophile Clet - https://tflcl.xyz
|
||||
// Based on Dave Green's work: http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/cubetry.html
|
||||
// Original publication: Green, D. A., 2011, `A colour scheme for the display of astronomical intensity images', Bulletin of the Astronomical Society of India, 39, 289. (2011BASI...39..289G at ADS.) ( http://astron-soc.in/bulletin/11June/289392011.pdf )
|
||||
// Original js code taken straight from the online example implementation: http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/cubetry.html
|
||||
|
||||
|
||||
autowatch = 0;
|
||||
inlets = 1;
|
||||
outlets = 2;
|
||||
|
||||
setinletassist(0, "List as input: {makeCubehelixRGB, start[float], rots[float], sign[-1,1], hue[float], gamma[float], levels(int), flip([0,1]}")
|
||||
setoutletassist(0, "To jit.matrix: outputs the color palette as a 4-plane 1 dim matrix");
|
||||
setoutletassist(1, "dump out. Outputs paramters used for generation. Bangs when finished.");
|
||||
|
||||
function makeCubehelixRGB(start, rots, sign, hue, gamma, levels, flip){
|
||||
rots = rots*sign;
|
||||
|
||||
//dumpOut(start, rots, hue, gamma, levels, flip);
|
||||
|
||||
outlet(0, "dim", levels, 1);
|
||||
for (var i = 0; i < levels; i++) {
|
||||
|
||||
var fract = CubeHelixFract(i,levels,flip);
|
||||
var red = CubeHelixRGB(fract,start,rots,hue,gamma,1);
|
||||
var grn = CubeHelixRGB(fract,start,rots,hue,gamma,2);
|
||||
var blu = CubeHelixRGB(fract,start,rots,hue,gamma,3);
|
||||
|
||||
if(flip == 1){fract = 1.0-fract;}
|
||||
|
||||
outlet(0, "setcell", i, 0, "val", 1., red, grn, blu);
|
||||
}
|
||||
outlet(0, "bang");
|
||||
outlet(1, "bang");
|
||||
}
|
||||
|
||||
function dumpOut(start, rots, hue, gamma, levels, flip){
|
||||
outlet(1, "start", start);
|
||||
outlet(1, "rots", rots);
|
||||
outlet(1, "hue", hue);
|
||||
outlet(1, "gamma", gamma);
|
||||
outlet(1, "levels", levels);
|
||||
outlet(1, "flip", flip);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
// 2017 May 30: make consistent with Fortran
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function CubeHelixRGB(fract,start,rots,hue,gamma,irgb){
|
||||
|
||||
var angle = 2*Math.PI*(start/3.0+1+rots*fract);
|
||||
var fract = Math.pow(fract, gamma);
|
||||
var amp=hue*fract*(1-fract)/2.0;
|
||||
|
||||
var r=fract+amp*(-0.14861*Math.cos(angle)+1.78277*Math.sin(angle));
|
||||
var g=fract+amp*(-0.29227*Math.cos(angle)-0.90649*Math.sin(angle));
|
||||
var b=fract+amp*(+1.97294*Math.cos(angle));
|
||||
|
||||
r=Math.max(Math.min(r,1.0),0.0);
|
||||
g=Math.max(Math.min(g,1.0),0.0);
|
||||
b=Math.max(Math.min(b,1.0),0.0);
|
||||
|
||||
if(irgb == 1){
|
||||
return r;
|
||||
}
|
||||
else if(irgb == 2) {
|
||||
return g;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function CubeHelixFract(i,n,flip){
|
||||
var fraction = i/(n-1);
|
||||
if (flip == 1) {
|
||||
fraction = 1 - fraction;
|
||||
}
|
||||
return fraction;
|
||||
}
|
2777
Cubehelix.maxpat
Normal file
2777
Cubehelix.maxpat
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user