-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ZeWaka <[email protected]>
- Loading branch information
1 parent
fc3fd8e
commit 22a6df5
Showing
7 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y) | ||
|
||
/** | ||
* Generates a 2D poisson disk distribution ('blue noise'), which is relatively uniform. | ||
* | ||
* params: | ||
* `seed`: str | ||
* `width`: int, width of the noisemap (see world.maxx) | ||
* `length`: int, height of the noisemap (see world.maxy) | ||
* `radius`: int, distance between points on the noisemap | ||
* | ||
* returns: | ||
* a width*length length string of 1s and 0s representing a 2D poisson sample collapsed into a 1D string | ||
*/ | ||
#define rustg_noise_poisson_map(seed, width, length, radius) RUSTG_CALL(RUST_G, "noise_poisson_map")(seed, width, length, radius) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use fast_poisson::Poisson2D; | ||
use std::fmt::Write; | ||
|
||
use crate::error::Result; | ||
|
||
byond_fn!(fn noise_poisson_map(seed, width, length, radius) { | ||
get_poisson_map(seed, width, length, radius).ok() | ||
}); | ||
|
||
fn get_poisson_map( | ||
seed_as_str: &str, | ||
width_as_str: &str, | ||
length_as_str: &str, | ||
radius_as_str: &str, | ||
) -> Result<String> { | ||
let width = width_as_str.parse::<f32>()?; | ||
let length = length_as_str.parse::<f32>()?; | ||
let radius = radius_as_str.parse::<f32>()?; | ||
let seed = seed_as_str.parse::<u64>()?; | ||
|
||
let points: Vec<[f32; 2]> = Poisson2D::new() | ||
.with_dimensions([width, length], radius) | ||
.with_seed(seed) | ||
.to_vec(); | ||
|
||
let mut output = String::new(); | ||
for y in 0..length as usize { | ||
for x in 0..width as usize { | ||
if points | ||
.iter() | ||
.any(|&point| point[0] as usize == x && point[1] as usize == y) | ||
{ | ||
let _ = write!(output, "1"); | ||
} else { | ||
let _ = write!(output, "0"); | ||
} | ||
} | ||
} | ||
|
||
Ok(output) | ||
} |