pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Fields§
§r: u8
§g: u8
§b: u8
§a: u8
Implementations§
Source§impl Color
impl Color
pub const WHITE: Color
pub const BLACK: Color
pub const GRAY: Color
pub const GREY: Color = Color::GRAY
pub const RED: Color
pub const GREEN: Color
pub const BLUE: Color
pub const MAGENTA: Color
pub const YELLOW: Color
pub const CYAN: Color
Sourcepub const fn RGB(r: u8, g: u8, b: u8) -> Color
pub const fn RGB(r: u8, g: u8, b: u8) -> Color
Examples found in repository?
examples/colour_cycle.rs (line 39)
24 fn on_update(
25 &mut self,
26 canvas: &mut WindowCanvas,
27 input: &InputState,
28 elapsed_time: f64,
29 ) -> sge::ApplicationResult {
30 // Handle keyboard input
31 if input.keyboard.pressed(Scancode::Q) {
32 return Ok(false);
33 }
34 // If we're at the bounds for a colour value, change direction
35 if self.col <= 0.0 || self.col >= 255.0 {
36 self.flipper = !self.flipper;
37 }
38 // Fill the screen with the current colour
39 canvas.set_draw_color(Color::RGB(self.col as u8, 0, 255 - self.col as u8));
40 canvas.clear();
41 // Change the colour
42 if !self.flipper {
43 self.col -= CYCLE_SPEED * elapsed_time as f32;
44 } else {
45 self.col += CYCLE_SPEED * elapsed_time as f32;
46 }
47 Ok(true)
48 }
pub const fn RGBA(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn to_u32(self, format: &PixelFormat) -> u32
pub fn from_u32(format: &PixelFormat, pixel: u32) -> Color
pub fn invert(self) -> Color
pub const fn rgb(self) -> (u8, u8, u8)
pub const fn rgba(self) -> (u8, u8, u8, u8)
Trait Implementations§
impl Copy for Color
impl Eq for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
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