Compare commits

..

No commits in common. "12a54c42da11fdfc5c8548586ab0e8914702dcc5" and "823ec0ad0045bd5f3f1de998e40ae057c80c9ac0" have entirely different histories.

View File

@ -1,70 +1,23 @@
#[derive(Copy, Clone)]
struct RGB {
red: u8,
green: u8,
blue: u8,
struct Vector3 {
x: f32,
y: f32,
z: f32,
}
impl RGB {
fn new(red: u8, green: u8, blue: u8) -> RGB {
RGB { red, green, blue }
}
fn black() -> RGB {
RGB {
red: 0,
green: 0,
blue: 0,
impl Vector3 {
pub fn new(x: f32, y: f32, z: f32) -> Vector3 {
Vector3 { x, y, z }
}
}
fn white() -> RGB {
RGB {
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 print(vec: Vector3) {
println!("Vector3( x = {}, y = {}, z = {})", vec.x, vec.y, vec.z);
}
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;
}