diff --git a/output_module/dictionary.py b/output_module/dictionary.py new file mode 100644 index 0000000..8e48cae --- /dev/null +++ b/output_module/dictionary.py @@ -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", + +} diff --git a/output_module/dynamic_glyph.py b/output_module/dynamic_glyph.py new file mode 100644 index 0000000..ddd114e --- /dev/null +++ b/output_module/dynamic_glyph.py @@ -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() diff --git a/output_module/dynamic_glyph.txt b/output_module/dynamic_glyph.txt new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/output_module/dynamic_glyph.txt differ diff --git a/output_module/empty.ps b/output_module/empty.ps new file mode 100644 index 0000000..7ee5fb0 --- /dev/null +++ b/output_module/empty.ps @@ -0,0 +1,5 @@ +%!PS +% empty file + +showpage +% print all on a page diff --git a/output_module/friction_label.py b/output_module/friction_label.py new file mode 100644 index 0000000..2aeb624 --- /dev/null +++ b/output_module/friction_label.py @@ -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