Compare commits

...

3 Commits

Author SHA1 Message Date
tfl
4d3d98fcc3 changed from rgb2hsl to rgb2luma in helpfile as more in purpose 2023-10-05 16:15:06 +02:00
tfl
1dd0cae4c3 readme update 2023-09-22 12:19:58 +02:00
tfl
c4f3c46fc6 remove ignored files 2023-09-22 11:38:25 +02:00
9 changed files with 44 additions and 7763 deletions

View File

@@ -1,9 +1,27 @@
# Cubehelix for Max
By Théophile Clet - 2021-05-13
By Théophile Clet - september, 2023. First version from 2021.
https://tflcl.xyz
Original work and js code by Dave Green
http://www.mrao.cam.ac.uk/~dag/CUBEHELIX
![jit.cubehelix.ui](img/jit.cubehelix.ui.png)
## What is this
This is an implementation of cubehelix color palette generator algorithm for Cycling74```s Max.
It consists of a few files:
- ```cubehelix.genjit``` which is the "low-level" code for cubehlix calculation in the jit world
- ```jit.cubehelix.maxpat```, an abstraction wrapping ```cubehelix.genjit``` as a patcher with some added features for convenience: initialization with attributes, accepts inputs for both ranges (like the D3 implementation) and legacy parameters (start, rotation), converts output matrix...
- ```jit.cubehelix.maxhelp```, the help file for the \[jit.cubehelix\] abstraction, with examples and explanations
- ```jit.cubehelix.ui.maxpat```, which is basically a wrapper for \[jit.cubehelix\] with an user interface (can be used as a \[bpatcher\]), randomization capabilities and preset handling (using the pattr system).
- ```knob-range.js```, a custom \[jsui\] knob made for \[jit.cubehelix.ui\] but which can be repurposed for other things. It allows to set a custom output range, randomize the value in an inner range that can be modified with ctrl+drag (change offset) and option/alt+drag (change width). Holding shift allows fine tuning.
- ```cubehelixui-default```, some default presets for \[jit.cubehelix.ui\].
Green, D. A., 2011, `A colour scheme for the display of astronomical intensity images', Bulletin of the Astronomical Society of India, 39, 289.
http://astron-soc.in/bulletin/11June/289392011.pdf
## How to use
1. Clone this repo
2. Put the folder in your Max search paths
3. Start patching. \[jit.cubehelix\] and its helper file are a good starting point.
## Credits
Heavily based on [@mbostock cubehelix implementation in D3.js](https://github.com/d3/d3-plugins/tree/master/cubehelix).
Original cubehelix by Dave Green: [Green, D. A., 2011, "A colour scheme for the display of astronomical intensity images", *Bulletin of the Astronomical Society of India*, 39, 289.](http://astron-soc.in/bulletin/11June/289392011.pdf)
![jit.cubehelix helper file example 1](img/jit.cubehelix.maxhelp.1.png)
![jit.cubehelix helper file example 2](img/jit.cubehelix.maxhelp.2.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
img/jit.cubehelix.ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@@ -354,7 +354,7 @@
}
,
"classnamespace" : "box",
"rect" : [ 0.0, 26.0, 747.0, 561.0 ],
"rect" : [ 85.0, 126.0, 747.0, 561.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
@@ -385,6 +385,18 @@
"assistshowspatchername" : 0,
"title" : "History",
"boxes" : [ {
"box" : {
"id" : "obj-11",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "jit_matrix", "" ],
"patching_rect" : [ 15.0, 398.0, 71.0, 22.0 ],
"text" : "jit.rgb2luma"
}
}
, {
"box" : {
"id" : "obj-4",
"maxclass" : "jit.pwindow",
@@ -515,8 +527,8 @@
"numinlets" : 1,
"numoutlets" : 3,
"outlettype" : [ "jit_matrix", "jit_matrix", "" ],
"patching_rect" : [ 15.0, 363.0, 244.0, 22.0 ],
"text" : "jit.cubehelix @dim 100 @coloroutputmode 1"
"patching_rect" : [ 15.0, 363.0, 194.0, 22.0 ],
"text" : "jit.cubehelix @type char @dim 100"
}
}
@@ -584,18 +596,6 @@
"textcolor" : [ 0.0, 0.0, 0.0, 1.0 ]
}
}
, {
"box" : {
"id" : "obj-15",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 5,
"outlettype" : [ "jit_matrix", "jit_matrix", "jit_matrix", "jit_matrix", "" ],
"patching_rect" : [ 15.0, 404.0, 69.0, 22.0 ],
"text" : "jit.unpack 4"
}
}
, {
"box" : {
@@ -606,7 +606,7 @@
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 303.0, 394.0, 168.0, 39.0 ],
"text" : "Shows only lightness channel"
"text" : "Shows perceived brightness"
}
}
@@ -638,7 +638,7 @@
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-15", 0 ],
"destination" : [ "obj-11", 0 ],
"source" : [ "obj-1", 0 ]
}
@@ -660,7 +660,7 @@
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-15", 3 ]
"source" : [ "obj-11", 0 ]
}
}
@@ -1280,7 +1280,7 @@
}
,
"classnamespace" : "box",
"rect" : [ 85.0, 126.0, 747.0, 561.0 ],
"rect" : [ 0.0, 26.0, 747.0, 561.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
@@ -2055,8 +2055,8 @@
}
, {
"name" : "knob-range.js",
"bootpath" : "D:/_MAX/_RESSOURCE/tc.utils/jsui_knob",
"patcherrelativepath" : "../tc.utils/jsui_knob",
"bootpath" : "D:/_MAX/_RESSOURCE/Cubehelix_color_MaxMSP",
"patcherrelativepath" : ".",
"type" : "TEXT",
"implicit" : 1
}

View File

@@ -1,139 +0,0 @@
// 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 = 4;
var RGBOUTLET = 0;
var HSLOUTLET = 1;
var LISTOUTLET = 2
var DUMPOUTLET = 3;
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: always outputs the color palette as a ARGB 4-plane matrix");
setoutletassist(1, "To jit.matrix: if 'hslenable 1' outputs the color palette as a AHSL 4-plane matrix");
setoutletassist(2, "If 'listmode 1' outputs all colors in list format as RGB or HSL.");
setoutletassist(3, "Bangs when generation is done.");
var hslmode = false;
var listmode = false;
function hslenable(s){
hslmode = s;
}
function listenable(s){
listmode = s;
}
function makeCubehelix(start, rots, hue, gamma, levels, flip){
//dumpOut(start, rots, hue, gamma, levels, flip);
outlet(RGBOUTLET, "dim", levels, 1);
if (hslmode) {
outlet(HSLOUTLET, "dim", levels, 1);
}
for (var i = 0; i < levels; i++) {
var fract = CubeHelixFract(i,levels,flip);
var color = CubeHelixRGB(fract,start,rots,hue,gamma);
if(flip == 1){fract = 1.0-fract;}
outlet(RGBOUTLET, "setcell", i, 0, "val", 1., color);
if (hslmode) {
color = rgb2hsl(color[0], color[1], color[2]);
outlet(HSLOUTLET, "setcell", i, 0, "val", 1., color);
}
if (listmode) { outlet(LISTOUTLET, i, color); }
}
outlet(RGBOUTLET, "bang");
if (hslmode) { outlet(HSLOUTLET, "bang"); }
if (listmode) { outlet(LISTOUTLET, "bang"); }
outlet(DUMPOUTLET, "bang");
}
function dumpOut(start, rots, hue, gamma, levels, flip){
outlet(DUMPOUTLET, "start", start);
outlet(DUMPOUTLET, "rots", rots);
outlet(DUMPOUTLET, "hue", hue);
outlet(DUMPOUTLET, "gamma", gamma);
outlet(DUMPOUTLET, "levels", levels);
outlet(DUMPOUTLET, "flip", flip);
}
function rgb2hsl(r,g,b) {
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0; // achromatic
} else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [ h, s, l ];
}
// ----------------------------------------------------------------------------
// 2017 May 30: make consistent with Fortran
// 2021 mai 12: a bit of calculation optimization (I think) - Théophile Clet
// ----------------------------------------------------------------------------
function CubeHelixRGB(fract,start,rots,hue,gamma){
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 acos = Math.cos(angle);
var asin = Math.sin(angle);
var r=fract+amp*(-0.14861*acos+1.78277*asin);
r=Math.max(Math.min(r,1.0),0.0);
var g=fract+amp*(-0.29227*acos-0.90649*asin);
g=Math.max(Math.min(g,1.0),0.0);
var b=fract+amp*(+1.97294*acos);
b=Math.max(Math.min(b,1.0),0.0);
return [r, g, b];
}
// ----------------------------------------------------------------------------
function CubeHelixFract(i,n,flip){
var fraction = i/(n-1);
if (flip == 1) {
fraction = 1 - fraction;
}
return fraction;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,468 +0,0 @@
{
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 3,
"revision" : 6,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 1198.0, 591.0, 578.0, 815.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"id" : "obj-38",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 462.0, 46.0, 70.0, 22.0 ],
"style" : "",
"text" : "getcolor $1"
}
}
, {
"box" : {
"id" : "obj-36",
"maxclass" : "number",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "bang" ],
"parameter_enable" : 0,
"patching_rect" : [ 462.0, 15.0, 50.0, 22.0 ],
"style" : ""
}
}
, {
"box" : {
"format" : 6,
"id" : "obj-33",
"maxclass" : "flonum",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "bang" ],
"parameter_enable" : 0,
"patching_rect" : [ 367.5, 15.0, 50.0, 22.0 ],
"style" : ""
}
}
, {
"box" : {
"id" : "obj-34",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 367.5, 46.0, 73.0, 22.0 ],
"style" : "",
"text" : "rotations $1"
}
}
, {
"box" : {
"format" : 6,
"id" : "obj-32",
"maxclass" : "flonum",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "bang" ],
"parameter_enable" : 0,
"patching_rect" : [ 275.5, 15.0, 50.0, 22.0 ],
"style" : ""
}
}
, {
"box" : {
"id" : "obj-28",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 275.5, 46.0, 77.0, 22.0 ],
"style" : "",
"text" : "startcolor $1"
}
}
, {
"box" : {
"id" : "obj-26",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 208.0, 42.0, 51.0, 22.0 ],
"style" : "",
"text" : "random"
}
}
, {
"box" : {
"id" : "obj-24",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 20.0, 10.0, 173.0, 22.0 ],
"style" : "",
"text" : "makeCubehelix 0. 1. 1. 1. 32 1"
}
}
, {
"box" : {
"id" : "obj-22",
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 237.0, 612.0, 33.0, 20.0 ],
"style" : "",
"text" : "Hue"
}
}
, {
"box" : {
"id" : "obj-21",
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 237.0, 638.0, 69.0, 20.0 ],
"style" : "",
"text" : "Luminance"
}
}
, {
"box" : {
"id" : "obj-19",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 132.0, 612.0, 103.0, 22.0 ],
"style" : "",
"text" : "planemap 1 1 1 1"
}
}
, {
"box" : {
"id" : "obj-18",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 132.0, 638.0, 103.0, 22.0 ],
"style" : "",
"text" : "planemap 3 3 3 3"
}
}
, {
"box" : {
"id" : "obj-16",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 132.0, 583.0, 103.0, 22.0 ],
"style" : "",
"text" : "planemap 0 1 2 3"
}
}
, {
"box" : {
"id" : "obj-13",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 208.0, 536.0, 52.0, 22.0 ],
"style" : "",
"text" : "print list"
}
}
, {
"box" : {
"id" : "obj-10",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 225.333313, 795.0, 189.0, 22.0 ],
"style" : "",
"text" : "15 0.46834 0.947702 0.333514"
}
}
, {
"box" : {
"id" : "obj-8",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 169.666656, 752.0, 198.0, 22.0 ],
"style" : "",
"text" : "4 0.053409 0.02406 0.011621"
}
}
, {
"box" : {
"id" : "obj-6",
"maxclass" : "button",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 302.0, 708.0, 24.0, 24.0 ],
"style" : ""
}
}
, {
"box" : {
"id" : "obj-4",
"maxclass" : "newobj",
"numinlets" : 4,
"numoutlets" : 4,
"outlettype" : [ "", "", "", "" ],
"patching_rect" : [ 302.0, 672.0, 159.0, 22.0 ],
"style" : "",
"text" : "route bang rgbcolor hslcolor"
}
}
, {
"box" : {
"id" : "obj-3",
"maxclass" : "jit.pwindow",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 114.0, 665.0, 80.0, 60.0 ],
"planemap" : [ 3, 3, 3, 3 ]
}
}
, {
"box" : {
"id" : "obj-2",
"maxclass" : "jit.pwindow",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 20.0, 665.0, 80.0, 60.0 ]
}
}
, {
"box" : {
"bgmode" : 0,
"border" : 0,
"clickthrough" : 0,
"enablehscroll" : 0,
"enablevscroll" : 0,
"id" : "obj-1",
"lockeddragscroll" : 0,
"maxclass" : "bpatcher",
"name" : "Cubehelix.maxpat",
"numinlets" : 1,
"numoutlets" : 4,
"offset" : [ 0.0, 0.0 ],
"outlettype" : [ "jit_matrix", "jit_matrix", "", "" ],
"patching_rect" : [ 20.0, 120.0, 301.0, 398.0 ],
"viewvisibility" : 1
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-13", 0 ],
"source" : [ "obj-1", 2 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-1", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"source" : [ "obj-1", 1 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-4", 0 ],
"source" : [ "obj-1", 3 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"source" : [ "obj-16", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"source" : [ "obj-18", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"source" : [ "obj-19", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-24", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-26", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-28", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-28", 0 ],
"source" : [ "obj-32", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-34", 0 ],
"source" : [ "obj-33", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-34", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-38", 0 ],
"source" : [ "obj-36", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-38", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-10", 1 ],
"source" : [ "obj-4", 2 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-6", 0 ],
"source" : [ "obj-4", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-8", 1 ],
"source" : [ "obj-4", 1 ]
}
}
],
"parameters" : {
"obj-1::obj-85" : [ "live.text[1]", "live.text[1]", 0 ],
"obj-1::obj-133" : [ "live.tab[1]", "live.tab", 0 ],
"obj-1::obj-1" : [ "live.text[2]", "live.text[1]", 0 ],
"obj-1::obj-104" : [ "live.tab", "live.tab", 0 ],
"obj-1::obj-141" : [ "live.tab[2]", "live.tab", 0 ]
}
,
"dependency_cache" : [ {
"name" : "Cubehelix.maxpat",
"bootpath" : "~/Documents/_MAX/_RESSOURCE/Color palettes",
"patcherrelativepath" : ".",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "Cubehelix.js",
"bootpath" : "~/Documents/_MAX/_RESSOURCE/Color palettes",
"patcherrelativepath" : ".",
"type" : "TEXT",
"implicit" : 1
}
],
"autosave" : 0
}
}

File diff suppressed because it is too large Load Diff