-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLevyFlight-NormalVariate.py
68 lines (53 loc) · 2.26 KB
/
LevyFlight-NormalVariate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import c4d
from c4d import documents # Unused. Find out why
from c4d import Vector
from random import seed
# Normal Variate distribution used for Rayleigh Flight.
# This is not a 'true' Levy Flight, but it produces nicer-looking results.
# For a longer tail, import the Pareto distribution (paretovariate), which is always positive.
from random import normalvariate as rand
from math import *
#########################################################################
#Constants
RANDOM_SEED = 8
SPHERE_RADIUS = 1
PIPE_RADIUS = 0.5
NUM_NODES = 40
RANGE = 800
#########################################################################
# Where to start randomizing
means = Vector(0, 1000, 0)
# Range?
ranges = Vector(RANGE, RANGE, RANGE)
SphereScale = Vector(SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS)
spheres = []
cylinders = []
# Init Random Funcs
seed(RANDOM_SEED)
def GetRandomVector(v=means):
"Returns a random vector with magnitude v (a vector quantity)"
return Vector(rand(v.x, ranges.x), rand(v.y, ranges.y), rand(v.z, ranges.z))
def AddSphere(i=0, position=Vector()):
"Adds a new sphere to the document and to the list. Defaults to the origin."
spheres.append(c4d.BaseObject(c4d.Osphere)) # Allocate a new Sphere object at (0, 0, 0)
spheres[i].SetAbsPos(position)
spheres[i].SetAbsScale(SphereScale)
doc.InsertObject(spheres[i])
def main():
AddSphere() # Add first one. for every other sphere, add a connector as well.
for i in xrange(1, NUM_NODES): # TODO change position
# Create next point
there = GetRandomVector(spheres[i - 1].GetAbsPos())
AddSphere(i=i, position=there)
myCylinder = c4d.BaseObject(c4d.Ocylinder)
cylinders.append(myCylinder)
delta = spheres[i].GetAbsPos() - spheres[i - 1].GetAbsPos()
pipeScale = Vector(PIPE_RADIUS, delta.GetLength() / 200 - SPHERE_RADIUS, PIPE_RADIUS)
cylinders[i - 1].SetAbsScale(pipeScale)
cylinders[i - 1].SetAbsPos(spheres[i - 1].GetAbsPos() + delta / 2)
cylinders[i - 1].SetRelRot(c4d.utils.VectorToHPB(- delta) + Vector(0, pi / 2, 0))
doc.InsertObject(cylinders[i - 1])
#For future use: returns a list of all the generated objects.
# return cylinders + spheres
# Run this
main()