1pub mod colour;
2pub mod gradient;
3
4pub use colour::*;
5pub use gradient::*;
6
7#[cfg(test)]
8mod tests {
9
10 #[cfg(feature = "image-tests")]
11 use color_eyre::eyre::Result;
12
13 #[cfg(feature = "image-tests")]
14 #[test]
15 pub fn with_noise_test() -> Result<()> {
16 use crate::{BlendMode, Colour, Gradient};
17 use fastnoise_lite::{FastNoiseLite, FractalType, NoiseType};
18 use image::{ImageFormat, Rgba, RgbaImage};
19
20 let mut galaxy_noise = FastNoiseLite::with_seed(0xbeefddd);
21 galaxy_noise.noise_type = NoiseType::OpenSimplex2S;
22 galaxy_noise.fractal_type = FractalType::FBm;
23 galaxy_noise.octaves = 6;
24 galaxy_noise.gain = 0.7f32;
25 galaxy_noise.lacunarity = 2f32;
26 galaxy_noise.frequency = 0.7f32;
27
28 let galaxy_gradient = Gradient(vec![
29 (-1f64, Colour::solid(0f64, 0f64, 0.02f64)), (-0.1f64, Colour::solid(0.04f64, 0.04f64, 0.08f64)), (0.3f64, Colour::solid(0.1f64, 0.08f64, 0.24f64)), (0.6f64, Colour::solid(0.20f64, 0.08f64, 0.45f64)), (0.75f64, Colour::solid(0.40f64, 0.12f64, 0.55f64)), (0.7f64, Colour::solid(0.55f64, 0.20f64, 0.65f64)), (0.9f64, Colour::solid(0.65f64, 0.30f64, 0.75f64)), (1f64, Colour::solid(0.65f64, 0.40f64, 0.80f64)), ]);
38
39 let mut star_noise = FastNoiseLite::with_seed(0xbeefaaa);
40 star_noise.noise_type = NoiseType::ValueCubic;
41 star_noise.fractal_type = FractalType::FBm;
42 star_noise.octaves = 4;
43 star_noise.gain = 1.0f32;
44 star_noise.lacunarity = 4f32;
45 star_noise.frequency = 2f32;
46
47 let star_gradient = Gradient(vec![
48 (0.95f64, Colour::transparent()),
49 (0.975f64, Colour::solid(0.9f64, 0.9f64, 1.0f64)), (0.9875f64, Colour::solid(1.0f64, 0.95f64, 0.9f64)), (1.0f64, Colour::solid(1.0f64, 1.0f64, 1.0f64)), ]);
54
55 let mut image = RgbaImage::new(512, 512);
56 for y in 0..image.height() {
57 for x in 0..image.width() {
58 image.put_pixel(
59 x,
60 y,
61 Rgba(
62 galaxy_gradient
63 .sample(
64 galaxy_noise.get_noise_2d(x as f32 / 512f32, y as f32 / 512f32)
65 as f64,
66 )
67 .blend(
68 star_gradient.sample(
69 star_noise.get_noise_2d(x as f32 / 512f32, y as f32 / 512f32)
70 as f64,
71 ),
72 BlendMode::HardLight,
73 )
74 .into(),
75 ),
76 );
77 }
78 }
79 image.save_with_format("test/noise.png", ImageFormat::Png)?;
80 Ok(())
81 }
82}