""" Koch Snowflake I 03.02.2022 (c) Juergen Meier (www.3d-meier.de) """ import c4d import random import math import cmath # Variablen und Konstanten Titel = 'Koch Snowflake I' # Name N = 1000000 # Anzahl Punkte Nv = 100 # Anzahl Punkte verwerfen dx = 2.0 # Breite Polygon dy = 2.0 # Hoehe Polygon Faktor = 1000 # Skalierungsfaktor s = math.sqrt(3.0) # Konstante xa = 0.5 a = 1/2.0 b = s/6.0 c = 1/3.0 d = 1/s e = 2/3.0 def CreatePolygonObject(): obj = c4d.BaseObject(c4d.Opolygon) obj.ResizeObject(4*N, N) obj.SetName(Titel) # Startwert der Berechnung x = 0.5 xa = x y = 0.5 # Zaehler fuer Punkte setzten zz = 0 # Zaehler fuer Polygone setzten zzz = 0 for i in xrange(0,Nv): zufall = random.randint(0,6) if zufall == 0: x = a*xa -b*y y = b*xa + a*y if zufall == 1: x = c*xa + d y = c*y + c if zufall == 2: x = c*xa y = c*y + e if zufall == 3: x = c*xa - d y = c*y + c if zufall == 4: x = c*xa - d y = c*y - c if zufall == 5: x = c*xa y = c*y - e if zufall == 6: x = c*xa + d y = c*y - c xa = x for i in xrange(0,N): zufall = random.randint(0,6) if zufall == 0: x = a*xa -b*y y = b*xa + a*y if zufall == 1: x = c*xa + d y = c*y + c if zufall == 2: x = c*xa y = c*y + e if zufall == 3: x = c*xa - d y = c*y + c if zufall == 4: x = c*xa - d y = c*y - c if zufall == 5: x = c*xa y = c*y - e if zufall == 6: x = c*xa + d y = c*y - c xa = x obj.SetPoint(zz, c4d.Vector((Faktor*x-dx/2.0),(Faktor*y+dy/2.0),0)) zz=zz+1 obj.SetPoint(zz, c4d.Vector((Faktor*x-dx/2.0),(Faktor*y-dy/2.0),0)) zz=zz+1 obj.SetPoint(zz, c4d.Vector((Faktor*x+dx/2.0),(Faktor*y+dy/2.0),0)) zz=zz+1 obj.SetPoint(zz, c4d.Vector((Faktor*x+dx/2.0),(Faktor*y-dy/2.0),0)) zz=zz+1 obj.SetPolygon(zzz, c4d.CPolygon(zz-1,zz-2,zz-4,zz-3)) zzz=zzz+1 # obj.Message(c4d.MSG_UPDATE) return obj def main(): plyobj = CreatePolygonObject() # doc.InsertObject(plyobj, None, None, True) c4d.EventAdd() if __name__=='__main__': main()