2d_rainbow/
2d-rainbow.rs

1use blinksy::{
2    layout::{Layout2d, Shape2d, Vec2},
3    layout2d,
4    patterns::rainbow::{Rainbow, RainbowParams},
5    ControlBuilder,
6};
7use blinksy_desktop::{
8    driver::{Desktop, DesktopError},
9    time::elapsed_in_ms,
10};
11use std::{thread::sleep, time::Duration};
12
13layout2d!(
14    PanelLayout,
15    [Shape2d::Grid {
16        start: Vec2::new(-1., -1.),
17        horizontal_end: Vec2::new(1., -1.),
18        vertical_end: Vec2::new(-1., 1.),
19        horizontal_pixel_count: 16,
20        vertical_pixel_count: 16,
21        serpentine: true,
22    }]
23);
24
25fn main() {
26    Desktop::new_2d::<PanelLayout>().start(|driver| {
27        let mut control = ControlBuilder::new_2d()
28            .with_layout::<PanelLayout, { PanelLayout::PIXEL_COUNT }>()
29            .with_pattern::<Rainbow>(RainbowParams {
30                ..Default::default()
31            })
32            .with_driver(driver)
33            .with_frame_buffer_size::<{ PanelLayout::PIXEL_COUNT }>()
34            .build();
35
36        loop {
37            if let Err(DesktopError::WindowClosed) = control.tick(elapsed_in_ms()) {
38                break;
39            }
40
41            sleep(Duration::from_millis(16));
42        }
43    });
44}