aboutsummaryrefslogtreecommitdiff
path: root/vec3.go
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-24 16:50:36 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-24 16:50:36 +0100
commit2f025ebfc6c9e3146ef1c356f99045edc203c9ee (patch)
treedb279ad3999be6a545d7ba80eef521df63592b66 /vec3.go
parent63cee9aa6eb62afb2e8e726d2de16b76935c5f4c (diff)
Chapter 8
Diffstat (limited to 'vec3.go')
-rw-r--r--vec3.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/vec3.go b/vec3.go
index 65d14e5..4212b46 100644
--- a/vec3.go
+++ b/vec3.go
@@ -53,9 +53,11 @@ func (v Vec3) Cross(w Vec3) Vec3 {
}
func (v Vec3) ToPPM() string {
- r := uint8(255.999 * v.X);
- g := uint8(255.999 * v.Y);
- b := uint8(255.999 * v.Z);
+ i := Interval{0, 0.999};
+
+ r := uint8(256 * i.Clamp(v.X));
+ g := uint8(256 * i.Clamp(v.Y));
+ b := uint8(256 * i.Clamp(v.Z));
return fmt.Sprintf("%3d %3d %3d", r, g, b);
}