From 9d9c52d8dad4236214ffadc215037c287d4c8ecc Mon Sep 17 00:00:00 2001 From: Martin Lehoux Date: Sat, 4 Apr 2020 18:23:27 -0700 Subject: feat - Add mean color functions --- color.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/color.go b/color.go index b8776ca..2dcf369 100644 --- a/color.go +++ b/color.go @@ -1,5 +1,7 @@ package main +import "math" + type Color struct { r, g, b float64 } @@ -25,3 +27,25 @@ func RayColor(ray Ray, hitable_list HitableList) Color { param := 0.5 * (ray.direction.Unit().y + 1) return LinearBlend(Color{0.5, 0.7, 1.0}, Color{1.0, 1.0, 1.0}, param) } + +func ColorMean(color_list [RAY_PER_PIXEL]Color) Color { + length := float64(len(color_list)) + mean_color := Color{} + for _, color := range color_list { + mean_color.r += color.r + mean_color.g += color.g + mean_color.b += color.b + } + mean_color.r /= length + mean_color.g /= length + mean_color.b /= length + return mean_color +} + +func ColorMeanSquare(color_list [RAY_PER_PIXEL]Color) Color { + mean_color := ColorMean(color_list) + mean_color.r = math.Sqrt(mean_color.r) + mean_color.g = math.Sqrt(mean_color.g) + mean_color.b = math.Sqrt(mean_color.b) + return mean_color +} -- cgit v1.3