|
|
|
from random import choice
|
|
|
|
from random import randrange
|
|
|
|
import re # libary to search and replace strings in the postscript file
|
|
|
|
from dictionary import font_index
|
|
|
|
from generate_postscript import generate_postscript
|
|
|
|
|
|
|
|
|
|
|
|
# function with three arguments
|
|
|
|
def whoosh(previous_module, current_module, module):
|
|
|
|
|
|
|
|
|
|
|
|
font = font_index[module[1]] # use font_index from dictionary to translate the fontname
|
|
|
|
|
|
|
|
paraA = int(module[2])
|
|
|
|
paraB = int(module[3])
|
|
|
|
paraC = int(module[4])
|
|
|
|
paraD = int(module[5])
|
|
|
|
paraE = int(module[6])
|
|
|
|
paraF = int(module[7])
|
|
|
|
paraG = int(module[8])
|
|
|
|
|
|
|
|
paraLine = int(module[9])
|
|
|
|
|
|
|
|
|
|
|
|
#use text from text file that was written by dynamic glyph module
|
|
|
|
textFile=open("dynamic_glyph.txt", "rt")
|
|
|
|
textContent = textFile.read()
|
|
|
|
if textContent != "": #use content of text file to define text variable
|
|
|
|
textIn = textContent
|
|
|
|
textIn = textIn.replace("\n", "")
|
|
|
|
else: #if text file is emptpy: randomly pick a default text (in case keyboard module is not used)
|
|
|
|
defaultText = ["Modular Matter", "MODULAR MATTER", "Rewire your prints!", "REWIRE YOUR PRINTS!"]
|
|
|
|
textIn = choice(defaultText)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
words = textIn.split(" ")
|
|
|
|
textOut = ""
|
|
|
|
firstWords = ""
|
|
|
|
mashWords = ""
|
|
|
|
patchWords = ""
|
|
|
|
|
|
|
|
#add to output: original text
|
|
|
|
origin = textIn + "\n"
|
|
|
|
textOut += origin
|
|
|
|
|
|
|
|
#add to output: pyramid with the first two words of the text (or the first word only)
|
|
|
|
#paraA and paraB
|
|
|
|
for x in range(1, paraA+1):
|
|
|
|
for y in range(1, paraB+1):
|
|
|
|
if len(words) >= 2:
|
|
|
|
firstWords = ((words[0]+" ")*x) + ((words[1] +" ")*y)
|
|
|
|
textOut += firstWords + "\n"
|
|
|
|
else:
|
|
|
|
firstWords = (words[0]+" ")*x*y
|
|
|
|
textOut += firstWords + "\n"
|
|
|
|
|
|
|
|
#add to output: original text
|
|
|
|
textOut += origin
|
|
|
|
|
|
|
|
|
|
|
|
#add to output: each round a new line with added random word
|
|
|
|
#paraC
|
|
|
|
for z in range(1, paraC+1):
|
|
|
|
mashWords += choice(words) + " "
|
|
|
|
textOut += mashWords + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
#add to output: each round the original text + random number of spaces
|
|
|
|
#paraD and paraE
|
|
|
|
for q in range(1, paraD+1):
|
|
|
|
textOut += origin
|
|
|
|
textOut += ' ' * randrange(paraE)
|
|
|
|
|
|
|
|
|
|
|
|
#add to output: each round the last word of the original text
|
|
|
|
#paraF
|
|
|
|
for s in range(1, paraF+1):
|
|
|
|
lastWord = (words[-1]+" ")
|
|
|
|
textOut += lastWord + "\n"
|
|
|
|
|
|
|
|
#add to output: each round a new line with 3 added random words
|
|
|
|
#paraG
|
|
|
|
for r in range(1, paraG+1):
|
|
|
|
patchWords += choice(words) + " " + choice(words) + " " + choice(words) + " "
|
|
|
|
textOut += patchWords + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
text = ''
|
|
|
|
tmp_line = ''
|
|
|
|
count = 0
|
|
|
|
for character in textOut:
|
|
|
|
|
|
|
|
if len(tmp_line) < paraLine:
|
|
|
|
tmp_line += character
|
|
|
|
if len(textOut) == count+1:
|
|
|
|
text = text + tmp_line + "\n"
|
|
|
|
else:
|
|
|
|
tmp_line += character
|
|
|
|
text = text + tmp_line + "\n"
|
|
|
|
tmp_line = ''
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
#print(text)
|
|
|
|
#return text
|
|
|
|
|
|
|
|
#print(textOut)
|
|
|
|
#return textOut
|
|
|
|
|
|
|
|
#split the text into lines to place them separated
|
|
|
|
text = text.split("\n")
|
|
|
|
paragraph = ""
|
|
|
|
for row in text:
|
|
|
|
paragraph = paragraph + "(" + row + ") true charpath newline-whoosh "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
script = """
|
|
|
|
|
|
|
|
newpath
|
|
|
|
% WHOOSH
|
|
|
|
|
|
|
|
/"""+font+"""
|
|
|
|
% fontname
|
|
|
|
|
|
|
|
14 selectfont
|
|
|
|
% fontsize in points, establishes the font as the current one
|
|
|
|
|
|
|
|
/x-whoosh { 20 } def
|
|
|
|
% define x position
|
|
|
|
|
|
|
|
/y-whoosh { 700 } def
|
|
|
|
% define y position
|
|
|
|
|
|
|
|
/lg-whoosh { 17 } def
|
|
|
|
% define linespacing
|
|
|
|
|
|
|
|
/newline-whoosh { y-whoosh lg-whoosh sub /y-whoosh exch def x-whoosh y-whoosh moveto } def
|
|
|
|
% define newline (position of new line) by using subtracting linespacing (lg) from y posiition and define that as the new y position (exch-ange), finally move to x position and re-defined y position
|
|
|
|
|
|
|
|
x-whoosh y-whoosh moveto
|
|
|
|
% x and y coordinates in px (origin is the lower-left corner of the page)
|
|
|
|
|
|
|
|
"""+paragraph+"""
|
|
|
|
|
|
|
|
fill
|
|
|
|
% fill the text in parentheses
|
|
|
|
|
|
|
|
showpage
|
|
|
|
% print all on a page
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generate_postscript(previous_module, current_module, script) # call function
|