Euphoria
palette_cubehelix.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "core/palette.h"
4 
5 
6 // original source: https://github.com/jiffyclub/palettable/blob/master/palettable/cubehelix/cubehelix.py
7 
8 /*
9 Copyright (c) 2014, James R. A. Davenport and contributors
10 All rights reserved.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14 
15 1. Redistributions of source code must retain the above copyright notice, this
16  list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright notice,
18  this list of conditions and the following disclaimer in the documentation
19  and/or other materials provided with the distribution.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
34 {
35  constexpr Rgbi
36  con(unsigned char r, unsigned char g, unsigned char b)
37  {
38  return {r, g, b};
39  }
40 
41  constexpr auto classic = make_static_palette
42  (
43  // dict(start=0.5, rotation=-1.5, gamma=1.0, sat=1.2,
44  // min_light=0., max_light=1., n=16)
45  "Classic",
46  con(0, 0, 0), con(22, 10, 34), con(24, 32, 68),
47  con(16, 62, 83), con(14, 94, 74), con(35, 116, 51),
48  con(80, 125, 35), con(138, 122, 45), con(190, 117, 85),
49  con(218, 121, 145), con(219, 138, 203), con(204, 167, 240),
50  con(191, 201, 251), con(195, 229, 244), con(220, 246, 239),
51  con(255, 255, 255)
52  );
53 
55  (
56  // Similar to Matteo Niccoli's Perceptual Rainbow:
57  // http://mycarta.wordpress.com/2013/02/21/perceptual-rainbow-palette-the-method/
58  // https://github.com/jradavenport/cubehelix
59  // dict(start_hue=240., end_hue=-300., min_sat=1., max_sat=2.5,
60  // min_light=0.3, max_light=0.8, gamma=.9, n=16)
61  "Perceptual_rainbow",
62  con(135, 59, 97), con(143, 64, 127), con(143, 72, 157),
63  con(135, 85, 185), con(121, 102, 207), con(103, 123, 220),
64  con(84, 146, 223), con(69, 170, 215), con(59, 192, 197),
65  con(60, 210, 172), con(71, 223, 145), con(93, 229, 120),
66  con(124, 231, 103), con(161, 227, 95), con(198, 220, 100),
67  con(233, 213, 117)
68  );
69 
70  constexpr auto purple = make_static_palette
71  (
72  // dict(start=0., rotation=0.0, n=16)
73  "Purple",
74  con(0, 0, 0), con(15, 14, 35), con(31, 28, 68),
75  con(47, 43, 99), con(63, 59, 127), con(79, 75, 152),
76  con(96, 91, 174), con(113, 107, 194), con(130, 124, 211),
77  con(147, 142, 225), con(164, 160, 237), con(182, 178, 246),
78  con(200, 196, 252), con(218, 215, 255), con(236, 235, 255),
79  con(255, 255, 255)
80  );
81 
83  (
84  // http://www.ifweassume.com/2014/04/cubehelix-colormap-for-python.html
85  // dict(start=0.3, rotation=-0.5, n=16)
86  "Jim_special",
87  con(0, 0, 0), con(22, 10, 34), con(37, 25, 68),
88  con(47, 43, 99), con(52, 65, 125), con(55, 88, 146),
89  con(59, 112, 160), con(64, 137, 169), con(74, 160, 173),
90  con(89, 181, 175), con(109, 199, 177), con(134, 214, 180),
91  con(163, 227, 189), con(195, 237, 203), con(226, 246, 225),
92  con(255, 255, 255)
93  );
94 
95  constexpr auto red = make_static_palette
96  (
97  // http://www.ifweassume.com/2014/04/cubehelix-colormap-for-python.html
98  // dict(start=0., rotation=0.5, n=16)
99  "Red",
100  con(0, 0, 0), con(19, 12, 35), con(44, 22, 65),
101  con(73, 32, 90), con(104, 41, 107), con(134, 53, 118),
102  con(162, 67, 124), con(185, 83, 126), con(204, 102, 128),
103  con(216, 124, 130), con(225, 148, 136), con(229, 172, 147),
104  con(232, 196, 164), con(236, 219, 189), con(242, 238, 219),
105  con(255, 255, 255)
106  );
107 
109  (
110  // http://nbviewer.ipython.org/gist/anonymous/a4fa0adb08f9e9ea4f94
111  // dict(gamma=1.0, start=1.5, rotation=-1.0, sat=1.5, n=16)
112  "Cubehelix1",
113  con(0, 0, 0), con(27, 15, 0), con(65, 23, 4),
114  con(104, 27, 32), con(133, 33, 75), con(147, 45, 126),
115  con(144, 66, 175), con(129, 96, 210), con(111, 131, 227),
116  con(99, 166, 226), con(101, 197, 211), con(120, 219, 194),
117  con(153, 233, 185), con(193, 240, 191), con(230, 245, 216),
118  con(255, 255, 255)
119  );
120 
122  (
123  // http://nbviewer.ipython.org/gist/anonymous/a4fa0adb08f9e9ea4f94
124  // dict(gamma=1.0, start=2.0, rotation=1.0, sat=1.5, n=16)
125  "Cubehelix2",
126  con(0, 0, 0), con(0, 28, 14), con(0, 51, 47),
127  con(7, 65, 91), con(35, 71, 135), con(78, 72, 168),
128  con(129, 72, 184), con(177, 77, 181), con(214, 90, 165),
129  con(235, 113, 143), con(238, 142, 128), con(230, 175, 127),
130  con(219, 206, 144), con(216, 231, 178), con(226, 247, 219),
131  con(255, 255, 255)
132  );
133 
135  (
136  // http://nbviewer.ipython.org/gist/anonymous/a4fa0adb08f9e9ea4f94
137  // dict(gamma=1.0, start=2.0, rotation=1.0, sat=3, n=16)
138  "Cubehelix3",
139  con(0, 0, 0), con(0, 39, 12), con(0, 68, 60),
140  con(0, 80, 131), con(3, 75, 202), con(72, 60, 252),
141  con(156, 43, 255), con(235, 36, 244), con(255, 45, 194),
142  con(255, 73, 134), con(255, 115, 86), con(255, 164, 67),
143  con(235, 209, 85), con(211, 241, 135), con(215, 255, 200),
144  con(255, 255, 255)
145  );
146 
147 
148 }
constexpr Rgbi con(unsigned char r, unsigned char g, unsigned char b)
constexpr StaticPalette< sizeof...(T)> make_static_palette(const std::string_view &name, T... colors)
Definition: palette.h:92
Definition: rgb.h:26