from harmonic.cad.shapes import * from harmonic.cad.manager import * from harmonic.mz.manager import * from harmonic.mz.gui import * from harmonic.mz.data.fields import * from harmonic.mz.data import * from harmonic.meshGeom.math import * from harmonic.viewer3D import * def fib(n): f0 = 0 f1 = 1 f2 = 1 a = Pnt3f() b = Pnt3f(-1, -1, 0) a0 = Pnt3f() clr = Clr3f(1, 1, 0) group = ShapeNode("FibSquares") group.addToCurrent() #handy cad-zilla helpers cad = CAD_HighLevels() #figure max scale i = 0 while i < n: f2 = f0 + f1 f0 = f1 f1 = f2 i = i+1 #pre scale viewpoint to seem impressive mat = TMat() mat.scale(1/f2) mat.translate(-0.4, -0.3, 0) viewport = ViewerCore.viewports().getActiveView() f0 = 0 f1 = 1 i = 1 while i < n: f2 = f0 + f1 mod = i%4 if mod==0: a.x = a0.x + f1 + f2 a.y = a0.y b.x = a.x - f2 b.y = a.y - f2 clr = Clr3f(0, 0.75, 0) if mod==1: a.x = a0.x a.y = a0.y - f1 - f2 b.x = a.x - f2 b.y = a.y + f2 clr = Clr3f(0.5, 0.5, 0) if mod==2: a.x = a0.x - f1 - f2 a.y = a0.y b.x = a.x + f2 b.y = a.y + f2 clr = Clr3f(0.65, 0, 0) if mod==3: a.x = a0.x a.y = a0.y + f1 + f2 b.x = a.x + f2 b.y = a.y - f2 clr = Clr3f(0, 0, 0.65) center = Pnt3f((a.x + b.x)/2, (a.y + b.y)/2, 0) #shrink a little shrink = 0.1 r = Rect4f(a, b) r.ax += shrink r.ay += shrink r.bx -= shrink r.by -= shrink shape = cad.rect(Pnt3f(r.ax, r.ay, 0), Pnt3f(r.bx, r.by, 0)) region = cad.regionFromLoops([shape]) region.fillColor.setAllColors(clr) region.fillColor.makeUnreferenced() region.lineColor.setAllColors(Clr3f(1, 1, 1)) region.lineColor.makeUnreferenced() region.surface.xSurfaceMode.setInt(2) region.surface.makeUnreferenced() group.addNode(region) viewport.renderNow() f0 = f1 f1 = f2 a0.set(a) i = i+1 mz = MZ_HighLevels() mz.loadModule("harmonic.cad.manager.CAD") fib(9)