func main() { scene := ln.Scene{} n := 20 for x := -n; x <= n; x++ { for y := -n; y <= n; y++ { // z := rand.Float64() * 3 // scene.Add(cube(float64(x), float64(y), float64(z))) // scene.Add(cube(float64(x), float64(y), float64(z+1))) // scene.Add(cube(float64(x), float64(y), float64(z+2))) } } n = 8 for x := -n; x <= n; x++ { for y := -n; y <= n; y++ { scene.Add(ln.NewSphere(ln.Vector{float64(x), float64(y), 0}, 0.45)) } } // scene.Add(ln.NewSphere(ln.Vector{0, 4, 0}, 4)) // scene.Add(ln.NewSphere(ln.Vector{-7, 0, 0}, 4)) // scene.Add(ln.NewSphere(ln.Vector{7, 0, 0}, 4)) eye := ln.Vector{8, 8, 1} center := ln.Vector{0, 0, -4.25} up := ln.Vector{0, 0, 1} width := 1024.0 height := 1024.0 paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01) paths.WriteToPNG("out.png", 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 main() { // create a scene and add a single cube scene := ln.Scene{} scene.Add(ln.NewCube(ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1})) // define camera parameters eye := ln.Vector{4, 3, 2} // camera position center := ln.Vector{0, 0, 0} // camera looks at up := ln.Vector{0, 0, 1} // up direction // define rendering parameters width := 1024.0 // rendered width height := 1024.0 // rendered height fovy := 50.0 // vertical field of view, degrees znear := 0.1 // near z plane zfar := 10.0 // far z plane step := 0.01 // how finely to chop the paths for visibility testing // compute 2D paths that depict the 3D scene paths := scene.Render(eye, center, up, width, height, fovy, znear, zfar, step) // save the result as a png paths.WriteToPNG("out.png", width, height) // save the result as an svg paths.WriteToSVG("out.svg", width, height) }
func main() { scene := ln.Scene{} n := 15 for x := -n; x <= n; x++ { for y := -n; y <= n; y++ { p := rand.Float64()*0.25 + 0.2 dx := rand.Float64()*0.5 - 0.25 dy := rand.Float64()*0.5 - 0.25 fx := float64(x) + dx*0 fy := float64(y) + dy*0 fz := rand.Float64()*3 + 1 shape := ln.NewCube(ln.Vector{fx - p, fy - p, 0}, ln.Vector{fx + p, fy + p, fz}) if x == 2 && y == 1 { continue } scene.Add(shape) } } eye := ln.Vector{1.75, 1.25, 6} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} width := 1024.0 height := 1024.0 paths := scene.Render(eye, center, up, width, height, 100, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) // paths.Print() }
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 Render(lines ln.Paths, matrix ln.Matrix) ln.Paths { scene := ln.Scene{} sphere := ln.NewSphere(ln.Vector{}, 1) earth := Earth{sphere, lines} shape := ln.NewTransformedShape(&earth, matrix) scene.Add(shape) eye := ln.LatLngToXYZ(35.7806, -78.6389, 1).Normalize().MulScalar(2.46) center := ln.Vector{} up := ln.Vector{0, 0, 1} return scene.Render(eye, center, up, 60, 1, 0.1, 100, 0.01) }
func main() { scene := ln.Scene{} box := ln.Box{ln.Vector{-2, -2, -4}, ln.Vector{2, 2, 2}} scene.Add(ln.NewFunction(function, box, ln.Below)) eye := ln.Vector{3, 0, 3} center := ln.Vector{1.1, 0, 0} up := ln.Vector{0, 0, 1} width := 1024.0 height := 1024.0 paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) paths.WriteToSVG("out.svg", width, height) // paths.Print() }
func main() { blocks := load("examples/mountain.csv") fmt.Println(len(blocks)) scene := ln.Scene{} size := ln.Vector{0.5, 0.5, 0.5} for _, v := range blocks { scene.Add(ln.NewCube(v.Sub(size), v.Add(size))) } eye := ln.Vector{90, -90, 70} center := ln.Vector{0, 0, -15} up := ln.Vector{0, 0, 1} width := 1920.0 height := 1080.0 paths := scene.Render(eye, center, up, width, height, 50, 0.1, 1000, 0.1) paths.WriteToPNG("out.png", width, height) // paths.Print() }
func main() { scene := ln.Scene{} mesh, err := ln.LoadOBJ("examples/suzanne.obj") if err != nil { panic(err) } mesh.UnitCube() scene.Add(ln.NewTransformedShape(mesh, ln.Rotate(ln.Vector{0, 1, 0}, 0.5))) // scene.Add(mesh) eye := ln.Vector{-0.5, 0.5, 2} center := ln.Vector{} up := ln.Vector{0, 1, 0} width := 1024.0 height := 1024.0 paths := scene.Render(eye, center, up, width, height, 35, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) }
func (m *Molecule) Paths(width, height float64) ln.Paths { scene := ln.Scene{} nodes := make([]ln.Vector, len(m.Atoms)) for i, atom := range m.Atoms { nodes[i] = ln.Vector{atom.X, atom.Y, atom.Z} } mid := ln.BoxForVectors(nodes).Center() for i, node := range nodes { nodes[i] = node.Sub(mid) } eye := CameraPosition(nodes) center := ln.Vector{} fov := CameraFOV(nodes, eye, center) up := ln.Vector{0, 0, 1} for i, node := range nodes { atom := m.Atoms[i] radius := float64(AtomicRadii[atom.Symbol]) / 100 scene.Add(ln.NewOutlineSphere(eye, up, node, radius*0.5)) } for _, bond := range m.Bonds { v0 := nodes[bond.I] v1 := nodes[bond.J] r := float64(bond.Type) / 16 scene.Add(ln.NewTransformedOutlineCylinder(eye, up, v0, v1, r)) } return scene.Render(eye, center, up, width, height, fov, 0.1, 100, 0.01) }
func main() { scene := ln.Scene{} for x := -2; x <= 2; x++ { for y := -2; y <= 2; y++ { z := rand.Float64() scene.Add(cube(float64(x), float64(y), z)) } } eye := ln.Vector{6, 5, 3} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} width := 1920.0 height := 1200.0 fovy := 30.0 paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) paths.WriteToSVG("out.svg", width, height) }
func main() { eye := ln.Vector{8, 8, 8} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} scene := ln.Scene{} n := 10 for x := -n; x <= n; x++ { for y := -n; y <= n; y++ { z := rand.Float64() * 3 v := ln.Vector{float64(x), float64(y), z} sphere := ln.NewOutlineSphere(eye, up, v, 0.45) scene.Add(sphere) } } width := 1920.0 height := 1200.0 fovy := 50.0 paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) }
func main() { scene := ln.Scene{} mesh, err := ln.LoadBinarySTL("bowser.stl") // mesh, err := ln.LoadOBJ("../pt/examples/bunny.obj") if err != nil { panic(err) } mesh.FitInside(ln.Box{ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}}, ln.Vector{0.5, 0.5, 0.5}) scene.Add(&Shape{*mesh}) // scene.Add(mesh) eye := ln.Vector{-2, 2, 1} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} width := 1024.0 * 2 height := 1024.0 * 2 paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) // paths.WriteToSVG("out.svg", width, height) // paths.Print() }
func main() { scene := ln.Scene{} mesh, err := ln.LoadBinarySTL("bowser.stl") // mesh, err := ln.LoadOBJ("../pt/examples/bunny.obj") if err != nil { panic(err) } mesh.FitInside(ln.Box{ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}}, ln.Vector{0.5, 0.5, 0.5}) cubes := mesh.Voxelize(1.0 / 64) for _, cube := range cubes { scene.Add(cube) } eye := ln.Vector{-1, -2, 0} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} width := 1024.0 * 2 height := 1024.0 * 2 paths := scene.Render(eye, center, up, width, height, 60, 0.1, 100, 0.01) paths.WriteToPNG("out.png", width, height) // paths.WriteToSVG("out.svg", width, height) // paths.Print() }
func main() { shape := ln.NewDifference( ln.NewIntersection( ln.NewSphere(ln.Vector{}, 1), ln.NewCube(ln.Vector{-0.8, -0.8, -0.8}, ln.Vector{0.8, 0.8, 0.8}), ), ln.NewCylinder(0.4, -2, 2), ln.NewTransformedShape(ln.NewCylinder(0.4, -2, 2), ln.Rotate(ln.Vector{1, 0, 0}, ln.Radians(90))), ln.NewTransformedShape(ln.NewCylinder(0.4, -2, 2), ln.Rotate(ln.Vector{0, 1, 0}, ln.Radians(90))), ) for i := 0; i < 90; i += 2 { fmt.Println(i) scene := ln.Scene{} m := ln.Rotate(ln.Vector{0, 0, 1}, ln.Radians(float64(i))) scene.Add(ln.NewTransformedShape(shape, m)) eye := ln.Vector{0, 6, 2} center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} width := 750.0 height := 750.0 paths := scene.Render(eye, center, up, width, height, 20, 0.1, 100, 0.01) paths.WriteToPNG(fmt.Sprintf("out%03d.png", i), width, height) } }
func (m *Molecule) Paths(width, height float64) ln.Paths { scene := ln.Scene{} camera := m.Camera() eye := camera.Eye.ln() center := camera.Center.ln() up := camera.Up.ln() fovy := camera.Fovy spheres, cylinders := m.Solids() for _, s := range spheres { scene.Add(ln.NewOutlineSphere(eye, up, s.Center.ln(), s.Radius*0.5)) } for _, c := range cylinders { scene.Add(ln.NewTransformedOutlineCylinder(eye, up, c.A.ln(), c.B.ln(), c.Radius)) } return scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01) }
func render(frame int) { cx := math.Cos(ln.Radians(float64(frame))) cy := math.Sin(ln.Radians(float64(frame))) scene := ln.Scene{} eye := ln.Vector{cx, cy, 0}.MulScalar(8) center := ln.Vector{0, 0, 0} up := ln.Vector{0, 0, 1} nodes := []ln.Vector{ {1.047, -0.000, -1.312}, {-0.208, -0.000, -1.790}, {2.176, 0.000, -2.246}, {1.285, -0.001, 0.016}, {-1.276, -0.000, -0.971}, {-0.384, 0.000, -2.993}, {-2.629, -0.000, -1.533}, {-1.098, -0.000, 0.402}, {0.193, 0.005, 0.911}, {-1.934, -0.000, 1.444}, {2.428, -0.000, 0.437}, {0.068, -0.000, 2.286}, {-1.251, -0.000, 2.560}, {1.161, -0.000, 3.261}, {1.800, 0.001, -3.269}, {2.783, 0.890, -2.082}, {2.783, -0.889, -2.083}, {-2.570, -0.000, -2.622}, {-3.162, -0.890, -1.198}, {-3.162, 0.889, -1.198}, {-1.679, 0.000, 3.552}, {1.432, -1.028, 3.503}, {2.024, 0.513, 2.839}, {0.839, 0.513, 4.167}, // {0.000000, 0.000000, 0.000000}, // {0.000000, 0.000000, 1.089000}, // {1.026719, 0.000000, -0.363000}, // {-0.513360, -0.889165, -0.363000}, // {-0.513360, 0.889165, -0.363000}, // // {0, 0, 0}, // {-1, 0, 0}, // {1, 0, 0}, // {0, 1, 0}, // {0, -1, 0}, // {0, 0, 1}, // {0, 0, -1}, // // {-1, 1, 1}, // {-1, 1, -1}, // {-1, -1, 1}, // {-1, -1, -1}, // {1, 1, 1}, // {1, 1, -1}, // {1, -1, 1}, // {1, -1, -1}, } edges := [][2]int{ {0, 1}, {0, 2}, {0, 3}, {1, 4}, {1, 5}, {2, 14}, {2, 15}, {2, 16}, {3, 8}, {3, 10}, {4, 6}, {4, 7}, {6, 17}, {6, 18}, {6, 19}, {7, 8}, {7, 9}, {8, 11}, {9, 12}, {11, 12}, {11, 13}, {12, 20}, {13, 21}, {13, 22}, {13, 23}, } for _, v := range nodes { scene.Add(ln.NewOutlineSphere(eye, up, v, 0.333)) } // for _, v0 := range nodes { // for _, v1 := range nodes { // if v0 == v1 { // continue // } for _, edge := range edges { v0 := nodes[edge[0]] v1 := nodes[edge[1]] d := v1.Sub(v0) z := d.Length() u := d.Cross(up).Normalize() a := math.Acos(d.Normalize().Dot(up)) m := ln.Translate(v0) if a != 0 { m = ln.Rotate(u, a).Translate(v0) } c := ln.NewOutlineCylinder(m.Inverse().MulPosition(eye), up, 0.1, 0, z) scene.Add(ln.NewTransformedShape(c, m)) } // } width := 750.0 height := 750.0 paths := scene.Render(eye, center, up, width, height, 60, 0.1, 100, 0.01) paths.WriteToPNG(fmt.Sprintf("out%03d.png", frame), width, height) }