-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new type of noise: Discrete Batched Perlin-like Noise (DBP) (#99)
- Loading branch information
Showing
5 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* This proc generates a grid of perlin-like noise | ||
* | ||
* Returns a single string that goes row by row, with values of 1 representing an turned on cell, and a value of 0 representing a turned off cell. | ||
* | ||
* Arguments: | ||
* * seed: seed for the function | ||
* * accuracy: how close this is to the original perlin noise, as accuracy approaches infinity, the noise becomes more and more perlin-like | ||
* * stamp_size: Size of a singular stamp used by the algorithm, think of this as the same stuff as frequency in perlin noise | ||
* * world_size: size of the returned grid. | ||
* * lower_range: lower bound of values selected for. (inclusive) | ||
* * upper_range: upper bound of values selected for. (exclusive) | ||
*/ | ||
#define rustg_dbp_generate(seed, accuracy, stamp_size, world_size, lower_range, upper_range) \ | ||
call(RUST_G, "dbp_generate")(seed, accuracy, stamp_size, world_size, lower_range, upper_range) | ||
|
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,36 @@ | ||
use crate::error::Result; | ||
use dbpnoise::gen_noise; | ||
|
||
byond_fn!(fn dbp_generate(seed, accuracy, stamp_size, world_size, lower_range, upper_range) { | ||
gen_dbp_noise(seed, accuracy, stamp_size, world_size, lower_range, upper_range).ok() | ||
}); | ||
|
||
fn gen_dbp_noise( | ||
seed: &str, | ||
accuracy_as_str: &str, | ||
stamp_size_as_str: &str, | ||
world_size_as_str: &str, | ||
lower_range_as_str: &str, | ||
upper_range_as_str: &str, | ||
) -> Result<String> { | ||
let accuracy = accuracy_as_str.parse::<usize>()?; | ||
let stamp_size = stamp_size_as_str.parse::<usize>()?; | ||
let world_size = world_size_as_str.parse::<usize>()?; | ||
let lower_range = lower_range_as_str.parse::<f32>()?; | ||
let upper_range = upper_range_as_str.parse::<f32>()?; | ||
let map: Vec<Vec<bool>> = gen_noise( | ||
seed, | ||
accuracy, | ||
stamp_size, | ||
world_size, | ||
lower_range, | ||
upper_range, | ||
); | ||
let mut result = String::new(); | ||
for row in map { | ||
for cell in row { | ||
result.push(if cell { '1' } else { '0' }); | ||
} | ||
} | ||
Ok(result) | ||
} |
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