axi/examples/text.py

55 lines
1.6 KiB
Python
Raw Normal View History

2017-04-01 03:29:02 +00:00
import axi
2017-04-02 01:27:59 +00:00
LINES = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
'incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis',
'nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu',
'fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in',
'culpa qui officia deserunt mollit anim id est laborum.',
]
LINES = [
'When you wish upon a star',
'Makes no difference who you are',
'Anything your heart desires will come to you',
]
2018-01-22 00:21:08 +00:00
LINES = [
'Five Seconds of Donkey Kong'
]
2017-04-02 01:27:59 +00:00
def stack_drawings(ds, spacing=0):
result = axi.Drawing()
y = 0
for d in ds:
d = d.origin().translate(-d.width / 2, y)
result.add(d)
y += d.height + spacing
return result
2017-04-01 03:29:02 +00:00
def main():
2018-01-22 00:21:08 +00:00
font = axi.FUTURAM
2017-04-02 01:27:59 +00:00
ds = [axi.Drawing(axi.text(line, font)).scale_to_fit_height(1) for line in LINES]
d = stack_drawings(ds, 0.1)
2017-04-01 03:29:02 +00:00
# d = d.rotate_and_scale_to_fit(12, 8.5, step=90)
2017-04-02 01:27:59 +00:00
# d = d.scale(0.02, 0.02)
# d = d.center(12, 8.5)
# d = d.move(0, 0, 0, 0)
d = d.scale_to_fit(12, 8.5)
2018-01-22 00:21:08 +00:00
d = d.scale_to_fit(12, 0.25)
2017-04-02 01:27:59 +00:00
# d = d.center(12, 8.5)
d = d.move(6, 0, 0.5, 0)
d = d.translate(0, 0.01)
2018-01-22 00:21:08 +00:00
d = d.move(6, 8.5, 0.5, 1)
d = d.translate(0, -0.01)
2017-04-02 01:27:59 +00:00
d = d.join_paths(0.01)
2017-04-01 03:29:02 +00:00
d.render().write_to_png('out.png')
2017-04-02 01:27:59 +00:00
print sum(x.t for x in axi.Device().plan_drawing(d))
2018-01-22 00:21:08 +00:00
axi.draw(d)
2017-04-01 03:29:02 +00:00
if __name__ == '__main__':
main()