-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cone generator #309
base: develop
Are you sure you want to change the base?
Add cone generator #309
Conversation
src/noise_fns/generators/cone.rs
Outdated
// Calculate the distance of the point from the origin. | ||
let dist_from_center = (x.powi(2) + y.powi(2)).sqrt(); | ||
|
||
match dist_from_center > self.radius{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should square the radius (you could even store the squared version) so you can avoid the sqrt()
call above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I've moved the sqrt call inside the match expression so that it is only computed for case false.
I'd like an explanation of the purpose for this noisefn. |
I have a use case where I needed to generate a binary terrain (1 or -1) in 2d that gradually becomes denser as you move further away from the center. There doesn't seem to be an easy way to do this without the cone NoiseFn. Here's how the cone is useful in this case: use noise::{Fbm, Perlin, Constant, Cone, Negate, Add, Select, Clamp};
use noise::utils::{NoiseMapBuilder, PlaneMapBuilder};
use noise::MultiFractal;
fn main() {
let noise = Select::new(
Constant::new(-1.0),
Constant::new(1.0),
Add::new(
Negate::new(
Clamp::new(
Cone::default().set_radius(39000f64)
).set_upper_bound(0.0)
),
Fbm::<Perlin>::new(1)
.set_octaves(5)
.set_frequency(0.0003)
.set_lacunarity(1.1)
.set_persistence(2.0)
)
)
.set_bounds(0.2, 1.0)
.set_falloff(-1.0);
let world = PlaneMapBuilder::<_, 2>::new(noise)
.set_size(500, 500)
.set_x_bounds(-30000.0, 30000.0)
.set_y_bounds(-30000.0, 30000.0)
.build();
world.write_to_file("arena.png");
} This code is essentially subtracting a cone from fbm noise. |
No description provided.