Echo Writes Code

color.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
use crate::geometry::{ Vector4D };

pub struct Color {
  channels: Vector4D<f32>,
}

impl Color {
  pub fn black() -> Color {
    Color::new(0.0, 0.0, 0.0, 1.0)
  }

  pub fn white() -> Color {
    Color::new(1.0, 1.0, 1.0, 1.0)
  }

  pub fn new(r: f32, g: f32, b: f32, a: f32) -> Color {
    Color {
      channels: Vector4D::new(r, g, b, a),
    }
  }

  pub fn r(&self) -> f32 {
    self.channels.x()
  }

  pub fn g(&self) -> f32 {
    self.channels.y()
  }

  pub fn b(&self) -> f32 {
    self.channels.z()
  }

  pub fn a(&self) -> f32 {
    self.channels.w()
  }
}