From bf02a74234f18750045afe091fe623a4cbd43e4e Mon Sep 17 00:00:00 2001 From: zeefaad Date: Sat, 14 Feb 2026 14:16:27 +0100 Subject: [PATCH] ratio --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e63b590..536acff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use core::f64; use image::{ImageBuffer, Rgba, RgbaImage}; use std::f64::consts::PI; use std::fs; @@ -9,9 +10,11 @@ fn chladni(x: f64, y: f64, n: f64, m: f64, eps: f64) -> f64 { fn generate_png(n: u32, m: u32, width: u32, height: u32, eps: f64) { let mut img: RgbaImage = ImageBuffer::new(width, height); + let ratio = width as f64 / height as f64; + for (x, y, pixel) in img.enumerate_pixels_mut() { // Centrage - let xf = (x as f64 / width as f64) * 2.0 - 1.0; + let xf = ((x as f64 / width as f64) * 2.0 - 1.0) * ratio; let yf = (y as f64 / height as f64) * 2.0 - 1.0; let val = chladni(xf, yf, n as f64, m as f64, eps); @@ -30,10 +33,10 @@ fn generate_png(n: u32, m: u32, width: u32, height: u32, eps: f64) { } fn main() { - let width = 1000; - let height = 1000; - let max_n = 30; - let max_m = 30; + let width = 1920; + let height = 1080; + let max_n = 6; + let max_m = 6; fs::create_dir_all("out").expect("Erreur");