diff --git a/examples/butterfly_test.py b/examples/butterfly_test.py old mode 100644 new mode 100755 diff --git a/examples/circles.py b/examples/circles.py old mode 100644 new mode 100755 index 46b3f1d..7c90ce2 --- a/examples/circles.py +++ b/examples/circles.py @@ -1,6 +1,7 @@ import axi import math import random +import sys def circle(cx, cy, r, n): points = [] @@ -35,8 +36,10 @@ def main(): add(0, 0, 64, paths) drawing = axi.Drawing(paths).rotate_and_scale_to_fit(11, 8.5).sort_paths() im = drawing.render() - im.write_to_png('out.png') - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main() diff --git a/examples/device_test.py b/examples/device_test.py old mode 100644 new mode 100755 index eb47807..9c601d4 --- a/examples/device_test.py +++ b/examples/device_test.py @@ -1,5 +1,6 @@ import axi import time +import sys from math import sin, cos, pi @@ -17,7 +18,10 @@ def main(): for i in range(10): path.extend(circle(4, 4, (i + 1) * 0.2, 3600)) drawing = axi.Drawing([path]).simplify_paths(0.001) - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main() diff --git a/examples/dragon_curve.py b/examples/dragon_curve.py old mode 100644 new mode 100755 index 2e82f07..d508176 --- a/examples/dragon_curve.py +++ b/examples/dragon_curve.py @@ -1,4 +1,5 @@ import axi +import sys def main(iteration): turtle = axi.Turtle() @@ -9,7 +10,10 @@ def main(iteration): else: turtle.circle(1, 90, 36) drawing = turtle.drawing.rotate_and_scale_to_fit(11, 8.5, step=90) - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main(12) diff --git a/examples/field.py b/examples/field.py old mode 100644 new mode 100755 index 411284a..643dcfa --- a/examples/field.py +++ b/examples/field.py @@ -1,6 +1,7 @@ import axi import random import time +import sys from math import hypot, atan2, sin, cos, pi @@ -64,7 +65,10 @@ def main(): paths.append(path) drawing = axi.Drawing(paths).sort_paths().simplify_paths(0.001) - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main() diff --git a/examples/growth.py b/examples/growth.py old mode 100644 new mode 100755 index edcfc07..162b2fe --- a/examples/growth.py +++ b/examples/growth.py @@ -1,5 +1,6 @@ import axi import random +import sys from collections import defaultdict from math import pi, sin, cos, hypot, floor @@ -129,8 +130,10 @@ def main(): points, pairs = poisson_disc(0, 0, 11, 8.5, 0.035, 32) path = make_path(pairs) drawing = axi.Drawing([path]).scale_to_fit(11, 8.5) - drawing.render().write_to_png('out.png') - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main() diff --git a/examples/lindenmayer.py b/examples/lindenmayer.py old mode 100644 new mode 100755 index e85034c..5a0ac83 --- a/examples/lindenmayer.py +++ b/examples/lindenmayer.py @@ -1,4 +1,5 @@ import axi +import sys def main(): system = axi.LSystem({ @@ -14,8 +15,10 @@ 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') - axi.draw(d) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + d.render().write_to_png(sys.argv[1]) + else: + axi.draw(d) if __name__ == '__main__': main() diff --git a/examples/paths.py b/examples/paths.py old mode 100644 new mode 100755 diff --git a/examples/piet.py b/examples/piet.py old mode 100644 new mode 100755 index 9dc4353..1e77821 --- a/examples/piet.py +++ b/examples/piet.py @@ -1,6 +1,7 @@ from shapely.geometry import LineString import axi import random +import sys X1 = 0 X2 = 11 @@ -57,8 +58,10 @@ def main(): d = axi.Drawing(paths) d = d.sort_paths() d = d.join_paths(0.001) - d.render().write_to_png('out.png') - axi.draw(d) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + d.render().write_to_png(sys.argv[1]) + else: + axi.draw(d) if __name__ == '__main__': main() diff --git a/examples/stars.py b/examples/stars.py old mode 100644 new mode 100755 index 71873b7..7ee2cb3 --- a/examples/stars.py +++ b/examples/stars.py @@ -1,6 +1,7 @@ import axi import math import random +import sys from axi.spatial import Index from poisson_disc import poisson_disc @@ -38,9 +39,10 @@ def main(): drawing = axi.Drawing(paths) drawing = drawing.remove_paths_outside(11, 8.5) drawing = drawing.sort_paths() - # im = drawing.render() - # im.write_to_png('out.png') - axi.draw(drawing) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + drawing.render().write_to_png(sys.argv[1]) + else: + axi.draw(drawing) if __name__ == '__main__': main() diff --git a/examples/text.py b/examples/text.py old mode 100644 new mode 100755 index ccabbaf..b1864b5 --- a/examples/text.py +++ b/examples/text.py @@ -1,4 +1,5 @@ import axi +import sys LINES = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor', @@ -39,7 +40,10 @@ def main(): d = d.join_paths(0.01) d.render().write_to_png('out.png') print sum(x.t for x in axi.Device().plan_drawing(d)) - # axi.draw(d) + if len(sys.argv) > 1 and sys.argv[1].endswith(".png"): + d.render().write_to_png(sys.argv[1]) + else: + axi.draw(d) if __name__ == '__main__': main() diff --git a/examples/tree_rings.py b/examples/tree_rings.py old mode 100644 new mode 100755 index 7401981..81ec2f2 --- a/examples/tree_rings.py +++ b/examples/tree_rings.py @@ -39,7 +39,10 @@ def main(): paths = create_paths(Image.open(sys.argv[1])) drawing = axi.Drawing(paths).rotate_and_scale_to_fit(11, 8.5, step=90) drawing = drawing.sort_paths().join_paths(0.02) - axi.draw(drawing) + if len(sys.argv) > 2 and sys.argv[2].endswith(".png"): + drawing.render().write_to_png(sys.argv[2]) + else: + axi.draw(drawing) if __name__ == '__main__': main()