draw basic function
All checks were successful
CI / Rust project (push) Successful in 1m5s

This commit is contained in:
fabolous005 2023-11-26 19:45:49 +01:00
parent d2c5e120b4
commit c911014e9e
3 changed files with 42 additions and 16 deletions

View File

@ -8,3 +8,4 @@ edition = "2021"
[dependencies] [dependencies]
image = "0.24.7" image = "0.24.7"
rand = "0.8.5" rand = "0.8.5"
num_cpus = "1.16.0"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 KiB

After

Width:  |  Height:  |  Size: 845 KiB

View File

@ -1,5 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::env;
use rand::Rng; use rand::Rng;
use image::Rgb; use image::Rgb;
use image::RgbImage; use image::RgbImage;
@ -7,31 +8,54 @@ use image::ImageBuffer;
fn main() { fn main() {
let width = 6500; let args: Vec<String> = env::args().collect();
let height = 6500;
let _num_chunks = args.get(1)
.and_then(|arg: &String| arg.parse::<usize>().ok())
.unwrap_or(num_cpus::get());
let width = 7000;
let height = 7000;
let mut img = get_image(width, height); let mut img = get_image(width, height);
// let mut colors= vec![]; let mut colors= vec![];
let mut points = vec![]; let mut points = vec![];
for i in 0..=1000 { // for i in 0..=10000 {
points.push(i as f64 / 1000.0); // points.push(i as f64 / 10000.0);
points.push(-(i as f64 / 1000.0)); // // points.push(-(i as f64 / 10000.0));
// }
let step = 0.001; // Define the step size
let mut current_value = 0.0;
while current_value <= 1.8 {
points.push(current_value);
current_value += step;
} }
// funktion = f(x) = 3x^2 // funktion = f(x) = 3x^2
// ableitungsquotient = 6a // ableitungsquotient = 6a
let color = [
generate_random(0, 255),
generate_random(0, 255),
generate_random(0, 255)
];
colors.push(color);
for point in points { for point in points {
// let color = [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]; let x = (point * 1000.0_f64).round() as u32;
// colors.push(color); let y = (get_point(point) * 1000.0).round() as u32;
// img.put_pixel((point * 1000.0_f64).round() as u32, (get_point(point as i32) * 1000.0).round() as u32, Rgb(color));
img.put_pixel( img.put_pixel(
(point * 1000.0_f64).round() as u32 + (width / 2), x + width / 2,
(get_point(point) * 1000.0).round() as u32 + (height / 2), y + height / 2,
Rgb([255,255,255]) Rgb(color)
); );
img.put_pixel(
x + width / 2 - x * 2,
y + height / 2,
Rgb(color)
);
} }
@ -44,7 +68,8 @@ fn get_pitch_quotient() -> u32 {
} }
fn get_point(x: f64) -> f64 { fn get_point(x: f64) -> f64 {
3.0 * x.powf(2.0) // 3.0 * x.powf(2.0)
x.powf(2.0)
} }
@ -57,7 +82,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 = 50;
let grid_color = Rgb([255, 9, 255]); // Black colo 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) {
for y in 0..height { for y in 0..height {