Example #1
0
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)
}
Example #2
0
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()
}
Example #3
0
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()
}
Example #4
0
File: csg.go Project: fogleman/ln
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)
	}
}
Example #5
0
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))
}
Example #6
0
File: test.go Project: fogleman/ln
func cube(x, y, z float64) ln.Shape {
	a := ln.Vector{x - 0.5, y - 0.5, z - 0.5}
	b := ln.Vector{x + 0.5, y + 0.5, z + 0.5}
	return ln.NewCube(a, b)
}