add clap + option for optimization
All checks were successful
CI / Rust project (push) Successful in 1m22s
All checks were successful
CI / Rust project (push) Successful in 1m22s
This commit is contained in:
parent
c911014e9e
commit
83b80c847b
@ -9,3 +9,4 @@ edition = "2021"
|
|||||||
image = "0.24.7"
|
image = "0.24.7"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
num_cpus = "1.16.0"
|
num_cpus = "1.16.0"
|
||||||
|
clap = { version = "4.4.8", features = ["derive"]}
|
||||||
|
|||||||
BIN
grid_image.png
BIN
grid_image.png
Binary file not shown.
|
Before Width: | Height: | Size: 845 KiB After Width: | Height: | Size: 774 KiB |
46
src/main.rs
46
src/main.rs
@ -1,18 +1,27 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::env;
|
use clap::Parser;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use image::Rgb;
|
use image::Rgb;
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
use image::ImageBuffer;
|
use image::ImageBuffer;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
#[derive(Parser)]
|
||||||
let args: Vec<String> = env::args().collect();
|
struct Args {
|
||||||
|
/// Optimization level
|
||||||
|
#[arg(short, default_value_t = 3)]
|
||||||
|
opt_level: u8,
|
||||||
|
|
||||||
let _num_chunks = args.get(1)
|
/// Number of cores [default: max]
|
||||||
.and_then(|arg: &String| arg.parse::<usize>().ok())
|
#[arg(short, value_name = "CORES")]
|
||||||
.unwrap_or(num_cpus::get());
|
core: Option<u8>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
let width = 7000;
|
let width = 7000;
|
||||||
let height = 7000;
|
let height = 7000;
|
||||||
@ -24,10 +33,14 @@ fn main() {
|
|||||||
// points.push(i as f64 / 10000.0);
|
// points.push(i as f64 / 10000.0);
|
||||||
// // points.push(-(i as f64 / 10000.0));
|
// // points.push(-(i as f64 / 10000.0));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let step = 0.001; // Define the step size
|
let mut step = "0.".to_string();
|
||||||
|
for _ in 0..args.opt_level {
|
||||||
|
step.push('0')
|
||||||
|
}
|
||||||
|
step.push('1');
|
||||||
|
let step: f64 = step.parse().unwrap();
|
||||||
let mut current_value = 0.0;
|
let mut current_value = 0.0;
|
||||||
|
|
||||||
while current_value <= 1.8 {
|
while current_value <= 1.8 {
|
||||||
points.push(current_value);
|
points.push(current_value);
|
||||||
current_value += step;
|
current_value += step;
|
||||||
@ -43,16 +56,17 @@ fn main() {
|
|||||||
];
|
];
|
||||||
colors.push(color);
|
colors.push(color);
|
||||||
for point in points {
|
for point in points {
|
||||||
let x = (point * 1000.0_f64).round() as u32;
|
// NOTE: convert later to u32 because deviding may change actual value
|
||||||
let y = (get_point(point) * 1000.0).round() as u32;
|
let x = point * 1000.0_f64;
|
||||||
|
let y = get_point(point) * 1000.0;
|
||||||
img.put_pixel(
|
img.put_pixel(
|
||||||
x + width / 2,
|
(width as f64 / 2.0 + x).round() as u32,
|
||||||
y + height / 2,
|
(height as f64 / 2.0 + y) as u32,
|
||||||
Rgb(color)
|
Rgb(color)
|
||||||
);
|
);
|
||||||
img.put_pixel(
|
img.put_pixel(
|
||||||
x + width / 2 - x * 2,
|
(width as f64 / 2.0 - x).round() as u32,
|
||||||
y + height / 2,
|
(height as f64 / 2.0 + y).round() as u32,
|
||||||
Rgb(color)
|
Rgb(color)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -81,7 +95,7 @@ fn generate_random(start: u8, end: u8) -> u8 {
|
|||||||
|
|
||||||
fn get_image(width: u32, height: u32) -> ImageBuffer<Rgb<u8>, Vec<u8>> {
|
fn get_image(width: u32, height: u32) -> ImageBuffer<Rgb<u8>, Vec<u8>> {
|
||||||
let mut img = RgbImage::new(width, height);
|
let mut img = RgbImage::new(width, height);
|
||||||
let grid_spacing = 50;
|
let grid_spacing = 100;
|
||||||
let grid_color = Rgb([255,9,255]);
|
let grid_color = Rgb([255,9,255]);
|
||||||
|
|
||||||
for x in (0..width).step_by(grid_spacing) {
|
for x in (0..width).step_by(grid_spacing) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user