larzraytrace
A real ray tracer, rendered to a real image.
Ray-sphere intersection by the quadratic formula, real lambertian and metal materials, recursive light bounces, antialiasing by sampling, gamma-corrected color - a genuine renderer in the spirit of Ray Tracing in One Weekend, not a toy. Every pixel is a real recursive ray_color() call; the output is a plain PPM image you can actually open.
larzscript pkg install raytrace
What you get
- Ray-sphere intersection, the real math
- Lambertian + metal materials
- Recursive light bounces
- Plain PPM output, no image library
Try it
import "raytrace" as rt
import "random" as rng
rng.seed(1)
let ground = rt.sphere(rt.vec3(0, -100.5, -1), 100, rt.lambertian(rt.vec3(0.8, 0.8, 0.0)))
let center = rt.sphere(rt.vec3(0, 0, -1), 0.5, rt.lambertian(rt.vec3(0.7, 0.3, 0.3)))
let metal_ball = rt.sphere(rt.vec3(1, 0, -1), 0.5, rt.metal(rt.vec3(0.8, 0.6, 0.2), 0.3))
let ppm = rt.render([ground, center, metal_ball], 20, 10, 4, 4)
let lines = ppm.strip().split("\n")
print(lines[0], lines[1], lines[2])
print("total lines:", len(lines))
print("a pixel:", lines[100])Output
P3 20 10 255 total lines: 203 a pixel: 183 175 114
Why it's in the Larz Stack
larzraytrace is a real Larzscript package (larzscript pkg install raytrace) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.