pub struct PixelColor {
pub red: u8,
pub green: u8,
pub blue: u8,
}
Expand description
24-bit RGB color pixel.
This is the fundamental representation for RGB colors.
Fields§
§red: u8
§green: u8
§blue: u8
Implementations§
Source§impl PixelColor
impl PixelColor
pub const BLACK: PixelColor
pub const RED: PixelColor
pub const BLUE: PixelColor
pub const GREEN: PixelColor
pub const WHITE: PixelColor
pub const YELLOW: PixelColor
pub const CYAN: PixelColor
pub const MAGENTA: PixelColor
Sourcepub fn from_rgb565_bytes(color: [u8; 2]) -> Self
pub fn from_rgb565_bytes(color: [u8; 2]) -> Self
Create a new LED pixel color from a pair of RGB565-encoded bytes.
Sourcepub fn rgb565(&self) -> [u8; 2]
pub fn rgb565(&self) -> [u8; 2]
Encodes the current LED pixel color into a pair of RGB565-encoded bytes.
Sourcepub fn dim(self, scale: f32) -> PixelColor
pub fn dim(self, scale: f32) -> PixelColor
Sets the brightness of this colour.
The scale
value should be between 0 and 1. Values outside this range
are clamped.
Examples found in repository?
examples/letter.rs (line 19)
16fn main() {
17 let mut screen = Screen::open("/dev/fb1").unwrap();
18
19 let white_50_pct = PixelColor::WHITE.dim(0.5);
20
21 let letter = "Dear Toño, I am well. Thank you. Bye. - ゆにち";
22
23 let screen_text = FONT_COLLECTION.sanitize_str(letter).unwrap();
24
25 for unicode in screen_text.chars() {
26 if let Some(symbol) = FONT_COLLECTION.get(unicode) {
27 let frame = font_to_frame(symbol.byte_array(), white_50_pct);
28 screen.write_frame(&frame);
29 }
30 thread::sleep(Duration::from_millis(800));
31 }
32}
More examples
examples/clip.rs (line 19)
15fn main() {
16 let mut screen = Screen::open("/dev/fb1").unwrap();
17
18 let letters = "a e i o u ";
19 let letter_color = PixelColor::YELLOW.dim(0.5);
20
21 let frames = letters
22 .chars()
23 .map(|sym| {
24 let font = FONT_COLLECTION.get(sym).unwrap();
25 font_to_pixel_frame(font.byte_array(), letter_color)
26 })
27 .collect::<Vec<PixelFrame>>();
28
29 // create a sequence of clips that will scroll each character-whitespace pair
30 // from appearing to move from right to left.
31 let frame_reel: Vec<PixelFrame> = frames.chunks(2).fold(Vec::new(), |mut v, chunk| match chunk
32 .len()
33 {
34 2 => {
35 let clip = chunk[0].build_clip(&chunk[1]);
36 for i in 0..=8 {
37 v.push(clip.offset(Offset::left(i)));
38 }
39 v
40 }
41 _ => panic!("this frame reel will only display &str of even length (divisible by 2)"),
42 });
43
44 for frame in &frame_reel {
45 screen.write_frame(&frame.frame_line());
46 ::std::thread::sleep(::std::time::Duration::from_millis(750));
47 }
48}
examples/offset.rs (line 18)
14fn main() {
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16 let fonts = FontCollection::new();
17
18 for &(sym, color) in &[('þ', PixelColor::CYAN), ('ß', PixelColor::WHITE.dim(0.5))] {
19 let font = fonts.get(sym).unwrap();
20 let symbol = font_to_pixel_frame(font.byte_array(), color);
21
22 // Starts with an empty screen, then the symbol slides from the left,
23 // reaching the offset = 0 position, which renders the entire symbol on
24 // the screen.
25 for i in 0..=8 {
26 screen.write_frame(&symbol.offset(Offset::left(8 - i)).frame_line());
27 ::std::thread::sleep(::std::time::Duration::from_millis(500));
28 }
29 // Slides the displayed symbol to the right until it disappears.
30 for i in 0..=8 {
31 screen.write_frame(&symbol.offset(Offset::right(i)).frame_line());
32 ::std::thread::sleep(::std::time::Duration::from_millis(500));
33 }
34
35 // Starts with an empty screen, then the symbol slides from the top,
36 // reaching the offset = 0 position, which renders the entire symbol on
37 // the screen.
38 for i in 0..=8 {
39 screen.write_frame(&symbol.offset(Offset::top(8 - i)).frame_line());
40 ::std::thread::sleep(::std::time::Duration::from_millis(500));
41 }
42 // Slides the displayed symbol to the bottom until it disappears.
43 for i in 0..=8 {
44 screen.write_frame(&symbol.offset(Offset::bottom(i)).frame_line());
45 ::std::thread::sleep(::std::time::Duration::from_millis(500));
46 }
47 }
48 screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
49}
Trait Implementations§
Source§impl Clone for PixelColor
impl Clone for PixelColor
Source§fn clone(&self) -> PixelColor
fn clone(&self) -> PixelColor
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PixelColor
impl Debug for PixelColor
Source§impl Default for PixelColor
impl Default for PixelColor
Source§fn default() -> PixelColor
fn default() -> PixelColor
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for PixelColor
impl<'de> Deserialize<'de> for PixelColor
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> From<&'a PixelColor> for Rgb565
impl<'a> From<&'a PixelColor> for Rgb565
Source§fn from(color: &'a PixelColor) -> Self
fn from(color: &'a PixelColor) -> Self
Converts to this type from the input type.
Source§impl From<PixelColor> for Rgb565
impl From<PixelColor> for Rgb565
Source§fn from(color: PixelColor) -> Self
fn from(color: PixelColor) -> Self
Converts to this type from the input type.
Source§impl From<Rgb565> for PixelColor
impl From<Rgb565> for PixelColor
Source§impl PartialEq for PixelColor
impl PartialEq for PixelColor
Source§impl Serialize for PixelColor
impl Serialize for PixelColor
impl Copy for PixelColor
impl StructuralPartialEq for PixelColor
Auto Trait Implementations§
impl Freeze for PixelColor
impl RefUnwindSafe for PixelColor
impl Send for PixelColor
impl Sync for PixelColor
impl Unpin for PixelColor
impl UnwindSafe for PixelColor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more