mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
use noise::{NoiseFn, Perlin, SuperSimplex, Turbulence};
|
|
|
|
use vek::*;
|
|
|
|
const W: usize = 640;
|
|
const H: usize = 640;
|
|
|
|
fn main() {
|
|
let mut win = minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap();
|
|
|
|
let nz: Turbulence<Turbulence<SuperSimplex, Perlin>, Perlin> = Turbulence::new(
|
|
Turbulence::new(SuperSimplex::new(0))
|
|
.set_frequency(0.2)
|
|
.set_power(1.5),
|
|
)
|
|
.set_frequency(2.0)
|
|
.set_power(0.2);
|
|
|
|
let _nz_x = SuperSimplex::new(0);
|
|
let _nz_y = SuperSimplex::new(1);
|
|
|
|
let mut _time = 0.0f64;
|
|
|
|
let mut scale = 50.0;
|
|
|
|
while win.is_open() {
|
|
let mut buf = vec![0; W * H];
|
|
|
|
for i in 0..W {
|
|
for j in 0..H {
|
|
let pos = Vec2::new(i as f64, j as f64) / scale;
|
|
|
|
let val = nz.get(pos.into_array());
|
|
|
|
buf[j * W + i] = u32::from_le_bytes([(val.clamp(0.0, 1.0) * 255.0) as u8; 4]);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
win.update_with_buffer(&buf, W, H).unwrap();
|
|
|
|
_time += 1.0 / 60.0;
|
|
}
|
|
}
|