Can make a clock face
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
target
|
target
|
||||||
rusty-tags.vi
|
rusty-tags.vi
|
||||||
out.ppm
|
*.ppm
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ impl Tuple {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn point_zero() -> Tuple {
|
||||||
|
Tuple {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
z: 0.0,
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn point(x: f32, y: f32, z: f32) -> Tuple {
|
pub fn point(x: f32, y: f32, z: f32) -> Tuple {
|
||||||
Tuple {
|
Tuple {
|
||||||
|
|||||||
44
src/main.rs
44
src/main.rs
@@ -3,6 +3,7 @@ use features::color::Color;
|
|||||||
use features::structs::Tuple;
|
use features::structs::Tuple;
|
||||||
use features::matrix::Matrix;
|
use features::matrix::Matrix;
|
||||||
|
|
||||||
|
use std::f32::consts::PI;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@@ -147,4 +148,47 @@ fn before_clock() {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
before_clock();
|
before_clock();
|
||||||
|
clock();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clock() {
|
||||||
|
println!("Starting clock!");
|
||||||
|
|
||||||
|
let mut canvas = Canvas::new(1024, 1024);
|
||||||
|
let color = Color::new(1.0, 0.0, 0.0);
|
||||||
|
let middle = 1024.0 / 2.0;
|
||||||
|
let three_fourths_middle = middle / 4.0 * 3.0;
|
||||||
|
let center = &Tuple::point_zero() * &Matrix::translation(0.0, 1.0, 0.0);
|
||||||
|
// canvas.write_pixel(center.x() as usize, center.y() as usize, color);
|
||||||
|
canvas.write_pixel(middle as usize, middle as usize, Color::new(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
|
for i in 1..13 {
|
||||||
|
let twelve = Tuple::point_zero();
|
||||||
|
|
||||||
|
let twelve = &Matrix::translation(0.0, -12.0, 0.0) * &twelve;
|
||||||
|
let twelve = &Matrix::scaling(0.0, 10.0, 0.0) * &twelve;
|
||||||
|
let twelve = &Matrix::rotation_z((i as f32 / 12.0) * (2.0 * PI)) * &twelve;
|
||||||
|
let twelve = &Matrix::translation(middle, middle, 0.0) * &twelve;
|
||||||
|
println!("{}", twelve);
|
||||||
|
|
||||||
|
canvas.write_pixel(twelve.x() as usize, twelve.y() as usize, color);
|
||||||
|
|
||||||
|
}
|
||||||
|
//for i in 0..=-1 {
|
||||||
|
// let position = ((2.0 * PI) / 12.0) * (i as f32);
|
||||||
|
// println!("i: {} pos: {}", i, position);
|
||||||
|
// let transform = &(&(&Matrix::identity(4)
|
||||||
|
// * &Matrix::translation(0.0, 1.0 , 0.0))
|
||||||
|
// * &Matrix::rotation_z(position))
|
||||||
|
// //* &Matrix::identity(4))
|
||||||
|
// * &Matrix::translation(middle, middle, 0.0);
|
||||||
|
// let point = &Tuple::point_zero() * &(&transform * &Matrix::scaling(three_fourths_middle, three_fourths_middle, 0.0));
|
||||||
|
// //let point = &Tuple::point_zero() * &(&Matrix::translation(i as f32 * 6.0, 0.0, 0.0) * &Matrix::translation(middle, middle, 0.0));
|
||||||
|
// println!("point rotated: {}", &point);
|
||||||
|
// canvas.write_pixel(point.x() as usize, point.y() as usize, color);
|
||||||
|
|
||||||
|
//}
|
||||||
|
write_canvas_to_file(canvas, "clock.ppm");
|
||||||
|
|
||||||
|
println!("Ending clock!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user