From 1bf702cd991682cc554f405fb2b451af735bae85 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 26 Aug 2023 20:18:32 -0500 Subject: [PATCH] decent-looking noise --- front/index.js | 4 ++-- pirates/src/lib.rs | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/front/index.js b/front/index.js index 1637704..78bc873 100644 --- a/front/index.js +++ b/front/index.js @@ -1,8 +1,8 @@ var ctx; var image; var memory; -const width = 80; -const height = 60; +const width = 160; +const height = 144; function blit_frame() { ctx.putImageData(image, 0, 0); diff --git a/pirates/src/lib.rs b/pirates/src/lib.rs index a17b5f5..b3338c1 100644 --- a/pirates/src/lib.rs +++ b/pirates/src/lib.rs @@ -25,8 +25,8 @@ fn draw_text(text: &str, x: i32, y: i32, size: u8) { } } -const WIDTH: usize = 80; -const HEIGHT: usize = 60; +const WIDTH: usize = 160; +const HEIGHT: usize = 144; #[no_mangle] static mut BUFFER: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT]; @@ -55,13 +55,18 @@ fn render_frame(buffer: &mut [u32; WIDTH*HEIGHT]) { for y in 0..HEIGHT { for x in 0..WIDTH { - let point = Vector2::new((x+frame as usize) as f32,y as f32)*100.0; - let mut n = noise::noise(point / 600.0, rand) * 2.0; - n += noise::noise(point / 300.0, rand) * 1.0; - n += noise::noise(point / 150.0, rand) * 0.5; - n += noise::noise(point / 75.0, rand) * 0.25; - n += noise::noise(point / 37.5, rand) * 0.125; - buffer[y*WIDTH + x] = (((n*0.5+0.5)*256.0) as u32) << 16| 0xFF005000; + let point = Vector2::new((x+frame as usize) as f32,y as f32)* 2.0; + let mut n = 0.0; + n += noise::noise(point / 64.0, rand) / 1.0; + n += noise::noise(point / 32.0, rand) / 2.0; + n += noise::noise(point / 16.0, rand) / 4.0; + n += noise::noise(point / 8.0, rand) / 8.0; + //buffer[y*WIDTH + x] = (((n*0.5+0.5)*256.0) as u32) << 16| 0xFF005000; + buffer[y*WIDTH + x] = if n > 0.02 { + 0xFF00FF00 + } else { + 0xFFFF0000 + } } } unsafe { blit_frame(); } @@ -122,7 +127,7 @@ mod noise { let y = p.y as usize % width; let one = b[x*width + y] as f32; - let two = b[x*width + y + 256] as f32; + let two = b[(x*width + y + 1)%512] as f32; Vector2::new(one, two).normalize() }