3d_cube_face_noise/
3d-cube-face-noise.rs

1use blinksy::{
2    layout::{Layout3d, Shape3d, Vec3},
3    layout3d,
4    patterns::noise::{noise_fns, Noise3d, NoiseParams},
5    ControlBuilder,
6};
7use blinksy_desktop::{
8    driver::{Desktop, DesktopError},
9    time::elapsed_in_ms,
10};
11use std::{thread::sleep, time::Duration};
12
13fn main() {
14    layout3d!(
15        CubeFaceLayout,
16        [
17            // bottom face
18            Shape3d::Grid {
19                start: Vec3::new(1., -1., 1.),           // right bottom front
20                horizontal_end: Vec3::new(-1., -1., 1.), // left bottom front
21                vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
22                horizontal_pixel_count: 16,
23                vertical_pixel_count: 16,
24                serpentine: true,
25            },
26            // back face
27            Shape3d::Grid {
28                start: Vec3::new(-1., -1., -1.),         // left bottom back
29                horizontal_end: Vec3::new(-1., 1., -1.), // left top back
30                vertical_end: Vec3::new(1., -1., -1.),   // right bottom back
31                horizontal_pixel_count: 16,
32                vertical_pixel_count: 16,
33                serpentine: true,
34            },
35            // right face
36            Shape3d::Grid {
37                start: Vec3::new(1., 1., -1.),         // right top back
38                horizontal_end: Vec3::new(1., 1., 1.), // right top front
39                vertical_end: Vec3::new(1., -1., -1.), // right bottom back
40                horizontal_pixel_count: 16,
41                vertical_pixel_count: 16,
42                serpentine: true,
43            },
44            // front face
45            Shape3d::Grid {
46                start: Vec3::new(-1., -1., 1.),         // left bottom front
47                horizontal_end: Vec3::new(1., -1., 1.), // right bottom front
48                vertical_end: Vec3::new(-1., 1., 1.),   // left top front
49                horizontal_pixel_count: 16,
50                vertical_pixel_count: 16,
51                serpentine: true,
52            },
53            // left face
54            Shape3d::Grid {
55                start: Vec3::new(-1., 1., -1.),           // left top back
56                horizontal_end: Vec3::new(-1., -1., -1.), // left bottom back
57                vertical_end: Vec3::new(-1., 1., 1.),     // left top front
58                horizontal_pixel_count: 16,
59                vertical_pixel_count: 16,
60                serpentine: true,
61            },
62            // top face
63            Shape3d::Grid {
64                start: Vec3::new(1., 1., 1.),           // right top front
65                horizontal_end: Vec3::new(1., 1., -1.), // right top back
66                vertical_end: Vec3::new(-1., 1., 1.),   // left top front
67                horizontal_pixel_count: 16,
68                vertical_pixel_count: 16,
69                serpentine: true,
70            }
71        ]
72    );
73
74    Desktop::new_3d::<CubeFaceLayout>().start(|driver| {
75        let mut control = ControlBuilder::new_3d()
76            .with_layout::<CubeFaceLayout, { CubeFaceLayout::PIXEL_COUNT }>()
77            .with_pattern::<Noise3d<noise_fns::Perlin>>(NoiseParams {
78                ..Default::default()
79            })
80            .with_driver(driver)
81            .with_frame_buffer_size::<{ CubeFaceLayout::PIXEL_COUNT }>()
82            .build();
83
84        loop {
85            if let Err(DesktopError::WindowClosed) = control.tick(elapsed_in_ms()) {
86                break;
87            }
88
89            sleep(Duration::from_millis(16));
90        }
91    });
92}