Skip to main content

mandelbruhst_cli/
config.rs

1use crate::mandelbrot::Complex;
2use crate::palette::ColorPalette;
3use crate::palette::ConfigRGB;
4use anyhow::{anyhow, Result};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Debug, Serialize, Deserialize)]
9pub struct Configuration {
10    pub color_palettes: HashMap<String, ColorPalette>,
11    pub named_points: HashMap<String, NamedPoint>,
12}
13
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct NamedPoint {
16    pub point: Complex,
17    pub zoom: usize,
18}
19
20impl Configuration {
21    pub fn get_palette(&self, name: &str) -> Result<&ColorPalette> {
22        self.color_palettes
23            .get(name)
24            .ok_or(anyhow!(format!("palette {} in palettes", name)))
25    }
26
27    pub fn get_named_point(&self, name: &str) -> Result<&NamedPoint> {
28        self.named_points
29            .get(name)
30            .ok_or(anyhow!(format!("point {} not in points", name)))
31    }
32}
33
34// don't fucking look here, for your own good
35impl Default for Configuration {
36    fn default() -> Self {
37        let color_palettes = HashMap::from_iter([
38            (
39                "greyscale".into(),
40                ColorPalette {
41                    color_vals: vec![
42                        ConfigRGB {
43                            value: 0.0,
44                            red: 0,
45                            green: 0,
46                            blue: 0,
47                        },
48                        ConfigRGB {
49                            value: 1.0,
50                            red: 255,
51                            green: 255,
52                            blue: 255,
53                        },
54                    ],
55                },
56            ),
57            (
58                "electric".into(),
59                ColorPalette {
60                    color_vals: vec![
61                        ConfigRGB {
62                            value: 0.0,
63                            red: 0,
64                            green: 18,
65                            blue: 25,
66                        },
67                        ConfigRGB {
68                            value: 0.1,
69                            red: 0,
70                            green: 18,
71                            blue: 25,
72                        },
73                        ConfigRGB {
74                            value: 0.5,
75                            red: 20,
76                            green: 33,
77                            blue: 61,
78                        },
79                        ConfigRGB {
80                            value: 0.8,
81                            red: 252,
82                            green: 163,
83                            blue: 17,
84                        },
85                        ConfigRGB {
86                            value: 0.9,
87                            red: 229,
88                            green: 229,
89                            blue: 229,
90                        },
91                        ConfigRGB {
92                            value: 0.9999,
93                            red: 255,
94                            green: 255,
95                            blue: 255,
96                        },
97                        ConfigRGB {
98                            value: 1.0,
99                            red: 0,
100                            green: 0,
101                            blue: 0,
102                        },
103                    ],
104                },
105            ),
106            (
107                "warm".into(),
108                ColorPalette {
109                    color_vals: vec![
110                        ConfigRGB {
111                            value: 0.0,
112                            red: 0,
113                            green: 18,
114                            blue: 25,
115                        },
116                        ConfigRGB {
117                            value: 0.1,
118                            red: 0,
119                            green: 18,
120                            blue: 25,
121                        },
122                        ConfigRGB {
123                            value: 0.3,
124                            red: 10,
125                            green: 147,
126                            blue: 150,
127                        },
128                        ConfigRGB {
129                            value: 0.6,
130                            red: 233,
131                            green: 216,
132                            blue: 166,
133                        },
134                        ConfigRGB {
135                            value: 0.92,
136                            red: 174,
137                            green: 32,
138                            blue: 18,
139                        },
140                        ConfigRGB {
141                            value: 1.0,
142                            red: 0,
143                            green: 0,
144                            blue: 0,
145                        },
146                    ],
147                },
148            ),
149        ]);
150
151        let named_points = HashMap::from_iter([
152            (
153                "capillary".into(),
154                NamedPoint {
155                    point: Complex {
156                        re: -0.0452407411,
157                        im: 0.9868162204352258,
158                    },
159                    zoom: 51200000,
160                },
161            ),
162            (
163                "chloro-zoom".into(),
164                NamedPoint {
165                    point: Complex {
166                        re: 0.281717921930775,
167                        im: 0.5771052841488505,
168                    },
169                    zoom: 102400000000,
170                },
171            ),
172            (
173                "chlorophyll".into(),
174                NamedPoint {
175                    point: Complex {
176                        re: 0.281717921930775,
177                        im: 0.5771052841488505,
178                    },
179                    zoom: 25600000000,
180                },
181            ),
182            (
183                "circle".into(),
184                NamedPoint {
185                    point: Complex {
186                        re: 0.432539867562512,
187                        im: 0.226118675951765,
188                    },
189                    zoom: 25000000000000,
190                },
191            ),
192            (
193                "divergence".into(),
194                NamedPoint {
195                    point: Complex {
196                        re: 0.2549870375144766,
197                        im: -0.0005679790528465,
198                    },
199                    zoom: 200000,
200                },
201            ),
202            (
203                "doubletentacle".into(),
204                NamedPoint {
205                    point: Complex {
206                        re: -0.745428,
207                        im: 0.113009,
208                    },
209                    zoom: 400000,
210                },
211            ),
212            (
213                "knife".into(),
214                NamedPoint {
215                    point: Complex {
216                        re: -1.25066,
217                        im: 0.02012,
218                    },
219                    zoom: 75000,
220                },
221            ),
222            (
223                "spiral".into(),
224                NamedPoint {
225                    point: Complex {
226                        re: -0.7771204433106587,
227                        im: 0.1268572387863619,
228                    },
229                    zoom: 20000,
230                },
231            ),
232            (
233                "splotches".into(),
234                NamedPoint {
235                    point: Complex {
236                        re: -0.74529,
237                        im: 0.113075,
238                    },
239                    zoom: 80000,
240                },
241            ),
242            (
243                "tendril".into(),
244                NamedPoint {
245                    point: Complex {
246                        re: -0.235125,
247                        im: 0.827215,
248                    },
249                    zoom: 260000,
250                },
251            ),
252            (
253                "tentacle".into(),
254                NamedPoint {
255                    point: Complex {
256                        re: -0.7453,
257                        im: 0.1127,
258                    },
259                    zoom: 10000,
260                },
261            ),
262            (
263                "tilt".into(),
264                NamedPoint {
265                    point: Complex {
266                        re: -0.16,
267                        im: 1.035,
268                    },
269                    zoom: 900,
270                },
271            ),
272            (
273                "tilt-zoom-out".into(),
274                NamedPoint {
275                    point: Complex {
276                        re: -0.16,
277                        im: 1.035,
278                    },
279                    zoom: 700,
280                },
281            ),
282            (
283                "void".into(),
284                NamedPoint {
285                    point: Complex {
286                        re: -1.25066,
287                        im: 0.02012,
288                    },
289                    zoom: 200000,
290                },
291            ),
292        ]);
293
294        Self {
295            color_palettes,
296            named_points,
297        }
298    }
299}