func run(seed int) { // fmt.Println(seed) rand.Seed(int64(seed)) eye := ln.Vector{} center := ln.Vector{0.5, 0, 8} up := ln.Vector{0, 0, 1} scene := ln.Scene{} n := 9.0 points := pt.PoissonDisc(-n, -n, n, n, 2, 32) for _, p := range points { z := rand.Float64()*5 + 20 v0 := ln.Vector{p.X, p.Y, 0} v1 := ln.Vector{p.X, p.Y, z} if v0.Distance(eye) < 1 { continue } c := ln.NewTransformedOutlineCone(eye, up, v0, v1, z/64) tree := Tree{c, v0, v1} scene.Add(&tree) } width := 2048.0 height := 2048.0 fovy := 90.0 paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.1) path := fmt.Sprintf("out%d.png", seed) paths.WriteToPNG(path, width, height) paths.Print() }
func main() { rand.Seed(1211) eye := ln.Vector{8, 8, 8} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} scene := ln.Scene{} for a := 0; a < 50; a++ { n := 200 xs := LowPassNoise(n, 0.3, 4) ys := LowPassNoise(n, 0.3, 4) zs := LowPassNoise(n, 0.3, 4) ss := LowPassNoise(n, 0.3, 4) position := ln.Vector{} for i := 0; i < n; i++ { sphere := ln.NewOutlineSphere(eye, up, position, 0.1) scene.Add(sphere) s := (ss[i]+1)/2*0.1 + 0.01 v := ln.Vector{xs[i], ys[i], zs[i]}.Normalize().MulScalar(s) position = position.Add(v) } } width := 380.0 * 5 height := 315.0 * 5 fovy := 50.0 paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) paths.Print() }
func CameraFOV(points []ln.Vector, eye, center ln.Vector) float64 { var result float64 c := center.Sub(eye).Normalize() for _, point := range points { d := point.Sub(eye).Normalize() a := math.Acos(d.Dot(c)) result = math.Max(result, a) } return ln.Degrees(result * 2 * 1.2) }
func (t *Tree) Paths() ln.Paths { paths := t.Shape.Paths() for i := 0; i < 128; i++ { p := math.Pow(rand.Float64(), 1.5)*0.5 + 0.5 c := t.V0.Add(t.V1.Sub(t.V0).MulScalar(p)) a := rand.Float64() * 2 * math.Pi l := (1 - p) * 8 d := ln.Vector{math.Cos(a), math.Sin(a), -2.75}.Normalize() e := c.Add(d.MulScalar(l)) paths = append(paths, ln.Path{c, e}) } return paths }
func cube(x, y, z float64) ln.Shape { size := 0.5 v := ln.Vector{x, y, z} return ln.NewCube(v.SubScalar(size), v.AddScalar(size)) }