2022-02-20 17:23:37 +00:00
|
|
|
use noise::{NoiseFn, Seedable, SuperSimplex, Turbulence};
|
2019-10-16 11:39:41 +00:00
|
|
|
|
2019-06-25 15:59:09 +00:00
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
const W: usize = 640;
|
|
|
|
const H: usize = 640;
|
|
|
|
|
|
|
|
fn main() {
|
2019-06-26 00:27:41 +00:00
|
|
|
let mut win = minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap();
|
2019-06-25 15:59:09 +00:00
|
|
|
|
2022-02-20 17:23:37 +00:00
|
|
|
let nz = Turbulence::new(
|
|
|
|
Turbulence::new(SuperSimplex::new())
|
|
|
|
.set_frequency(0.2)
|
|
|
|
.set_power(1.5),
|
|
|
|
)
|
|
|
|
.set_frequency(2.0)
|
|
|
|
.set_power(0.2);
|
|
|
|
|
2019-10-16 11:39:41 +00:00
|
|
|
let _nz_x = SuperSimplex::new().set_seed(0);
|
|
|
|
let _nz_y = SuperSimplex::new().set_seed(1);
|
2019-06-25 15:59:09 +00:00
|
|
|
|
2019-12-09 09:50:14 +00:00
|
|
|
let mut _time = 0.0f64;
|
|
|
|
|
2022-02-20 17:23:37 +00:00
|
|
|
let mut scale = 50.0;
|
|
|
|
|
2019-06-25 15:59:09 +00:00
|
|
|
while win.is_open() {
|
|
|
|
let mut buf = vec![0; W * H];
|
|
|
|
|
|
|
|
for i in 0..W {
|
|
|
|
for j in 0..H {
|
2022-02-20 17:23:37 +00:00
|
|
|
let pos = Vec2::new(i as f64, j as f64) / scale;
|
2019-06-25 15:59:09 +00:00
|
|
|
|
2022-02-20 17:23:37 +00:00
|
|
|
let val = nz.get(pos.into_array());
|
2019-06-25 15:59:09 +00:00
|
|
|
|
|
|
|
buf[j * W + i] = u32::from_le_bytes([(val.max(0.0).min(1.0) * 255.0) as u8; 4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:23:37 +00:00
|
|
|
if win.is_key_pressed(minifb::Key::Right, minifb::KeyRepeat::No) {
|
|
|
|
scale *= 1.5;
|
|
|
|
} else if win.is_key_pressed(minifb::Key::Left, minifb::KeyRepeat::No) {
|
|
|
|
scale /= 1.5;
|
|
|
|
}
|
|
|
|
|
2020-12-16 00:07:39 +00:00
|
|
|
win.update_with_buffer(&buf, W, H).unwrap();
|
2019-06-25 15:59:09 +00:00
|
|
|
|
2019-12-09 09:50:14 +00:00
|
|
|
_time += 1.0 / 60.0;
|
2019-06-25 15:59:09 +00:00
|
|
|
}
|
|
|
|
}
|