1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Extract lego example

This commit is contained in:
Andrey Pohilko 2017-12-26 19:32:47 +03:00
parent 4efe3705ec
commit b0bdbebf56
2 changed files with 85 additions and 71 deletions

81
examples/plotter/lego.py Normal file
View File

@ -0,0 +1,81 @@
def lego(plotter, t):
h = t * 5.0
w = t * 3.0
plotter.move(-t * 2.0, 0)
l(h, plotter, t, w)
plotter.move(0, w + t)
e(h, plotter, t, w)
plotter.move(0, w + t)
g(plotter, t)
plotter.move(0, w + t)
o(plotter, t)
def o(plotter, t):
# O
plotter.move(t, 0)
plotter.line(3 * t, 0)
plotter.line(t, t)
plotter.line(0, t)
plotter.line(-t, t)
plotter.line(-3 * t, 0)
plotter.line(-t, -t)
plotter.line(0, -t)
plotter.line(t, -t)
plotter.move(0, t)
plotter.line(3 * t, 0)
plotter.line(0, t)
plotter.line(-3 * t, 0)
plotter.line(0, -t)
def g(plotter, t):
# G
plotter.move(t, 0)
plotter.line(3 * t, 0)
plotter.line(t, t)
plotter.line(0, t)
plotter.line(-t, t)
plotter.line(-t, 0)
plotter.line(0, -t)
plotter.line(t, 0)
plotter.line(0, -t)
plotter.line(-3 * t, 0)
plotter.line(0, t)
plotter.line(t * 0.25, 0)
plotter.line(0, -t * 0.25)
plotter.line(t * 0.75, 0)
plotter.line(0, t * 1.25)
plotter.line(-3 * t, 0)
plotter.line(0, -t)
plotter.line(t, 0)
plotter.line(0, -t)
plotter.line(t, -t)
plotter.move(-t, 0)
def e(h, plotter, t, w):
# E
plotter.line(h, 0)
plotter.line(0, w)
plotter.line(-t, 0)
plotter.line(0, -2 * t)
plotter.line(-t, 0)
plotter.line(0, t)
plotter.line(-t, 0)
plotter.line(0, -t)
plotter.line(-t, 0)
plotter.line(0, 2 * t)
plotter.line(-t, 0)
plotter.line(0, -w)
def l(h, plotter, t, w):
# L
plotter.line(h, 0)
plotter.line(0, t)
plotter.line(-(h - t), 0)
plotter.line(0, 2 * t)
plotter.line(-t, 0)
plotter.line(0, -w)

View File

@ -55,75 +55,6 @@ def circles():
plotter.circle(FIELD_WIDTH)
def lego():
t = FIELD_WIDTH / 5.0
h = t * 5.0
w = t * 3.0
plotter.move(-t * 2.0, 0)
plotter.line(h, 0)
plotter.line(0, t)
plotter.line(-(h - t), 0)
plotter.line(0, 2 * t)
plotter.line(-t, 0)
plotter.line(0, -w)
plotter.move(0, w + t)
plotter.line(h, 0)
plotter.line(0, w)
plotter.line(-t, 0)
plotter.line(0, -2 * t)
plotter.line(-t, 0)
plotter.line(0, t)
plotter.line(-t, 0)
plotter.line(0, -t)
plotter.line(-t, 0)
plotter.line(0, 2 * t)
plotter.line(-t, 0)
plotter.line(0, -w)
plotter.move(0, w + t)
plotter.move(t, 0)
plotter.line(3 * t, 0)
plotter.line(t, t)
plotter.line(0, t)
plotter.line(-t, t)
plotter.line(-t, 0)
plotter.line(0, -t)
plotter.line(t, 0)
plotter.line(0, -t)
plotter.line(-3 * t, 0)
plotter.line(0, t)
plotter.line(t, 0)
plotter.line(0, t)
plotter.line(-3 * t, 0)
plotter.line(0, -t)
plotter.line(t, 0)
plotter.line(0, -t)
plotter.line(t, -t)
plotter.move(-t, 0)
plotter.move(0, w + t)
plotter.move(t, 0)
plotter.line(3 * t, 0)
plotter.line(t, t)
plotter.line(0, t)
plotter.line(-t, t)
plotter.line(-3 * t, 0)
plotter.line(-t, -t)
plotter.line(0, -t)
plotter.line(t, -t)
plotter.move(0, t)
plotter.line(3 * t, 0)
plotter.line(0, t)
plotter.line(-3 * t, 0)
plotter.line(0, -t)
def square_spiral():
rounds = 7
step = plotter.base_speed / rounds / 3.0
@ -212,6 +143,8 @@ def snowflake(scale=1.0):
for item in reversed(vals):
plotter.line(item[0] * zoom, -item[1] * zoom)
plotter.line(0.05 * zoom, 0)
def angles_experiment():
parts = 2
@ -291,9 +224,9 @@ if __name__ == '__main__':
# plotter.rectangle(FIELD_WIDTH / 5.0, FIELD_WIDTH / 5.0, solid=True)
# square_spiral()
# lego()
snowflake(0.75)
# christmas_tree()
# snowflake(0.5)
# lego(plotter, FIELD_WIDTH / 5.0)
pass
finally:
plotter.finalize()