1use araea_wordcloud::{ColorScheme, MaskShape, WordCloudBuilder, WordInput};
2use std::fs;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let output_path = "output_mask_heart.png";
6
7 let width = 800;
8 let height = 800;
9
10 println!("Generating words...");
11 let mut words = Vec::new();
12 for i in 0..300 {
13 words.push(WordInput::new("Love", 100.0));
14 words.push(WordInput::new("Rust", 80.0));
15 words.push(WordInput::new("Heart", 60.0 + (i as f32 % 40.0)));
16 words.push(WordInput::new("Mask", 40.0));
17 }
18
19 println!("Building word cloud...");
20
21 let scheme = ColorScheme::Default;
22 let wordcloud = WordCloudBuilder::new()
23 .size(width, height)
24 .mask_preset(MaskShape::Heart)
25 .color_scheme(scheme)
26 .background(scheme.background_color())
27 .padding(2)
28 .word_spacing(2.0)
29 .font_size_range(12.0, 80.0)
30 .build(&words)?;
31
32 println!("Saving to {}...", output_path);
33 fs::write(output_path, wordcloud.to_png(2.0)?)?;
34
35 println!("Done! Check {}", output_path);
36 Ok(())
37}