Compare commits
No commits in common. "81205e5b29d05fd5cdff5911d69b651b4d99c386" and "12a54c42da11fdfc5c8548586ab0e8914702dcc5" have entirely different histories.
81205e5b29
...
12a54c42da
49
src/main.rs
49
src/main.rs
@ -1,4 +1,4 @@
|
|||||||
//#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct RGB {
|
struct RGB {
|
||||||
red: u8,
|
red: u8,
|
||||||
green: u8,
|
green: u8,
|
||||||
@ -11,11 +11,19 @@ impl RGB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn black() -> RGB {
|
fn black() -> RGB {
|
||||||
RGB::new(0, 0, 0)
|
RGB {
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn white() -> RGB {
|
fn white() -> RGB {
|
||||||
RGB::new(255, 255, 255)
|
RGB {
|
||||||
|
red: 255,
|
||||||
|
green: 255,
|
||||||
|
blue: 255,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,42 +58,13 @@ impl Image {
|
|||||||
Image::new(width, height, data)
|
Image::new(width, height, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, x: usize, y: usize) -> &RGB {
|
fn get(&self, x: usize, y: usize) -> RGB {
|
||||||
self.data.get(y * self.width + x).unwrap()
|
self.data[y * self.width + x]
|
||||||
}
|
|
||||||
|
|
||||||
fn get_mut(&mut self, x: usize, y: usize) -> &mut RGB {
|
|
||||||
self.data.get_mut(y * self.width + x).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Container<'a> {
|
|
||||||
value: &'a RGB,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Container<'a> {
|
|
||||||
fn new(value: &RGB) -> Container {
|
|
||||||
Container { value }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn brighter<'a>(a: &'a RGB, b: &'a RGB) -> &'a RGB {
|
|
||||||
if a.red / 3 + a.green / 3 + a.blue / 3 > b.red / 3 + b.green / 3 + b.blue / 3 {
|
|
||||||
a
|
|
||||||
} else {
|
|
||||||
b
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let image = Image::white_image(640, 480);
|
let image = Image::white_image(640, 480);
|
||||||
|
|
||||||
let black = RGB::black();
|
let c = image.get(0, 0);
|
||||||
|
|
||||||
let c1 = image.get(0, 0);
|
|
||||||
//let c2 = image.get(1, 1);
|
|
||||||
|
|
||||||
let brightest = brighter(c1, &black);
|
|
||||||
|
|
||||||
println!("{}", brightest.red);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user