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

View File

@ -13,7 +13,7 @@ class LSystem(object):
def step(self, value): def step(self, value):
def func(match): def func(match):
rule = self.rules[match.group(0)] rule = self.rules[match.group(0)]
if isinstance(rule, basestring): if isinstance(rule, str):
return rule return rule
return random.choice(rule) return random.choice(rule)
return self.pattern.sub(func, value) 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.rotate_and_scale_to_fit(12, 8.5, step=90)
# d = d.sort_paths() # d = d.sort_paths()
# d = d.join_paths(0.015) # 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) axi.draw(d)
if __name__ == '__main__': if __name__ == '__main__':