CSGSMEDMI4B2TK4UA6PWGCDYPNSHUWRJXN6YNV6LCJWFXZI7UJ6QC
3NRFPYXPGOWBGL6W4K456TG5PSD5VANZSM5IE5OM73BVM64HWLGQC
RSWQPKYWMLVXPFAGSCLBEKSXR2VMBHQDWCHTZ3DNILL475H7MHTQC
EAI4GDFVBMMFBHE3DTHAO6M4CTOMMCX77CVEVUFSVNSEUYBCXTBAC
ACSSNXV42QLP5AJPQF5ZQJAC2BTIZULX3543SDQAJJT4LBETYF7AC
QHTTPQTALS2XJVJJ6CFOM5TKE7X3JJC73R465P2D6UCXD5BIIVXQC
ITLJXDCETDPXJCHHSYRGJL4V7UJWNG7BQP57PPDF365HMWPNHUQQC
OYLAFIHLW6O3VBMJHWRJM4QS5VEA2UJXLLTSHUEELUMYUA5L3NJAC
J4GXXT5TT6X7Y72ZBDX5WRWH5DHRYX2LLKYN77XMHOQXUJMBHWBAC
m = OUTPUT_SCALE
dx, dy = (PADDING, PADDING)
im = Image.new('RGB', (self.width * m + dx, self.height * m + dy))
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0, self.width * m, self.height * m), FILL_COLOR)
m = OUTPUT_SCALE
dx, dy = (PADDING, PADDING)
im = Image.new('RGB', (self.width * m + dx, self.height * m + dy))
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0, self.width * m, self.height * m), FILL_COLOR)
svg_root = ET.Element("svg")
svg_root.set("xmlns", "http://www.w3.org/2000/svg")
svg_root.set("viewBox", "0 0 " + str(self.width + PADDING) + " " + str(self.height + PADDING))
svg_root.set("width", str((self.width + PADDING) * m))
svg_root.set("height", str((self.height + PADDING) * m))
svg_root = ET.Element("svg")
svg_root.set("xmlns", "http://www.w3.org/2000/svg")
svg_root.set("viewBox", "0 0 " + str(self.width +
PADDING) + " " + str(self.height + PADDING))
svg_root.set("width", str((self.width + PADDING) * m))
svg_root.set("height", str((self.height + PADDING) * m))
svg_rect = ET.SubElement(svg_root, "rect")
svg_rect.set("x", "0")
svg_rect.set("y", "0")
svg_rect.set("width", "100%") #str(self.width * m))
svg_rect.set("height", "100%") #str(self.height * m))
svg_rect.set("fill", "rgb(" + str(FILL_COLOR[0]) + ", " + str(FILL_COLOR[1]) + ", " + str(FILL_COLOR[2]) + ")")
svg_rect = ET.SubElement(svg_root, "rect")
svg_rect.set("x", "0")
svg_rect.set("y", "0")
svg_rect.set("width", "100%") # str(self.width * m))
svg_rect.set("height", "100%") # str(self.height * m))
svg_rect.set("fill", "rgb(" + str(FILL_COLOR[0]) + ", " + str(
FILL_COLOR[1]) + ", " + str(FILL_COLOR[2]) + ")")
for quad in self.root.get_leaf_nodes(max_depth):
l, t, r, b = quad.box
box = (l * m + dx, t * m + dy, r * m - 1, b * m - 1)
if MODE == MODE_ELLIPSE:
draw.ellipse(box, quad.color)
for quad in self.root.get_leaf_nodes(max_depth):
l, t, r, b = quad.box
box = (l * m + dx, t * m + dy, r * m - 1, b * m - 1)
if MODE == MODE_ELLIPSE:
draw.ellipse(box, quad.color)
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("rx", "100%")
svg_rect.set("ry", "100%")
svg_rect.set("width", str(quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height",str(quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(quad.color[1]) + ", " + str(quad.color[2]) + ")")
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("rx", "100%")
svg_rect.set("ry", "100%")
svg_rect.set("width", str(
quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height", str(
quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(
quad.color[1]) + ", " + str(quad.color[2]) + ")")
elif MODE == MODE_ROUNDED_RECTANGLE:
radius = m * min((r - l), (b - t)) / 4
rounded_rectangle(draw, box, radius, quad.color)
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("rx", str(radius))
svg_rect.set("ry", str(radius))
svg_rect.set("width", str(
quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height", str(
quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(
quad.color[1]) + ", " + str(quad.color[2]) + ")")
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("rx", str(radius))
svg_rect.set("ry", str(radius))
svg_rect.set("width", str(quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height",str(quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(quad.color[1]) + ", " + str(quad.color[2]) + ")")
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("width", str(
quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height", str(
quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(
quad.color[1]) + ", " + str(quad.color[2]) + ")")
del draw
im.save(path, 'PNG')
tree = ET.ElementTree(svg_root)
tree.write("output.svg")
else:
draw.rectangle(box, quad.color)
svg_rect = ET.SubElement(svg_contents, "rect")
svg_rect.set("x", str(quad.box[0] + PADDING))
svg_rect.set("y", str(quad.box[1] + PADDING))
svg_rect.set("width", str(quad.box[2] - (quad.box[0] + PADDING)))
svg_rect.set("height",str(quad.box[3] - (quad.box[1] + PADDING)))
svg_rect.set("fill", "rgb(" + str(quad.color[0]) + ", " + str(quad.color[1]) + ", " + str(quad.color[2]) + ")")
del draw
im.save(path, 'PNG')
tree = ET.ElementTree(svg_root)
tree.write("output.svg")