def cookieExample(): # construct a christmas cookie with the help of the shapes star = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4) circle = Circle(radius=1.0, center=(1.0, 3.0), points=64) cookie = star - circle # shift star and circle to the right to plot all polygons # on one page star.shift(5.0, 0.0) circle.shift(10.0, 0.0) # plot all three to an svg file writeSVG('Cookie.svg', (cookie, star, circle)) # break a polygon object into a list of polygons by arranging # it on tiles # tile into 3x3 parts plist = tileEqual(cookie, 3, 3) writeSVG('CookieTiled1.svg', plist) # test tile at x = 0.3, 0.5 and y = 2.7, 3.1 plist = tile(cookie, [0.3, 0.5], [2.7, 3.1]) writeSVG('CookieTiled2.svg', plist) # let's simulate an explosion, move all parts away # from the cookie's center, small parts are faster xc, yc = cookie.center() for p in plist: if p: # speed/distance dval = 0.1 / p.area() x, y = p.center() # move the part a little bit p.shift(dval * (x - xc), dval * (y - yc)) # and rotate it slightly ;-) p.rotate(0.2 * math.pi * (random.random() - 0.5)) writeSVG('CookieExploded.svg', plist)
def cookieExample(): # construct a christmas cookie with the help of the shapes star = Star(radius=2.0, center=(1.0, 3.0), beams=5, iradius=1.4) circle = Circle(radius=1.0, center=(1.0, 3.0), points=64) cookie = star-circle # shift star and circle to the right to plot all polygons # on one page star.shift(5.0, 0.0) circle.shift(10.0, 0.0) # plot all three to an svg file writeSVG('Cookie.svg', (cookie, star, circle)) # break a polygon object into a list of polygons by arranging # it on tiles # tile into 3x3 parts plist = tileEqual(cookie, 3, 3) writeSVG('CookieTiled1.svg', plist) # test tile at x = 0.3, 0.5 and y = 2.7, 3.1 plist = tile(cookie, [0.3, 0.5], [2.7, 3.1]) writeSVG('CookieTiled2.svg', plist) # let's simulate an explosion, move all parts away # from the cookie's center, small parts are faster xc, yc = cookie.center() for p in plist: if p: # speed/distance dval = 0.1 / p.area() x, y = p.center() # move the part a little bit p.shift(dval*(x-xc), dval*(y-yc)) # and rotate it slightly ;-) p.rotate(0.2*math.pi*(random.random()-0.5)) writeSVG('CookieExploded.svg', plist)
def testLargeOperations(self): sheet = Rectangle(1000, 500) perf = cloneGrid(Circle(0.5, points=32), 0, 200, 100, 5, 5) perfSheet = sheet - perf #print 'perfSheet has %d points in %d contours' % (perfSheet.nPoints(), len(perfSheet)) circle = Circle(400, points=512) circle.scale(1.0, 0.5) circle.shift(500, 250) perfCircle = circle & perfSheet #print 'perfCircle has %d points in %d contours' % (perfCircle.nPoints(), len(perfCircle)) perfCircle.write('perfcircle.gpf')
def testLargeOperations(self): sheet = Rectangle(1000, 500) perf = cloneGrid(Circle(0.5, points=32), 0, 200, 100, 5, 5) perfSheet = sheet - perf circle = Circle(400, points=512) circle.scale(1.0, 0.5) circle.shift(500, 250) perfCircle = circle & perfSheet perfCircle.write('perfcircle.gpf', ) c, h, p, hf = gpfInfo('perfcircle.gpf') self.assertEqual(c, len(perfCircle)) self.assertEqual(p, perfCircle.nPoints()) self.assertEqual(hf, True)