1 use crate::gradient::EvalGradient;
2 use crate::{interpolate, Color, Gradient};
3 
4 #[derive(Copy, Clone)]
5 struct Diverging {
6     name: &'static str,
7     three: [Color; 3],
8     four: [Color; 4],
9     five: [Color; 5],
10     six: [Color; 6],
11     seven: [Color; 7],
12     eight: [Color; 8],
13     nine: [Color; 9],
14     ten: [Color; 10],
15     eleven: [Color; 11],
16 }
17 
18 impl EvalGradient for Diverging {
name(&self) -> &'static str19     fn name(&self) -> &'static str {
20         self.name
21     }
22 
eval_rational(&self, i: usize, n: usize) -> Color23     fn eval_rational(&self, i: usize, n: usize) -> Color {
24         match n {
25             0 | 1 => self.three[2],
26             2 => self.three[i * 2],
27             3 => self.three[i],
28             4 => self.four[i],
29             5 => self.five[i],
30             6 => self.six[i],
31             7 => self.seven[i],
32             8 => self.eight[i],
33             9 => self.nine[i],
34             10 => self.ten[i],
35             11 => self.eleven[i],
36             _ => self.eval_continuous(i as f64 / (n - 1) as f64),
37         }
38     }
39 
eval_continuous(&self, t: f64) -> Color40     fn eval_continuous(&self, t: f64) -> Color {
41         interpolate::spline(&self.eleven, t)
42     }
43 }
44 
45 /// ​
46 ///
47 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/BrBG.png" width="100%" height="40" alt="BrBG">
48 pub const BROWN_GREEN: Gradient = Gradient {
49     eval: &Diverging {
50         name: "BrBG",
51         three: colors!(0xd8b365 0xf5f5f5 0x5ab4ac),
52         four: colors!(0xa6611a 0xdfc27d 0x80cdc1 0x018571),
53         five: colors!(0xa6611a 0xdfc27d 0xf5f5f5 0x80cdc1 0x018571),
54         six: colors!(0x8c510a 0xd8b365 0xf6e8c3 0xc7eae5 0x5ab4ac 0x01665e),
55         seven: colors!(0x8c510a 0xd8b365 0xf6e8c3 0xf5f5f5 0xc7eae5 0x5ab4ac 0x01665e),
56         eight: colors!(0x8c510a 0xbf812d 0xdfc27d 0xf6e8c3 0xc7eae5 0x80cdc1 0x35978f 0x01665e),
57         nine: colors!(0x8c510a 0xbf812d 0xdfc27d 0xf6e8c3 0xf5f5f5 0xc7eae5 0x80cdc1 0x35978f 0x01665e),
58         ten: colors!(0x543005 0x8c510a 0xbf812d 0xdfc27d 0xf6e8c3 0xc7eae5 0x80cdc1 0x35978f 0x01665e 0x003c30),
59         eleven: colors!(0x543005 0x8c510a 0xbf812d 0xdfc27d 0xf6e8c3 0xf5f5f5 0xc7eae5 0x80cdc1 0x35978f 0x01665e 0x003c30),
60     },
61 };
62 
63 /// &#8203;
64 ///
65 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PRGn.png" width="100%" height="40" alt="PRGn">
66 pub const PURPLE_GREEN: Gradient = Gradient {
67     eval: &Diverging {
68         name: "PRGn",
69         three: colors!(0xaf8dc3 0xf7f7f7 0x7fbf7b),
70         four: colors!(0x7b3294 0xc2a5cf 0xa6dba0 0x008837),
71         five: colors!(0x7b3294 0xc2a5cf 0xf7f7f7 0xa6dba0 0x008837),
72         six: colors!(0x762a83 0xaf8dc3 0xe7d4e8 0xd9f0d3 0x7fbf7b 0x1b7837),
73         seven: colors!(0x762a83 0xaf8dc3 0xe7d4e8 0xf7f7f7 0xd9f0d3 0x7fbf7b 0x1b7837),
74         eight: colors!(0x762a83 0x9970ab 0xc2a5cf 0xe7d4e8 0xd9f0d3 0xa6dba0 0x5aae61 0x1b7837),
75         nine: colors!(0x762a83 0x9970ab 0xc2a5cf 0xe7d4e8 0xf7f7f7 0xd9f0d3 0xa6dba0 0x5aae61 0x1b7837),
76         ten: colors!(0x40004b 0x762a83 0x9970ab 0xc2a5cf 0xe7d4e8 0xd9f0d3 0xa6dba0 0x5aae61 0x1b7837 0x00441b),
77         eleven: colors!(0x40004b 0x762a83 0x9970ab 0xc2a5cf 0xe7d4e8 0xf7f7f7 0xd9f0d3 0xa6dba0 0x5aae61 0x1b7837 0x00441b),
78     },
79 };
80 
81 /// &#8203;
82 ///
83 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PiYG.png" width="100%" height="40" alt="PiYG">
84 pub const PINK_GREEN: Gradient = Gradient {
85     eval: &Diverging {
86         name: "PiYG",
87         three: colors!(0xe9a3c9 0xf7f7f7 0xa1d76a),
88         four: colors!(0xd01c8b 0xf1b6da 0xb8e186 0x4dac26),
89         five: colors!(0xd01c8b 0xf1b6da 0xf7f7f7 0xb8e186 0x4dac26),
90         six: colors!(0xc51b7d 0xe9a3c9 0xfde0ef 0xe6f5d0 0xa1d76a 0x4d9221),
91         seven: colors!(0xc51b7d 0xe9a3c9 0xfde0ef 0xf7f7f7 0xe6f5d0 0xa1d76a 0x4d9221),
92         eight: colors!(0xc51b7d 0xde77ae 0xf1b6da 0xfde0ef 0xe6f5d0 0xb8e186 0x7fbc41 0x4d9221),
93         nine: colors!(0xc51b7d 0xde77ae 0xf1b6da 0xfde0ef 0xf7f7f7 0xe6f5d0 0xb8e186 0x7fbc41 0x4d9221),
94         ten: colors!(0x8e0152 0xc51b7d 0xde77ae 0xf1b6da 0xfde0ef 0xe6f5d0 0xb8e186 0x7fbc41 0x4d9221 0x276419),
95         eleven: colors!(0x8e0152 0xc51b7d 0xde77ae 0xf1b6da 0xfde0ef 0xf7f7f7 0xe6f5d0 0xb8e186 0x7fbc41 0x4d9221 0x276419),
96     },
97 };
98 
99 /// &#8203;
100 ///
101 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/PuOr.png" width="100%" height="40" alt="PuOr">
102 pub const PURPLE_ORANGE: Gradient = Gradient {
103     eval: &Diverging {
104         name: "PuOr",
105         three: colors!(0x998ec3 0xf7f7f7 0xf1a340),
106         four: colors!(0x5e3c99 0xb2abd2 0xfdb863 0xe66101),
107         five: colors!(0x5e3c99 0xb2abd2 0xf7f7f7 0xfdb863 0xe66101),
108         six: colors!(0x542788 0x998ec3 0xd8daeb 0xfee0b6 0xf1a340 0xb35806),
109         seven: colors!(0x542788 0x998ec3 0xd8daeb 0xf7f7f7 0xfee0b6 0xf1a340 0xb35806),
110         eight: colors!(0x542788 0x8073ac 0xb2abd2 0xd8daeb 0xfee0b6 0xfdb863 0xe08214 0xb35806),
111         nine: colors!(0x542788 0x8073ac 0xb2abd2 0xd8daeb 0xf7f7f7 0xfee0b6 0xfdb863 0xe08214 0xb35806),
112         ten: colors!(0x2d004b 0x542788 0x8073ac 0xb2abd2 0xd8daeb 0xfee0b6 0xfdb863 0xe08214 0xb35806 0x7f3b08),
113         eleven: colors!(0x2d004b 0x542788 0x8073ac 0xb2abd2 0xd8daeb 0xf7f7f7 0xfee0b6 0xfdb863 0xe08214 0xb35806 0x7f3b08),
114     },
115 };
116 
117 /// &#8203;
118 ///
119 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdBu.png" width="100%" height="40" alt="RdBu">
120 pub const RED_BLUE: Gradient = Gradient {
121     eval: &Diverging {
122         name: "RdBu",
123         three: colors!(0xef8a62 0xf7f7f7 0x67a9cf),
124         four: colors!(0xca0020 0xf4a582 0x92c5de 0x0571b0),
125         five: colors!(0xca0020 0xf4a582 0xf7f7f7 0x92c5de 0x0571b0),
126         six: colors!(0xb2182b 0xef8a62 0xfddbc7 0xd1e5f0 0x67a9cf 0x2166ac),
127         seven: colors!(0xb2182b 0xef8a62 0xfddbc7 0xf7f7f7 0xd1e5f0 0x67a9cf 0x2166ac),
128         eight: colors!(0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xd1e5f0 0x92c5de 0x4393c3 0x2166ac),
129         nine: colors!(0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xf7f7f7 0xd1e5f0 0x92c5de 0x4393c3 0x2166ac),
130         ten: colors!(0x67001f 0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xd1e5f0 0x92c5de 0x4393c3 0x2166ac 0x053061),
131         eleven: colors!(0x67001f 0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xf7f7f7 0xd1e5f0 0x92c5de 0x4393c3 0x2166ac 0x053061),
132     },
133 };
134 
135 /// &#8203;
136 ///
137 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdGy.png" width="100%" height="40" alt="RdGy">
138 pub const RED_GREY: Gradient = Gradient {
139     eval: &Diverging {
140         name: "RdGy",
141         three: colors!(0xef8a62 0xffffff 0x999999),
142         four: colors!(0xca0020 0xf4a582 0xbababa 0x404040),
143         five: colors!(0xca0020 0xf4a582 0xffffff 0xbababa 0x404040),
144         six: colors!(0xb2182b 0xef8a62 0xfddbc7 0xe0e0e0 0x999999 0x4d4d4d),
145         seven: colors!(0xb2182b 0xef8a62 0xfddbc7 0xffffff 0xe0e0e0 0x999999 0x4d4d4d),
146         eight: colors!(0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xe0e0e0 0xbababa 0x878787 0x4d4d4d),
147         nine: colors!(0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xffffff 0xe0e0e0 0xbababa 0x878787 0x4d4d4d),
148         ten: colors!(0x67001f 0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xe0e0e0 0xbababa 0x878787 0x4d4d4d 0x1a1a1a),
149         eleven: colors!(0x67001f 0xb2182b 0xd6604d 0xf4a582 0xfddbc7 0xffffff 0xe0e0e0 0xbababa 0x878787 0x4d4d4d 0x1a1a1a),
150     },
151 };
152 
153 /// &#8203;
154 ///
155 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdYlBu.png" width="100%" height="40" alt="RdYlBu">
156 pub const RED_YELLOW_BLUE: Gradient = Gradient {
157     eval: &Diverging {
158         name: "RdYlBu",
159         three: colors!(0xfc8d59 0xffffbf 0x91bfdb),
160         four: colors!(0xd7191c 0xfdae61 0xabd9e9 0x2c7bb6),
161         five: colors!(0xd7191c 0xfdae61 0xffffbf 0xabd9e9 0x2c7bb6),
162         six: colors!(0xd73027 0xfc8d59 0xfee090 0xe0f3f8 0x91bfdb 0x4575b4),
163         seven: colors!(0xd73027 0xfc8d59 0xfee090 0xffffbf 0xe0f3f8 0x91bfdb 0x4575b4),
164         eight: colors!(0xd73027 0xf46d43 0xfdae61 0xfee090 0xe0f3f8 0xabd9e9 0x74add1 0x4575b4),
165         nine: colors!(0xd73027 0xf46d43 0xfdae61 0xfee090 0xffffbf 0xe0f3f8 0xabd9e9 0x74add1 0x4575b4),
166         ten: colors!(0xa50026 0xd73027 0xf46d43 0xfdae61 0xfee090 0xe0f3f8 0xabd9e9 0x74add1 0x4575b4 0x313695),
167         eleven: colors!(0xa50026 0xd73027 0xf46d43 0xfdae61 0xfee090 0xffffbf 0xe0f3f8 0xabd9e9 0x74add1 0x4575b4 0x313695),
168     },
169 };
170 
171 /// &#8203;
172 ///
173 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/RdYlGn.png" width="100%" height="40" alt="RdYlGn">
174 pub const RED_YELLOW_GREEN: Gradient = Gradient {
175     eval: &Diverging {
176         name: "RdYlGn",
177         three: colors!(0xfc8d59 0xffffbf 0x91cf60),
178         four: colors!(0xd7191c 0xfdae61 0xa6d96a 0x1a9641),
179         five: colors!(0xd7191c 0xfdae61 0xffffbf 0xa6d96a 0x1a9641),
180         six: colors!(0xd73027 0xfc8d59 0xfee08b 0xd9ef8b 0x91cf60 0x1a9850),
181         seven: colors!(0xd73027 0xfc8d59 0xfee08b 0xffffbf 0xd9ef8b 0x91cf60 0x1a9850),
182         eight: colors!(0xd73027 0xf46d43 0xfdae61 0xfee08b 0xd9ef8b 0xa6d96a 0x66bd63 0x1a9850),
183         nine: colors!(0xd73027 0xf46d43 0xfdae61 0xfee08b 0xffffbf 0xd9ef8b 0xa6d96a 0x66bd63 0x1a9850),
184         ten: colors!(0xa50026 0xd73027 0xf46d43 0xfdae61 0xfee08b 0xd9ef8b 0xa6d96a 0x66bd63 0x1a9850 0x006837),
185         eleven: colors!(0xa50026 0xd73027 0xf46d43 0xfdae61 0xfee08b 0xffffbf 0xd9ef8b 0xa6d96a 0x66bd63 0x1a9850 0x006837),
186     },
187 };
188 
189 /// &#8203;
190 ///
191 /// <img src="https://raw.githubusercontent.com/dtolnay/colorous/readme/Spectral.png" width="100%" height="40" alt="Spectral">
192 pub const SPECTRAL: Gradient = Gradient {
193     eval: &Diverging {
194         name: "Spectral",
195         three: colors!(0xfc8d59 0xffffbf 0x99d594),
196         four: colors!(0xd7191c 0xfdae61 0xabdda4 0x2b83ba),
197         five: colors!(0xd7191c 0xfdae61 0xffffbf 0xabdda4 0x2b83ba),
198         six: colors!(0xd53e4f 0xfc8d59 0xfee08b 0xe6f598 0x99d594 0x3288bd),
199         seven: colors!(0xd53e4f 0xfc8d59 0xfee08b 0xffffbf 0xe6f598 0x99d594 0x3288bd),
200         eight: colors!(0xd53e4f 0xf46d43 0xfdae61 0xfee08b 0xe6f598 0xabdda4 0x66c2a5 0x3288bd),
201         nine: colors!(0xd53e4f 0xf46d43 0xfdae61 0xfee08b 0xffffbf 0xe6f598 0xabdda4 0x66c2a5 0x3288bd),
202         ten: colors!(0x9e0142 0xd53e4f 0xf46d43 0xfdae61 0xfee08b 0xe6f598 0xabdda4 0x66c2a5 0x3288bd 0x5e4fa2),
203         eleven: colors!(0x9e0142 0xd53e4f 0xf46d43 0xfdae61 0xfee08b 0xffffbf 0xe6f598 0xabdda4 0x66c2a5 0x3288bd 0x5e4fa2),
204     },
205 };
206