-
Notifications
You must be signed in to change notification settings - Fork 3
/
offset.rs
49 lines (44 loc) · 2 KB
/
offset.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[cfg(feature = "default")]
extern crate sensehat_screen;
#[cfg(feature = "default")]
use sensehat_screen::Offset;
#[cfg(feature = "default")]
use sensehat_screen::{font_to_pixel_frame, FontCollection, PixelColor, PixelFrame, Screen};
#[cfg(not(feature = "default"))]
fn main() {
unimplemented!("This examples needs the 'default' features.");
}
#[cfg(feature = "default")]
fn main() {
let mut screen = Screen::open("/dev/fb1").unwrap();
let fonts = FontCollection::new();
for &(sym, color) in &[('þ', PixelColor::CYAN), ('ß', PixelColor::WHITE.dim(0.5))] {
let font = fonts.get(sym).unwrap();
let symbol = font_to_pixel_frame(font.byte_array(), color);
// Starts with an empty screen, then the symbol slides from the left,
// reaching the offset = 0 position, which renders the entire symbol on
// the screen.
for i in 0..=8 {
screen.write_frame(&symbol.offset(Offset::left(8 - i)).frame_line());
::std::thread::sleep(::std::time::Duration::from_millis(500));
}
// Slides the displayed symbol to the right until it disappears.
for i in 0..=8 {
screen.write_frame(&symbol.offset(Offset::right(i)).frame_line());
::std::thread::sleep(::std::time::Duration::from_millis(500));
}
// Starts with an empty screen, then the symbol slides from the top,
// reaching the offset = 0 position, which renders the entire symbol on
// the screen.
for i in 0..=8 {
screen.write_frame(&symbol.offset(Offset::top(8 - i)).frame_line());
::std::thread::sleep(::std::time::Duration::from_millis(500));
}
// Slides the displayed symbol to the bottom until it disappears.
for i in 0..=8 {
screen.write_frame(&symbol.offset(Offset::bottom(i)).frame_line());
::std::thread::sleep(::std::time::Duration::from_millis(500));
}
}
screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
}