Browse Source

added a multi_column example

master
televex 4 years ago
parent
commit
24c3d8af3e
  1. 48
      multi_column_page.py
  2. 14
      repeated_sinus_amplitude_variation.py

48
multi_column_page.py

@ -0,0 +1,48 @@
#!/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
# Define width and height of the output
width = 125
height = 27
# Import a text
text = open('texts/about.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 single column
#lines, remaining = make_column(text, height=height, line_width=sin_width, line_offset=cos_width)
# Transform the text into multiple columns
lines, remaining = make_multi_column(text, height=height, column_width=40, column_count=2, column_gap=5)
lines = translate(lines, x=20, 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)

14
repeated_sinus_amplitude_variation.py

@ -1,27 +1,27 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from asciiWriter.patterns import sinus_vertical from asciiWriter.patterns import sinus_vertical
from asciiWriter.utils import make_lines, visit, print_lines, merge from asciiWriter.utils import make_lines, visit, print_lines, merge, translate
from asciiWriter.marks import sentence, space from asciiWriter.marks import sentence, space
import random import random
# Define width and height of the output # Define width and height of the output
width = 75 width = 125
height = 75 height = 90
# As we draw multiple sinoids we will collect # As we draw multiple sinoids we will collect
# them in a list of layers # them in a list of layers
layers = [] layers = []
# Loop through an amplitude of -50 to 50 in steps of 10 # Loop through an amplitude of -50 to 50 in steps of 10
for amplitude in range(-50, 50, 10): for amplitude in range(-40, 50, 10):
# Set the pattern with the changing amplitude # Set the pattern with the changing amplitude
pattern = sinus_vertical(period=40, amplitude=amplitude) pattern = sinus_vertical(period=60, amplitude=amplitude)
# We use a sentence to draw the text # We use a sentence to draw the text
mark = sentence('OPEN DESIGN COURSE ') mark = sentence('VARIA-')
# Define a blank character # Define a blank character
blank = space() blank = space('-')
# Make the canvas # Make the canvas
lines = make_lines(width, height) lines = make_lines(width, height)

Loading…
Cancel
Save