aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMartin Lehoux <martin@lehoux.net>2020-04-05 22:46:01 -0700
committerMartin Lehoux <martin@lehoux.net>2020-04-05 22:46:01 -0700
commite93eee4bb96bd2d81e422dc9d453da6138fd6ba2 (patch)
tree0ef600be27a5bcde32d04283563c7b9fb8dd50d5 /main.go
parent8730659596dbfdb9625c0fc413625b261f7d6d70 (diff)
misc - Doc
Diffstat (limited to 'main.go')
-rw-r--r--main.go83
1 files changed, 53 insertions, 30 deletions
diff --git a/main.go b/main.go
index 316ebff..7211f8e 100644
--- a/main.go
+++ b/main.go
@@ -7,46 +7,69 @@ import (
"github.com/schollz/progressbar"
)
-const HEIGHT = 100
-const WIDTH = 200
-const T_MIN = 0.001
-const T_MAX = 1000
-const RAY_PER_PIXEL = 100
-const MAX_DEPTH = 50
+const (
+ // Height of frame
+ Height = 1000
+ // Width of frame
+ Width = 2000
+ // TMin is the minimal no zero time
+ TMin = 0.001
+ // TMax limits time
+ TMax = 1000
+ // RaysPerPixel for anti-aliasing
+ RaysPerPixel = 10
+ // MaxDepth for ray boucing
+ MaxDepth = 50
+ // FPS Frames per second for movies
+ FPS = 60
+)
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}
- CAMERA := Camera{LOWER_LEFT_CORNER, ORIGIN, HORIZONTAL, VERTICAL}
+ // Scene
+ lowerLeftCorner := 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}
+ camera := Camera{lowerLeftCorner, origin, horizontal, vertical}
- MAT_RED := Lambertian{Color{0.7, 0.3, 0.3}}
- MAT_GREEN := Lambertian{Color{0.8, 0.8, 0.0}}
- METAL_GREY := Metal{Color{0.8, 0.8, 0.8}, 0.3}
- METAL_BROWN := Metal{Color{0.8, 0.6, 0.2}, 1.0}
+ matRed := Lambertian{Color{0.7, 0.3, 0.3}}
+ matGreen := Lambertian{Color{0.8, 0.8, 0.0}}
+ metalGrey := Metal{Color{0.8, 0.8, 0.8}, 0.3}
+ // metalBrown := Metal{Color{0.8, 0.6, 0.2}, 1.0}
+ glass := Dielectric{1.5}
WORLD := HitableList{
- Sphere{Vec3D{0.0, 0.0, -1.0}, 0.5, MAT_RED},
- Sphere{Vec3D{-1.0, 0.0, -1.0}, 0.5, METAL_GREY},
- Sphere{Vec3D{1.0, 0.0, -1.0}, 0.5, METAL_BROWN},
- Sphere{Vec3D{0.0, -100.5, -1.0}, 100.0, MAT_GREEN},
+ Sphere{Vec3D{0.0, 0.0, -1.0}, 0.5, glass},
+ Sphere{Vec3D{-1.0, 0.0, -1.0}, 0.5, metalGrey},
+ Sphere{Vec3D{1.0, 0.0, -1.0}, 0.5, matRed},
+ Sphere{Vec3D{0.0, -100.5, -1.0}, 100.0, matGreen},
}
+
+ // Program
+ // start := AddVec3D(Origin, Vec3D{-1.0, 0.0, 0.0})
+ // move := Vec3D{2.0, 0.0, 0.0}
frame := Frame{}
- bar := progressbar.New(HEIGHT)
- for x := 0; x < HEIGHT; x++ {
- for y := 0; y < WIDTH; y++ {
- var color_list [RAY_PER_PIXEL]Color
- for it := 0; it < RAY_PER_PIXEL; it++ {
- u := (float64(y) + rand.Float64()) / float64(WIDTH)
- v := (float64(x) + rand.Float64()) / float64(HEIGHT)
- ray := CAMERA.GetRay(u, v)
- color_list[it] = RayColor(ray, WORLD, 0)
+ bar := progressbar.New(Height)
+ bar.RenderBlank()
+ // for k := 0; k < FPS*DURATION; k++ {
+ // origin := AddVec3D(start, ScalarProduct(float64(k)/float64(FPS*DURATION), move))
+ // camera.origin = origin
+ for x := 0; x < Height; x++ {
+ for y := 0; y < Width; y++ {
+ var colorList [RaysPerPixel]Color
+ for it := 0; it < RaysPerPixel; it++ {
+ u := (float64(y) + rand.Float64()) / float64(Width)
+ v := (float64(x) + rand.Float64()) / float64(Height)
+ ray := camera.GetRay(u, v)
+ colorList[it] = RayColor(ray, WORLD, 0)
}
- color := ColorMeanSquare(color_list)
- frame[HEIGHT-1-x][y] = color.ToPixel()
+ color := ColorMeanSquare(colorList)
+ frame[Height-1-x][y] = color.ToPixel()
}
bar.Add(1)
}
frame.Save("img.ppm")
+ // frame.Save(fmt.Sprintf("frames/frame_%06d.ppm", k))
}
+
+// }