This commit is contained in:
Michael Fogleman 2018-03-04 21:17:46 -05:00
parent dfb41d54a1
commit bf422c3ed8
3 changed files with 4 additions and 12 deletions

View File

@ -244,14 +244,11 @@ class Drawing(object):
return Drawing(paths)
def render(self, scale=109, margin=1, line_width=0.35/25.4,
bounds=None, show_bounds=True,
use_axi_bounds=False, show_axi_bounds=False):
bounds=None, show_bounds=True):
if cairo is None:
raise Exception('Drawing.render() requires cairo')
bounds = bounds or self.bounds
x1, y1, x2, y2 = bounds
if use_axi_bounds:
x1, y1, x2, y2 = (0, 0, 12, 8.5)
w = x2 - x1
h = y2 - y1
margin *= scale
@ -266,15 +263,10 @@ class Drawing(object):
dc.translate(-x1, -y1)
dc.set_source_rgb(1, 1, 1)
dc.paint()
if show_axi_bounds:
dc.set_source_rgb(0.5, 0.5, 0.5)
dc.set_line_width(1 / scale)
dc.rectangle(0, 0, 12, 8.5)
dc.stroke()
if show_bounds:
dc.set_source_rgb(0.5, 0.5, 0.5)
dc.set_line_width(1 / scale)
dc.rectangle(*bounds)
dc.rectangle(x1, y1, w, h)
dc.stroke()
dc.set_source_rgb(0, 0, 0)
dc.set_line_width(line_width)

View File

@ -13,7 +13,7 @@ class LSystem(object):
def step(self, value):
def func(match):
rule = self.rules[match.group(0)]
if isinstance(rule, basestring):
if isinstance(rule, str):
return rule
return random.choice(rule)
return self.pattern.sub(func, value)

View File

@ -14,7 +14,7 @@ def main():
d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
# d = d.sort_paths()
# d = d.join_paths(0.015)
d.render().write_to_png('out.png')
d.render(bounds=axi.V3_BOUNDS).write_to_png('out.png')
axi.draw(d)
if __name__ == '__main__':