Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update examples to accept optional image output name #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified examples/butterfly_test.py
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions examples/circles.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axi
import math
import random
import sys

def circle(cx, cy, r, n):
points = []
Expand Down Expand Up @@ -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()
6 changes: 5 additions & 1 deletion examples/device_test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axi
import time
import sys

from math import sin, cos, pi

Expand All @@ -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()
6 changes: 5 additions & 1 deletion examples/dragon_curve.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axi
import sys

def main(iteration):
turtle = axi.Turtle()
Expand All @@ -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)
6 changes: 5 additions & 1 deletion examples/field.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axi
import random
import time
import sys

from math import hypot, atan2, sin, cos, pi

Expand Down Expand Up @@ -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()
7 changes: 5 additions & 2 deletions examples/growth.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axi
import random
import sys

from collections import defaultdict
from math import pi, sin, cos, hypot, floor
Expand Down Expand Up @@ -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()
7 changes: 5 additions & 2 deletions examples/lindenmayer.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axi
import sys

def main():
system = axi.LSystem({
Expand All @@ -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()
Empty file modified examples/paths.py
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions examples/piet.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from shapely.geometry import LineString
import axi
import random
import sys

X1 = 0
X2 = 11
Expand Down Expand Up @@ -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()
8 changes: 5 additions & 3 deletions examples/stars.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axi
import math
import random
import sys

from axi.spatial import Index
from poisson_disc import poisson_disc
Expand Down Expand Up @@ -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()
6 changes: 5 additions & 1 deletion examples/text.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axi
import sys

LINES = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
Expand Down Expand Up @@ -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()
5 changes: 4 additions & 1 deletion examples/tree_rings.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()