You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 KiB

ASCII Canvas

(using Reportlab to export it as a PDF)

In [1]:
width = 75
height = 65
In [2]:
multipage = False
In [3]:
# Simple fill-up of a page, to set the reach of our canvas
lines = [] # All the lines will be stored here

for linenumber in range(height):
    line = 'x' * width
    lines.append(line)

print('\n'.join(lines))
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxx
In [5]:
# Another way to fill-up the page
import random 

lines = []

txt = open('txt/language.txt', 'r').read()
words = txt.split()

for linenumber in range(height):
    word = random.choice(words)
    length_of_word = len(word)
    nr_of_words_fit_in_line = width / length_of_word
    line = word * int(nr_of_words_fit_in_line)
    lines.append(line)
    
print('\n'.join(lines))
TuringcompleteTuringcompleteTuringcompleteTuringcompleteTuringcomplete
isisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisis
thanthanthanthanthanthanthanthanthanthanthanthanthanthanthanthanthanthan
givinggivinggivinggivinggivinggivinggivinggivinggivinggivinggivinggiving
OulipoOulipoOulipoOulipoOulipoOulipoOulipoOulipoOulipoOulipoOulipoOulipo
(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or(or
ideographic-pictorialideographic-pictorialideographic-pictorial
andandandandandandandandandandandandandandandandandandandandandandandandand
parts.parts.parts.parts.parts.parts.parts.parts.parts.parts.parts.parts.
converseconverseconverseconverseconverseconverseconverseconverseconverse
forforforforforforforforforforforforforforforforforforforforforforforforfor
MyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMyMy
performperformperformperformperformperformperformperformperformperform
“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a“a
whateverwhateverwhateverwhateverwhateverwhateverwhateverwhateverwhatever
becomebecomebecomebecomebecomebecomebecomebecomebecomebecomebecomebecome
complicatecomplicatecomplicatecomplicatecomplicatecomplicatecomplicate
typicallytypicallytypicallytypicallytypicallytypicallytypicallytypically
ButButButButButButButButButButButButButButButButButButButButButButButButBut
sincesincesincesincesincesincesincesincesincesincesincesincesincesincesince
ofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofof
likelikelikelikelikelikelikelikelikelikelikelikelikelikelikelikelikelike
notnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnotnot
ofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofof
ititititititititititititititititititititititititititititititititititititit
computercomputercomputercomputercomputercomputercomputercomputercomputer
misperceivesmisperceivesmisperceivesmisperceivesmisperceivesmisperceives
Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,
anotheranotheranotheranotheranotheranotheranotheranotheranotheranother
tototototototototototototototototototototototototototototototototototototo
controlcontrolcontrolcontrolcontrolcontrolcontrolcontrolcontrolcontrol
computercomputercomputercomputercomputercomputercomputercomputercomputer
metaphoricallymetaphoricallymetaphoricallymetaphoricallymetaphorically
andandandandandandandandandandandandandandandandandandandandandandandandand
thethethethethethethethethethethethethethethethethethethethethethethethethe
significance.significance.significance.significance.significance.
ininininininininininininininininininininininininininininininininininininin
sincesincesincesincesincesincesincesincesincesincesincesincesincesincesince
bebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebe
purepurepurepurepurepurepurepurepurepurepurepurepurepurepurepurepurepure
asasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasas
inputinputinputinputinputinputinputinputinputinputinputinputinputinputinput
lesslesslesslesslesslesslesslesslesslesslesslesslesslesslesslesslessless
structures—semanticstructures—semanticstructures—semantic
cantcantcantcantcantcantcantcantcantcantcantcantcantcantcant
isisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisis
isisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisis
functionsfunctionsfunctionsfunctionsfunctionsfunctionsfunctionsfunctions
shape,shape,shape,shape,shape,shape,shape,shape,shape,shape,shape,shape,
namenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename
atatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatatat
ininininininininininininininininininininininininininininininininininininin
isisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisisis
ofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofof
thethethethethethethethethethethethethethethethethethethethethethethethethe
humanshumanshumanshumanshumanshumanshumanshumanshumanshumanshumanshumans
terminals,terminals,terminals,terminals,terminals,terminals,terminals,
meaningmeaningmeaningmeaningmeaningmeaningmeaningmeaningmeaningmeaning
appropriatedappropriatedappropriatedappropriatedappropriatedappropriated
asasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasas
thatthatthatthatthatthatthatthatthatthatthatthatthatthatthatthatthatthat
bebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebe
ononononononononononononononononononononononononononononononononononononon
DigitalDigitalDigitalDigitalDigitalDigitalDigitalDigitalDigitalDigital
ofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofofof
In [ ]:
# Same as above + a "switch" to make multipaged PDFs
import random 

multipage = True
number_of_pages = 100

lines = []
pages = []

txt = open('txt/language.txt', 'r').read()
words = txt.split()

for page in range(number_of_pages):
    
    for linenumber in range(height):
        word = random.choice(words)
        length_of_word = len(word)
        nr_of_words_fit_in_line = width / length_of_word
        line = word * int(nr_of_words_fit_in_line)
        lines.append(line)
        
    # Add a page
    pages.append(lines)
    lines = []

for page in pages:
    print('\n'.join(page))
    print('-' * width)
In [ ]:
 
In [ ]:
 
In [ ]:
 

Exporting with Reportlab

In [4]:
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm

pagewidth = 210*mm
pageheight = 297*mm

c = Canvas("ASCII-canvas-to-PDF.pdf", pagesize=(pagewidth, pageheight), bottomup=0)
c.setFont('Courier', 12)

start_y = 10*mm # start position of the lines

y = start_y
lineheight = 4*mm

if multipage == True:
    for page in pages:
        for line in page:
            c.drawCentredString(pagewidth/2, y, line)
            y += lineheight
        c.showPage()
        y = start_y
else:
    for line in lines:
        c.drawCentredString(pagewidth/2, y, line)
        y += lineheight
    
c.save()
In [ ]: