decent-looking noise
This commit is contained in:
parent
3bc500c727
commit
1bf702cd99
2 changed files with 17 additions and 12 deletions
|
@ -1,8 +1,8 @@
|
||||||
var ctx;
|
var ctx;
|
||||||
var image;
|
var image;
|
||||||
var memory;
|
var memory;
|
||||||
const width = 80;
|
const width = 160;
|
||||||
const height = 60;
|
const height = 144;
|
||||||
|
|
||||||
function blit_frame() {
|
function blit_frame() {
|
||||||
ctx.putImageData(image, 0, 0);
|
ctx.putImageData(image, 0, 0);
|
||||||
|
|
|
@ -25,8 +25,8 @@ fn draw_text(text: &str, x: i32, y: i32, size: u8) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const WIDTH: usize = 80;
|
const WIDTH: usize = 160;
|
||||||
const HEIGHT: usize = 60;
|
const HEIGHT: usize = 144;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
static mut BUFFER: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
|
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 y in 0..HEIGHT {
|
||||||
for x in 0..WIDTH {
|
for x in 0..WIDTH {
|
||||||
let point = Vector2::new((x+frame as usize) as f32,y as f32)*100.0;
|
let point = Vector2::new((x+frame as usize) as f32,y as f32)* 2.0;
|
||||||
let mut n = noise::noise(point / 600.0, rand) * 2.0;
|
let mut n = 0.0;
|
||||||
n += noise::noise(point / 300.0, rand) * 1.0;
|
n += noise::noise(point / 64.0, rand) / 1.0;
|
||||||
n += noise::noise(point / 150.0, rand) * 0.5;
|
n += noise::noise(point / 32.0, rand) / 2.0;
|
||||||
n += noise::noise(point / 75.0, rand) * 0.25;
|
n += noise::noise(point / 16.0, rand) / 4.0;
|
||||||
n += noise::noise(point / 37.5, rand) * 0.125;
|
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] = (((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(); }
|
unsafe { blit_frame(); }
|
||||||
|
@ -122,7 +127,7 @@ mod noise {
|
||||||
let y = p.y as usize % width;
|
let y = p.y as usize % width;
|
||||||
|
|
||||||
let one = b[x*width + y] as f32;
|
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()
|
Vector2::new(one, two).normalize()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue