diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-04 18:23:27 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-04 18:23:27 -0700 |
| commit | 9d9c52d8dad4236214ffadc215037c287d4c8ecc (patch) | |
| tree | 315fafe83a3139c39c1b3c59f10cfd4444ad73db | |
| parent | f230ab264adebce9868d088ea408445d66254963 (diff) | |
feat - Add mean color functions
| -rw-r--r-- | color.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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 +} |
