csci5607/assignment-0/src/main.rs

49 lines
918 B
Rust
Raw Normal View History

2023-01-21 08:03:11 +00:00
use std::{fs::File, path::PathBuf};
use anyhow::Result;
2023-01-21 08:22:22 +00:00
use clap::{Parser, ValueEnum};
use turbulence::generate_turbulence;
2023-01-21 08:03:11 +00:00
use crate::value_noise::generate_noise;
mod ppm;
2023-01-21 08:22:22 +00:00
mod turbulence;
2023-01-21 08:03:11 +00:00
mod value_noise;
mod vec2;
#[derive(Parser)]
struct Opt {
2023-01-21 08:22:22 +00:00
#[clap(long = "algorithm", default_value = "turbulence")]
algorithm: Algorithm,
#[clap(long = "size", default_value = "1024")]
size: usize,
#[clap(short = 'o', long = "out", default_value = "out.ppm")]
output_path: PathBuf,
}
#[derive(ValueEnum, Clone)]
enum Algorithm {
Noise,
Turbulence,
2023-01-21 08:03:11 +00:00
}
fn main() -> Result<()> {
2023-01-21 08:22:22 +00:00
let opt = Opt::parse();
2023-01-21 08:03:11 +00:00
2023-01-21 08:22:22 +00:00
let rng = rand::thread_rng();
2023-01-21 08:03:11 +00:00
2023-01-21 08:22:22 +00:00
let ppm = match opt.algorithm {
Algorithm::Noise => generate_noise(opt.size, opt.size, rng),
Algorithm::Turbulence => generate_turbulence(opt.size, opt.size, rng),
};
2023-01-21 08:03:11 +00:00
2023-01-21 08:22:22 +00:00
{
let file = File::create(opt.output_path)?;
ppm.write(file)?;
}
2023-01-21 08:03:11 +00:00
2023-01-21 08:22:22 +00:00
Ok(())
2023-01-21 08:03:11 +00:00
}