def save_image(self): """ Save to SVG file. """ file_name = f'generated/{generate_uuid()}.svg' writeSVG(file_name, (self.polygon, )) return file_name
def printMultiBigChromosome(source, target, chromosomes): ans = [] colors = [] for i, chromosome in enumerate(chromosomes): tmp1, tmp2 = printBigChromosome(source, target, chromosome) for j in xrange(len(tmp1)): tmp1[j].shift(0, -1.5 * i) ans += tmp1 colors += tmp2 writeSVG( "testing4.svg", ans, height=(50 / len(chromosome)) * len(ans), fill_color=tuple(colors), fill_opacity=[0.3] * len(ans), ) return None
p = Polygon() shapes.append(p) p.addContour(datas[i]) p.shift(0,10) x, y = p.center() p.rotate(math.pi, x, y) return shapes def draw_polygon(shapes): ax = plt.axes() ax.set_xlim(-10, 150) ax.set_ylim(-10, 150) output_obj = list() for s in shapes: print s.contour(0) # x, y ,w, h = s.boundingBox() # output_obj.append(patches.Rectangle((x, y), w, h, fc='green')) output_obj.append(patches.Polygon(s.contour(0), fc='yellow')) # corner_points_2, hull_points 是最终坐标,然后通过新的坐标 for p in output_obj: ax.add_patch(p) plt.gca().set_aspect('equal') plt.title('Rate') plt.show() if __name__ == '__main__': s = test_polygon('f6.dxf') writeSVG('Operations.svg', s, width=600) draw_polygon(s)
from Polygon import * from Polygon.Shapes import Circle, Star, Rectangle from Polygon.IO import writeSVG p = Circle(5.5, points=128) p -= Circle(4.4, points=128) p += Circle(3.3, points=128) p -= Circle(2.2, points=128) p += Star(1.1) l = Rectangle(4, 14) l.shift(-4.3, -10.5) r = p ^ l writeSVG('logo.svg', [r], width=800)