Пример #1
0
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()
}
Пример #2
0
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)
}
Пример #3
0
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)
}
Пример #4
0
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)
}
Пример #5
0
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)
}