This Cinema 4D Python Effector Script is generating random walker splines on selected geometries.
Python
Random_Walker_C4D_2024_v5_Grow_On_a_Shape (0 downloads )
import c4d, random
op: c4d.BaseObject
gen: c4d.BaseObject
doc: c4d.documents.BaseDocument
thread: c4d.threading.BaseThread
def main() -> bool:
moData = c4d.modules.mograph.GeGetMoData(op)
if moData is None:
return False
cnt = moData.GetCount ()
marr = moData.GetArray (c4d.MODATA_MATRIX)
frame = doc.GetTime().GetFrame(doc.GetFps())
global x, y, z, updated
hasField = op[c4d.FIELDS].HasContent()
fall = moData.GetFalloffs()
def walk():
for i in range(cnt):
marr[i] = updated[i]
x = updated[i].off.x
y = updated[i].off.y
z = updated[i].off.z
if frame % op[c4d.ID_USERDATA,2] == 0:
rnd = random.randint (0,5)
if rnd == 0:
x += op[c4d.ID_USERDATA,3]
x+= 10
if rnd == 1:
x -= op[c4d.ID_USERDATA,4]
if rnd == 2:
y+= op[c4d.ID_USERDATA,5]
if rnd == 3:
y -= op[c4d.ID_USERDATA,6]
if rnd == 4:
z+= op[c4d.ID_USERDATA,7]
if rnd == 5:
z -= op[c4d.ID_USERDATA,8]
updated[i].off = c4d.Vector (x, y, z)
if frame == 0:
updated = marr
walk()
moData.SetArray(c4d.MODATA_MATRIX, marr, hasField)
return True