Compare commits
2 Commits
132dfaa770
...
3a6ee835df
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a6ee835df | |||
| 5cd8fda72e |
@ -6,7 +6,7 @@ Génère pour tous les $(n, m)$ les figures de Chladni associées. Sortie en `.p
|
||||
Modifier les bornes de $(n, m)$ dans `main.rs`.
|
||||
|
||||
### Équation :
|
||||
$$\cos(n\pi x)\cos(m\pi y) - \cos(m\pi x)\cos(n\pi y)$$
|
||||
$$\cos(n\pi x)\cos(m\pi y) \pm \cos(m\pi x)\cos(n\pi y)$$
|
||||
|
||||
### Lancement
|
||||
Release pour que ce soit rapide.
|
||||
|
||||
15
src/main.rs
15
src/main.rs
@ -2,11 +2,11 @@ use image::{ImageBuffer, Rgba, RgbaImage};
|
||||
use std::f64::consts::PI;
|
||||
use std::fs;
|
||||
|
||||
fn chladni(x: f64, y: f64, n: f64, m: f64) -> f64 {
|
||||
fn chladni(x: f64, y: f64, n: f64, m: f64, eps: f64) -> f64 {
|
||||
(n * PI * x).cos() * (m * PI * y).cos() - (m * PI * x).cos() * (n * PI * y).cos()
|
||||
}
|
||||
|
||||
fn generate_png(n: u32, m: u32, width: u32, height: u32) {
|
||||
fn generate_png(n: u32, m: u32, width: u32, height: u32, eps: f64) {
|
||||
let mut img: RgbaImage = ImageBuffer::new(width, height);
|
||||
|
||||
for (x, y, pixel) in img.enumerate_pixels_mut() {
|
||||
@ -14,7 +14,7 @@ fn generate_png(n: u32, m: u32, width: u32, height: u32) {
|
||||
let xf = (x as f64 / width as f64) * 2.0 - 1.0;
|
||||
let yf = (y as f64 / height as f64) * 2.0 - 1.0;
|
||||
|
||||
let val = chladni(xf, yf, n as f64, m as f64);
|
||||
let val = chladni(xf, yf, n as f64, m as f64, eps);
|
||||
let intensity = val.abs();
|
||||
|
||||
let bright = (((0.08 - intensity).max(0.0) / 0.08) * 255.0) as u8;
|
||||
@ -22,7 +22,7 @@ fn generate_png(n: u32, m: u32, width: u32, height: u32) {
|
||||
// *pixel = Rgb([brigh, brigh, brigh]);
|
||||
}
|
||||
|
||||
let filename = format!("out/chladni_{}_{}.png", n, m);
|
||||
let filename = format!("out/chladni_{}_{}_{}.png", n, m, eps);
|
||||
img.save(&filename).unwrap();
|
||||
println!("{}", filename);
|
||||
}
|
||||
@ -30,14 +30,15 @@ fn generate_png(n: u32, m: u32, width: u32, height: u32) {
|
||||
fn main() {
|
||||
let width = 1000;
|
||||
let height = 1000;
|
||||
let max_n = 6;
|
||||
let max_m = 6;
|
||||
let max_n = 5;
|
||||
let max_m = 5;
|
||||
|
||||
fs::create_dir_all("out").expect("Erreur");
|
||||
|
||||
for n in 1..max_n {
|
||||
for m in 1..max_m {
|
||||
generate_png(n, m, width, height);
|
||||
generate_png(n, m, width, height, -1.0);
|
||||
generate_png(n, m, width, height, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user