Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Razaekel committed May 19, 2024
1 parent 1953743 commit 140faca
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 153 deletions.
270 changes: 135 additions & 135 deletions examples/complexplanet.rs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions examples/power.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
extern crate noise;

use noise::{utils::*, Perlin, Power};
use noise::{utils::*, Perlin, Power, DEFAULT_SEED};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let perlin1 = Perlin::default();
let perlin2 = Perlin::new(1);
let perlin2 = Perlin::new(XorShiftRng::from_seed(DEFAULT_SEED).gen());
let power = Power::new(perlin1, perlin2);

utils::write_example_to_file(&PlaneMapBuilder::new(power).build(), "power.png");
Expand Down
10 changes: 7 additions & 3 deletions examples/ridgedmulti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
extern crate noise;

use noise::{utils::*, Perlin, RidgedMulti, Worley};
use noise::{utils::*, Perlin, RidgedMulti, Worley, DEFAULT_SEED};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let ridged_multi = RidgedMulti::<Perlin>::default();
let mut rng = XorShiftRng::from_seed(DEFAULT_SEED);

let ridged_multi = RidgedMulti::<Perlin>::new(rng.gen());

utils::write_example_to_file(
&PlaneMapBuilder::new(ridged_multi).build(),
Expand All @@ -21,7 +25,7 @@ fn main() {
"ridged_multi_worley.png",
);

let ridged_multi = RidgedMulti::<RidgedMulti<Perlin>>::default();
let ridged_multi = RidgedMulti::<RidgedMulti<Perlin>>::new(rng.gen());

utils::write_example_to_file(
&PlaneMapBuilder::new(ridged_multi).build(),
Expand Down
10 changes: 7 additions & 3 deletions examples/texturegranite.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
extern crate noise;

use noise::{core::worley::ReturnType, utils::*, *};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let mut rng = XorShiftRng::from_seed(DEFAULT_SEED);

// Primary granite texture. This generates the "roughness" of the texture
// when lit by a light source.
let primary_granite = Billow::<Perlin>::new(0)
let primary_granite = Billow::<Perlin>::new(rng.gen())
.set_frequency(8.0)
.set_persistence(0.625)
.set_lacunarity(2.18359375)
.set_octaves(6);

// Use Worley polygons to produce the small grains for the granite texture.
let base_grains = Worley::new(1)
let base_grains = Worley::new(rng.gen())
.set_frequency(16.0)
.set_return_type(ReturnType::Distance);

Expand All @@ -28,7 +32,7 @@ fn main() {

// Finally, perturb the granite texture to add realism.
let final_granite = Turbulence::<_, Perlin>::new(combined_granite)
.set_seed(2)
.set_seed(rng.gen())
.set_frequency(4.0)
.set_power(1.0 / 8.0)
.set_roughness(6);
Expand Down
10 changes: 7 additions & 3 deletions examples/texturejade.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
extern crate noise;

use noise::{utils::*, *};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let mut rng = XorShiftRng::from_seed(DEFAULT_SEED);

// Primary jade texture. The ridges from the ridged-multifractal function
// produces the veins.
let primary_jade = RidgedMulti::<Perlin>::new(0)
let primary_jade = RidgedMulti::<Perlin>::new(rng.gen())
.set_frequency(2.0)
.set_lacunarity(2.20703125)
.set_octaves(6);
Expand All @@ -24,7 +28,7 @@ fn main() {

// Slightly perturb the secondary jade texture for more realism.
let perturbed_base_secondary_jade = Turbulence::<_, Perlin>::new(rotated_base_secondary_jade)
.set_seed(1)
.set_seed(rng.gen())
.set_frequency(4.0)
.set_power(1.0 / 4.0)
.set_roughness(4);
Expand All @@ -43,7 +47,7 @@ fn main() {
// Finally, perturb the combined jade texture to produce the final jade
// texture. A low roughness produces nice veins.
let final_jade = Turbulence::<_, Perlin>::new(combined_jade)
.set_seed(2)
.set_seed(rng.gen())
.set_frequency(4.0)
.set_power(1.0 / 16.0)
.set_roughness(2);
Expand Down
12 changes: 8 additions & 4 deletions examples/textureslime.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
extern crate noise;

use noise::{utils::*, *};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let mut rng = XorShiftRng::from_seed(DEFAULT_SEED);

// Large slime bubble texture.
let large_slime = Billow::<Perlin>::new(0)
let large_slime = Billow::<Perlin>::new(rng.gen())
.set_frequency(4.0)
.set_lacunarity(2.12109375)
.set_octaves(1);

// Base of the small slime bubble texture. This texture will eventually
// appear inside cracks in the large slime bubble texture.
let small_slime_base = Billow::<Perlin>::new(1)
let small_slime_base = Billow::<Perlin>::new(rng.gen())
.set_frequency(24.0)
.set_lacunarity(2.14453125)
.set_octaves(1);
Expand All @@ -25,7 +29,7 @@ fn main() {

// Create a map that specifies where the large and small slime bubble
// textures will appear in the final texture map.
let slime_map = RidgedMulti::<Perlin>::new(2)
let slime_map = RidgedMulti::<Perlin>::new(rng.gen())
.set_frequency(2.0)
.set_lacunarity(2.20703125)
.set_octaves(3);
Expand All @@ -42,7 +46,7 @@ fn main() {

// Finally, perturb the slime texture to add realism.
let final_slime = Turbulence::<_, Perlin>::new(slime_chooser)
.set_seed(3)
.set_seed(rng.gen())
.set_frequency(8.0)
.set_power(1.0 / 32.0)
.set_roughness(2);
Expand Down
10 changes: 7 additions & 3 deletions examples/texturewood.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
extern crate noise;

use noise::{utils::*, *};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

mod utils;

fn main() {
let mut rng = XorShiftRng::from_seed(DEFAULT_SEED);

// Base wood texture. Uses concentric cylinders aligned on the z-axis, like a log.
let base_wood = Cylinders::new().set_frequency(16.0);

// Basic Multifractal noise to use for the wood grain.
let wood_grain_noise = BasicMulti::<Perlin>::new(0)
let wood_grain_noise = BasicMulti::<Perlin>::new(rng.gen())
.set_frequency(48.0)
.set_persistence(0.5)
.set_lacunarity(2.20703125)
Expand All @@ -29,7 +33,7 @@ fn main() {

// Slightly perturb the wood to create a more realistic texture.
let perturbed_wood = Turbulence::<_, Perlin>::new(combined_wood)
.set_seed(1)
.set_seed(rng.gen())
.set_frequency(4.0)
.set_power(1.0 / 256.0)
.set_roughness(4);
Expand All @@ -42,7 +46,7 @@ fn main() {

// Finally, perturb the wood texture again to produce the final texture.
let final_wood = Turbulence::<_, Perlin>::new(rotated_wood)
.set_seed(2)
.set_seed(rng.gen())
.set_frequency(2.0)
.set_power(1.0 / 64.0)
.set_roughness(4);
Expand Down

0 comments on commit 140faca

Please sign in to comment.