diff --git a/Cargo.toml b/Cargo.toml index 5efa16115826e6..04c47564f1d3b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,6 +170,10 @@ path = "examples/2d/texture_atlas.rs" name = "3d_scene" path = "examples/3d/3d_scene.rs" +[[example]] +name = "hierarchy_fractal" +path = "examples/3d/hierarchy_fractal.rs" + [[example]] name = "lighting" path = "examples/3d/lighting.rs" diff --git a/examples/3d/hierarchy_fractal.rs b/examples/3d/hierarchy_fractal.rs new file mode 100644 index 00000000000000..dcf7115f41e5cc --- /dev/null +++ b/examples/3d/hierarchy_fractal.rs @@ -0,0 +1,216 @@ +use bevy::prelude::*; + +// tree width (per node) and depth +// results in 1 + WIDTH^(DEPTH - 1) total +const WIDTH: usize = 3; +const DEPTH: usize = 6; + +// line size +const BASE_LENGTH: f32 = 18.0; +const BASE_WIDTH: f32 = 0.15; + +// mutation parameters for branching (uses 0..WIDTH) +const OFFSETS: [f32; 5] = [0.19, 0.42, 0.68, 0.33, 0.73]; + +// color palette parameters +// see: https://iquilezles.org/www/articles/palettes/palettes.htm +const PALETTE: [(f32, f32, f32); 4] = [ + (0.5, 0.5, 0.5), + (0.5, 0.5, 0.5), + (1.0, 1.0, 1.0), + (0.00, 0.10, 0.20), +]; + +#[derive(Component)] +struct Rotate { + pub speed: f32, + pub offset: f32, + pub axis: Vec3, +} + +fn rotate(time: Res