a python library to draw with ASCII (but with Unicode)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

#!/usr/bin/env python3
from asciiWriter.text import make_column, make_multi_column
from asciiWriter.utils import merge, print_lines, make_lines, translate
import math
from os.path import join, dirname
# Define width and height of the output
width = 100
height = 370
# Import a text
text = open(join(dirname(__file__), 'data', 'language.txt')).read()
# Make an empty layers list
layers = []
def sin_width (line_nr, _):
amplitude = 25
period = 150 / (math.pi * 2)
return 50 + math.floor(math.sin(line_nr / period) * amplitude)
def cos_width (line_nr, _):
amplitude = 5
period = 20 / (math.pi * 2)
half_amplitude = amplitude * .5
return math.floor(half_amplitude + math.cos(line_nr / period) * half_amplitude)
# Transform the text into a column
try:
from hyphen import Hyphenator
h_en = Hyphenator('en_US')
lines, remaining = make_column(text, height=height, use_hyphenator=h_en, line_width=sin_width, line_offset=cos_width)
except ImportError:
lines, remaining = make_column(text, height=height, line_width=sin_width, line_offset=cos_width)
# Move the text slightly
lines = translate(lines, x=15, y=1)
# Add the lines to the layers
layers.append(lines)
# Merge the layers into one layer again
merged = merge(width, height, ' ', layers)
# Print the result
print_lines(merged)