Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
walker84837 committed Jan 14, 2024
1 parent b1ecaf8 commit d2f8452
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 41 deletions.
282 changes: 282 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 4 additions & 41 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ struct Opt {
#[arg(short, long, help = "Calculates the sRGB distance between two colors")]
distance: bool,

#[structopt(short, long, help = "Output file path")]
output: Option<PathBuf>,

#[structopt(short, long, help = "Calculates the sRGB distance between two colors")]
distance: bool,

#[structopt(short, long, help = "Prints the time it took to blend colors")]
#[arg(short, long, help = "Prints the time it took to blend colors")]
benchmark: bool,
}

Expand All @@ -47,11 +41,10 @@ fn main() -> Result<()> {
let second_color = opt.second_color.to_string();

let blender = ColorBlender::new(first_color, second_color, opt.midpoints);
let mut colors: Vec<String> = Vec::new();

if opt.benchmark {
let start_time = Instant::now();
colors = blender.blend_colors();
let colors: Vec<String> = blender.blend_colors();
let end_time = Instant::now();

let elapsed_time = end_time - start_time;
Expand All @@ -76,37 +69,6 @@ fn main() -> Result<()> {
let (r, g, b) = lastcolors;
let last_colors = (r as f32, g as f32, b as f32);

let num_iterations = &opt.midpoints;

let start_time = Instant::now();
colors = blender.blend_colors();
let end_time = Instant::now();

let elapsed_time = end_time - start_time;
let avg_time_per_iteration = (elapsed_time / *num_iterations as u32).as_nanos();

for color in &colors {
println!("{}", color);
}

println!("Elapsed time: {}μs", elapsed_time.as_micros());
println!("Average time per iteration: {}ns", avg_time_per_iteration);
return Ok(());
}


if opt.distance {
let firstcolors = ColorConverter::hex_to_rgb(&opt.first_color)?;
let lastcolors = ColorConverter::hex_to_rgb(&opt.second_color)?;

let first_colors = match firstcolors {
(r, g, b) => (r as f32, g as f32, b as f32),
};

let last_colors = match lastcolors {
(r, g, b) => (r as f32, g as f32, b as f32),
};

let distance = color_difference(first_colors, last_colors);

println!("Distance: {distance}");
Expand All @@ -127,7 +89,7 @@ fn main() -> Result<()> {
}


colors = blender.blend_colors();
let colors: Vec<String> = blender.blend_colors();

match opt.output {
Some(path) => {
Expand All @@ -143,6 +105,7 @@ fn main() -> Result<()> {
}
}
};

Ok(())
}

Expand Down

0 comments on commit d2f8452

Please sign in to comment.