Debian Codegraph @

examples/rainbow.rs

raw symbols SCIP
1 #[cfg(feature = "color")]
2 use colored::Color;
3 #[cfg(feature = "color")]
4 use rasciigraph::{plot_many_colored, Config};
5
6 #[cfg(feature = "color")]
7 fn main() {
8 // Generate concentric semi-circles
9 let mut data = vec![vec![]; 6];
10 for i in 0i64..6 {
11 for x in -40i64..=40 {
12 let v = if x >= -(40 - i) && x <= (40 - i) {
13 Some(((40 - i) as f64).powi(2) - (x as f64).powi(2))
14 .map(|v| v.sqrt() / 2.0)
15 .unwrap_or(f64::NAN)
16 } else {
17 f64::NAN
18 };
19 data[i as usize].push(v);
20 }
21 }
22
23 // Define the configuration
24 let config = Config::default()
25 .with_height(20)
26 .with_width(80)
27 .with_caption("Concentric Semi-Circles".to_string())
28 .with_caption_color(Color::Blue)
29 .with_axis_color(Color::Green)
30 .with_series_legends(vec!["gemini".into(), "chatgpt".into()])
31 .with_series_colors(vec![
32 Color::Red,
33 Color::Yellow,
34 Color::Green,
35 Color::Blue,
36 Color::Magenta,
37 Color::Cyan,
38 ]);
39
40 // Generate the plot
41 let result = plot_many_colored(data, config);
42
43 // Print the result
44 println!("{}", result);
45 }