summaryrefslogtreecommitdiff
path: root/src/global.rs
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 11:56:55 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 11:56:55 +0700
commitf3b0b1846c03bb2252830147481ba56056d6a405 (patch)
treec12ffef584b5a3ec318a2795d0a76638e8d28d70 /src/global.rs
parent202f7a315bcc0f7cd836348a29e9d06c7a4fa198 (diff)
upd: color struct
Diffstat (limited to 'src/global.rs')
-rw-r--r--src/global.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/global.rs b/src/global.rs
index 2f99cb9..b322746 100644
--- a/src/global.rs
+++ b/src/global.rs
@@ -3,8 +3,8 @@ use crate::calculus::calculus::Point3;
// "Ideal" aspect ratio, allowing fraction
-pub const ASPECT_RATIO: f32 = 9.0f32 / 5.0f32;
-pub const IMG_WIDTH: usize = 1000;
+pub const ASPECT_RATIO: f32 = 16.0f32 / 9.0f32;
+pub const IMG_WIDTH: usize = 400;
const IMG_HEIGHT_TMP: usize = (IMG_WIDTH as f32 / ASPECT_RATIO) as usize;
pub const IMG_HEIGHT: usize = if (IMG_HEIGHT_TMP < 1) { 1 } else { IMG_HEIGHT_TMP };
@@ -28,6 +28,11 @@ impl Pixel {
b: (255.999 * b) as u8,
}
}
+
+ pub fn from_color(color: &Color) -> Self {
+ let (r, g, b) = (color.r, color.g, color.b);
+ Self::from_frac(r, g, b)
+ }
}
impl Default for Pixel {
@@ -37,3 +42,31 @@ impl Default for Pixel {
}
pub type DisplayBuffer = [[Pixel; IMG_WIDTH]; IMG_HEIGHT];
+
+pub struct Color {
+ pub r: f32,
+ pub g: f32,
+ pub b: f32,
+}
+
+impl Color {
+ pub fn new(r: f32, g: f32, b: f32) -> Self {
+ Self { r, g, b }
+ }
+
+ pub fn mul_scalar(&self, scalar: f32) -> Color {
+ Self {
+ r: self.r * scalar,
+ g: self.g * scalar,
+ b: self.b * scalar,
+ }
+ }
+
+ pub fn add(&self, other: &Self) -> Color {
+ Self {
+ r: self.r + other.r,
+ g: self.g + other.g,
+ b: self.b + other.b
+ }
+ }
+}