Dateien hochladen nach „output_module“

main
ohjian 1 year ago
parent e7edd3df05
commit 6505d04cc5

@ -0,0 +1,15 @@
font_index = {
"T-1": "Times-Roman",
"T-2": "Times-Italic",
"T-3": "Times-Bold",
"T-4": "Times-BoldItalic",
"H-1": "Helvetica",
"H-2": "Helvetica-Oblique",
"H-3": "Helvetica-Bold",
"H-4": "Helvetica-BoldOblique",
"C-1": "Courier",
"C-2": "Courier-Oblique",
"C-3": "Courier-Bold",
"C-4": "Courier-BoldOblique",
}

@ -0,0 +1,12 @@
# function with three arguments
def dynamic_glyph(previous_module, current_module, module):
text = module[1]
print("starting to write the text-file")
#file to write the result to
textFile = open("dynamic_glyph.txt", "wt") # wt = write text mode
# write the new text to the file
textFile.write(text)
#close input and output files
textFile.close()

Binary file not shown.

@ -0,0 +1,5 @@
%!PS
% empty file
showpage
% print all on a page

@ -0,0 +1,101 @@
import re # libary to search and replace strings in the postscript file
from dictionary import font_index
from random import choice
from generate_postscript import generate_postscript
# function with three arguments
def friction_label(previous_module, current_module, module):
font = font_index[module[1]] # use font_index from dictionary to translate the fontname
fontsize = module[2] # sensor3
rotation = module[3] # sensor2
linewidth = module[4]
x = module[5] # sensor4
y = module[6] # sensor 4, same the exact same value
graytone1 = module[7] # sensor5
graytone2 = module[8] # sensor5, opposite range
#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
text = textContent
text = text.replace("\n", "")
elif textContent == "": #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!"]
text = choice(defaultText)
# split the text into words to place them in separate lines
text = text.split(" ")
paragraph = ""
for word in text:
paragraph = paragraph + "(" + word + ") true charpath newline-friction-label "
script = """
newpath
% FRICTION LABEL
/"""+font+"""
% fontname
"""+fontsize+""" selectfont
% fontsize in points, establishes the font as the current one
/x-friction-label { """+x+""" } def
% define x position
/y-friction-label { """+y+""" } def
% define y position
/lg-friction-label { """+fontsize+""" 4 div """+fontsize+""" add } def
% define linespacing:
% fontsize divided by 4 plus fontsize
/newline-friction-label { y-friction-label lg-friction-label sub /y-friction-label exch def x-friction-label y-friction-label 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-friction-label y-friction-label moveto
% x and y coordinates in px (origin is the lower-left corner of the page)
"""+rotation+""" rotate
% degree of rotation, counter clockwise around the given position
"""+paragraph+"""
gsave
% save the current path to apply stroke first and then go back to the saved path to apply fill (Both drawing commands destroy the current path)
"""+linewidth+""" setlinewidth
% linewidth for the outline of the text
"""+graytone2+""" setgray
% graytone for the outline (0 = black, 1 = white)
stroke
% stroke (outline) the text in parentheses
grestore
% restore the original path to apply fill
"""+graytone1+""" setgray
% graytone for the filling (0 = black, 1 = white)
fill
% fill the text in parentheses
-"""+rotation+""" rotate
% set rotation back to zero
showpage
% print all on a page
"""
generate_postscript(previous_module, current_module, script) # call function
Loading…
Cancel
Save