You are on page 1of 2

#GROW

import c4d
import math
from c4d import utils as u
#Welcome to the world of Python

started = False

def main():
global started
obj = op.GetObject()
doc = op.GetDocument()

speed = op[c4d.ID_USERDATA,7]
iterations = int(math.ceil(speed))
k = speed/iterations

initial = op[c4d.ID_USERDATA,1]
result = op[c4d.ID_USERDATA,2]
i_data = initial.GetAllHighlevelData()

grow = op[c4d.ID_USERDATA,4]

new_data = [0.0]*len(result.GetAllHighlevelData())

if not grow and not started:


result.SetAllHighlevelData(new_data)
elif grow:
if not started:
result.SetAllHighlevelData(initial.GetAllHighlevelData())
started = True
else:
r_data = result.GetAllHighlevelData()
n = u.Neighbor()
n.Init(obj)
allpoints = obj.GetAllPoints()
for iteration in xrange(iterations):
new_data = list(r_data)
point_ids = range(len(allpoints))
point_ids = [id for id in point_ids if r_data[id]<1]
for i in point_ids:
polys = n.GetPointPolys(i)
np = set()
for p in polys:
poly = obj.GetPolygon(p)
if i == poly.a:
np.add(poly.b)
np.add(poly.d)
elif i == poly.b:
np.add(poly.a)
np.add(poly.c)
elif i == poly.c:
np.add(poly.b)
np.add(poly.d if poly.c != poly.d else poly.a)
elif i == poly.d:
np.add(poly.c if poly.c != poly.d else poly.b)
np.add(poly.a)
weights = [r_data[id] for id in np]
mean_weights = sum(weights)/len(weights)
if op[c4d.ID_USERDATA,6]:
new_data[i] += min((r_data[i] + mean_weights *
u.noise.Turbulence(allpoints[i]*op[c4d.ID_USERDATA,5], op[c4d.ID_USERDATA,3],
True)) * k, 1.0)
else:
new_data[i] += min((r_data[i] + mean_weights) * k * .5,
1.0)
new_data[i] = (new_data[i], 1.0)[new_data[i]>1]
new_data[i] = (new_data[i], 0.0)[new_data[i]<0]
r_data = list(new_data)
result.SetAllHighlevelData(r_data)
n.Flush()

#INVERT
import c4d
from c4d import utils as u
#Welcome to the world of Python

def main():
obj = op.GetObject()
doc = op.GetDocument()

initial = op[c4d.ID_USERDATA,1]
result = op[c4d.ID_USERDATA,2]
i_data = initial.GetAllHighlevelData()
r_data = map(lambda x: 1-x, i_data)
result.SetAllHighlevelData(r_data)

You might also like