From b3bef1bdddb73e386e6f54635d6bcc39efd1b911 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 27 Oct 2021 15:31:09 +0300 Subject: refactor: define WIDTH & HEIGHT in one place --- src/camera.rs | 14 +++++++------- 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; @@ -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, }; -- cgit v1.2.3