init chladni
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
src/target
|
||||||
|
out
|
||||||
1016
Cargo.lock
generated
Normal file
1016
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "chladni"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
image = "0.25.9"
|
||||||
38
src/main.rs
Normal file
38
src/main.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use image::{ImageBuffer, Rgb, RgbImage};
|
||||||
|
use std::f64::consts::PI;
|
||||||
|
|
||||||
|
fn chladni(x: f64, y: f64, n: f64, m: 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) {
|
||||||
|
let mut img: RgbImage = ImageBuffer::new(width, height);
|
||||||
|
|
||||||
|
for (x, y, pixel) in img.enumerate_pixels_mut() {
|
||||||
|
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 intensity = val.abs();
|
||||||
|
|
||||||
|
let brigh = (((0.08 - intensity).max(0.0) / 0.08) * 255.0) as u8;
|
||||||
|
*pixel = Rgb([brigh, brigh, brigh]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let filename = format!("chladni_{}_{}.png", n, m);
|
||||||
|
img.save(&filename).unwrap();
|
||||||
|
println!("{}", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let width = 1000;
|
||||||
|
let height = 1000;
|
||||||
|
let max_n = 6;
|
||||||
|
let max_m = 6;
|
||||||
|
|
||||||
|
for n in 1..max_n {
|
||||||
|
for m in 1..max_m {
|
||||||
|
generate_png(n, m, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user