Compare commits
No commits in common. "12a54c42da11fdfc5c8548586ab0e8914702dcc5" and "823ec0ad0045bd5f3f1de998e40ae057c80c9ac0" have entirely different histories.
12a54c42da
...
823ec0ad00
73
src/main.rs
73
src/main.rs
@ -1,70 +1,23 @@
|
|||||||
#[derive(Copy, Clone)]
|
struct Vector3 {
|
||||||
struct RGB {
|
x: f32,
|
||||||
red: u8,
|
y: f32,
|
||||||
green: u8,
|
z: f32,
|
||||||
blue: u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RGB {
|
impl Vector3 {
|
||||||
fn new(red: u8, green: u8, blue: u8) -> RGB {
|
pub fn new(x: f32, y: f32, z: f32) -> Vector3 {
|
||||||
RGB { red, green, blue }
|
Vector3 { x, y, z }
|
||||||
}
|
|
||||||
|
|
||||||
fn black() -> RGB {
|
|
||||||
RGB {
|
|
||||||
red: 0,
|
|
||||||
green: 0,
|
|
||||||
blue: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn white() -> RGB {
|
fn print(vec: Vector3) {
|
||||||
RGB {
|
println!("Vector3( x = {}, y = {}, z = {})", vec.x, vec.y, vec.z);
|
||||||
red: 255,
|
|
||||||
green: 255,
|
|
||||||
blue: 255,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Image {
|
|
||||||
width: usize,
|
|
||||||
height: usize,
|
|
||||||
data: Vec<RGB>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Image {
|
|
||||||
fn new(width: usize, height: usize, data: Vec<RGB>) -> Image {
|
|
||||||
if width * height != data.len() {
|
|
||||||
panic!("Width and height of image does not match amount of data.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let img = Image {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
|
|
||||||
img
|
|
||||||
}
|
|
||||||
|
|
||||||
fn white_image(width: usize, height: usize) -> Image {
|
|
||||||
let mut data = Vec::new();
|
|
||||||
|
|
||||||
for i in 0..width * height {
|
|
||||||
data.push(RGB::white());
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::new(width, height, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, x: usize, y: usize) -> RGB {
|
|
||||||
self.data[y * self.width + x]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let image = Image::white_image(640, 480);
|
let mut vec = Vector3::new(1.0, 0.0, 0.0);
|
||||||
|
|
||||||
let c = image.get(0, 0);
|
print(vec);
|
||||||
|
|
||||||
|
vec.y = 2.0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user