aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--color.go5
-rw-r--r--main.go12
2 files changed, 12 insertions, 5 deletions
diff --git a/color.go b/color.go
index c710c75..2bee0af 100644
--- a/color.go
+++ b/color.go
@@ -15,3 +15,8 @@ func LinearBlend(color1 Color, color2 Color, param float64) Color {
param*color1.b + (1.0-param)*color2.b,
}
}
+
+func RayColor(ray Ray) 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)
+}
diff --git a/main.go b/main.go
index 52bcb12..981a324 100644
--- a/main.go
+++ b/main.go
@@ -4,14 +4,16 @@ const HEIGHT = 100
const WIDTH = 200
func main() {
+ LOWER_LEFT_CORNER := Vec3D{-2.0, -1.0, -1.0}
+ ORIGIN := Vec3D{0.0, 0.0, 0.0}
+ HORIZONTAL := Vec3D{4.0, 0.0, 0.0}
+ VERTICAL := Vec3D{0.0, 2.0, 0.0}
frame := Frame{}
for x := 0; x < HEIGHT; x++ {
for y := 0; y < WIDTH; y++ {
- color := Color{
- float64(y) / float64(WIDTH),
- float64(x) / float64(HEIGHT),
- 0.2,
- }
+ u, v := float64(y)/float64(WIDTH), float64(x)/float64(HEIGHT)
+ ray := Ray{ORIGIN, AddVec3D(AddVec3D(LOWER_LEFT_CORNER, ScalarProduct(u, HORIZONTAL)), ScalarProduct(v, VERTICAL))}
+ color := RayColor(ray)
frame[HEIGHT-1-x][y] = color.ToPixel()
}
}