diff options
author | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 15:31:09 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 15:31:26 +0300 |
commit | b3bef1bdddb73e386e6f54635d6bcc39efd1b911 (patch) | |
tree | 505f11d6fe9f524e4a4166503cfc4e59902f5e18 | |
parent | e444b6784e9e6867df3622ee986b4adbb7bcc685 (diff) | |
download | pistol-b3bef1bdddb73e386e6f54635d6bcc39efd1b911.tar.gz |
refactor: define WIDTH & HEIGHT in one place
-rw-r--r-- | src/camera.rs | 14 | ||||
-rw-r--r-- | src/main.rs | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/camera.rs b/src/camera.rs index 61afe97..ff4b4f7 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,6 +1,6 @@ -use cgmath::{Vector3, Matrix}; +use cgmath::Vector3; use cgmath::prelude::*; -use std::{cmp::{max, min}, f32::consts::PI, f64::MAX_EXP, fmt}; +use std::{cmp::{max, min}, f32::consts::PI, fmt}; type Vector = Vector3<f32>; @@ -12,16 +12,16 @@ pub fn rotate_z(vec: Vector, angle: f32) -> Vector { } } -const WIDTH: i32 = 180; -const HEIGHT: i32 = 60; +pub const HEIGHT: i32 = 40; +pub const WIDTH: i32 = HEIGHT * 3; #[derive(Debug)] -pub struct Buffer (pub [[char; 180]; 60]); +pub struct Buffer (pub [[char; WIDTH as usize]; HEIGHT as usize]); impl fmt::Display for Buffer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - for i in 0..60 { - for j in 0..180 { + for i in 0..HEIGHT as usize { + for j in 0..WIDTH as usize { write!(f, "{}", self.0[i][j])?; } writeln!(f)?; diff --git a/src/main.rs b/src/main.rs index ae1fafb..243ee2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod canvas; use std::f32::consts::PI; use cgmath::Vector3; -use crate::camera::{Buffer, Camera}; +use crate::camera::{Buffer, Camera, WIDTH, HEIGHT}; fn main() { let mut cam = Camera { @@ -11,9 +11,9 @@ fn main() { direction: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, angle: PI / 2.0, distance: 1.0, - aspect_ratio: 2.0 / 3.0, + aspect_ratio: 2.0 * HEIGHT as f32 / WIDTH as f32, brightness: 5.0, - buffer: Buffer([['.'; 180]; 60]), + buffer: Buffer([[' '; WIDTH as usize]; HEIGHT as usize]), time: 0.0, }; |