going around through the example scripts
This commit is contained in:
parent
da9f92e8ed
commit
1463c11280
37
asciiWriter/examples/multi_column.py
Normal file
37
asciiWriter/examples/multi_column.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from asciiWriter.text import make_column, make_multi_column
|
||||
from asciiWriter.utils import merge, print_lines, make_lines, translate
|
||||
from asciiWriter.marks import single
|
||||
|
||||
import math
|
||||
|
||||
from os.path import join, dirname
|
||||
|
||||
# Define width and height of the output
|
||||
width = 80
|
||||
height = 265 # it would be nice to make an "automated fit" function, that defines the height based on an attempt to fill both columns.
|
||||
|
||||
# Import a text
|
||||
text = open(join(dirname(__file__), 'data', 'language.txt')).read()
|
||||
|
||||
# Collect layers in a list
|
||||
layers = []
|
||||
|
||||
# Transform the text into multiple columns
|
||||
lines, remaining = make_multi_column(text, height=height, column_width=35, column_count=2, column_gap=5)
|
||||
# Move the lines 3 characters to the right
|
||||
lines = translate(lines, x=3, y=0)
|
||||
|
||||
# Create an background
|
||||
background = make_lines(width, height, ' ')
|
||||
|
||||
# Add all your layers to the layers list
|
||||
layers.append(background)
|
||||
layers.append(lines)
|
||||
|
||||
# Merge the layers into one layer again
|
||||
merged = merge(width, height, ' ', layers)
|
||||
|
||||
# Print the result
|
||||
print_lines(merged)
|
@ -7,7 +7,7 @@ from asciiWriter.marks import sentence, single
|
||||
import random
|
||||
|
||||
# Define width and height of the output
|
||||
width = 125
|
||||
width = 100
|
||||
height = 90
|
||||
|
||||
# As we draw multiple sinoids we will collect
|
||||
@ -15,11 +15,11 @@ height = 90
|
||||
layers = []
|
||||
|
||||
# Loop through an amplitude of -50 to 50 in steps of 10
|
||||
for amplitude in range(-40, 50, 10):
|
||||
for amplitude in range(-50, 50, 10):
|
||||
# Set the pattern with the changing amplitude
|
||||
pattern = sinus_vertical(period=60, amplitude=amplitude)
|
||||
# We use a sentence to draw the text
|
||||
mark = sentence('VARIA-')
|
||||
mark = sentence('asciiWriter-')
|
||||
# Define a blank character
|
||||
blank = single('-')
|
||||
|
||||
@ -29,7 +29,7 @@ for amplitude in range(-40, 50, 10):
|
||||
result = visit(lines, pattern, mark, blank)
|
||||
# Add it the result to the list of layers
|
||||
layers.append(result)
|
||||
|
||||
|
||||
# Merge the layers into one layer again
|
||||
merged = merge(width, height, blank(), layers)
|
||||
|
||||
|
44
asciiWriter/examples/single_column.py
Normal file
44
asciiWriter/examples/single_column.py
Normal file
@ -0,0 +1,44 @@
|
||||
#!/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 = 250 # it would be nice to make an "automated fit" function, that defines the height based on an attempt to fill both columns.
|
||||
|
||||
# Import a text
|
||||
text = open(join(dirname(__file__), 'data', 'language.txt')).read()
|
||||
|
||||
# Import a hyphenator
|
||||
|
||||
# Make an empty layers list
|
||||
layers = []
|
||||
|
||||
# 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=80, line_offset=0)
|
||||
except ImportError:
|
||||
lines, remaining = make_column(text, height=height, line_width=80, line_offset=0)
|
||||
|
||||
# Transform the text into multiple columns
|
||||
# lines, remaining = make_multi_column(text, height=height-3, use_hyphenator=h_en)
|
||||
lines = translate(lines, x=10, y=0)
|
||||
|
||||
# Create an background
|
||||
background = make_lines(width, height, ' ')
|
||||
|
||||
# Add all your layers to the layers list
|
||||
layers.append(background)
|
||||
layers.append(lines)
|
||||
|
||||
# Merge the layers into one layer again
|
||||
merged = merge(width, height, ' ', layers)
|
||||
|
||||
# Print the result
|
||||
print_lines(merged)
|
@ -13,9 +13,9 @@ height = 75
|
||||
# of 30 characters. Slightly less than half our canvas width
|
||||
pattern = sinus_vertical(period=40, amplitude=30)
|
||||
# We use a sentence to draw the text
|
||||
mark = sentence('OPEN DESIGN COURSE ')
|
||||
mark = sentence('HELLO ASCIIWRITER ')
|
||||
# Define a blank character
|
||||
blank = single('-')
|
||||
blank = single('|')
|
||||
|
||||
# Make the canvas
|
||||
lines = make_lines(width, height)
|
||||
|
Loading…
Reference in New Issue
Block a user