Dateien hochladen nach „output_module“
parent
6505d04cc5
commit
3be3070829
@ -0,0 +1,144 @@
|
|||||||
|
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 future_relics(previous_module, current_module, module):
|
||||||
|
|
||||||
|
shape = module[1]
|
||||||
|
rotation = module[2]
|
||||||
|
x = module[3]
|
||||||
|
y = module[4]
|
||||||
|
graytone = module[5]
|
||||||
|
|
||||||
|
|
||||||
|
spike = ['spike1', 'spike2', 'spike3']
|
||||||
|
bubble = ['bubble1', 'bubble2', 'bubble3']
|
||||||
|
square = ['square1', 'square2', 'square3']
|
||||||
|
fraction = ['fraction1', 'fraction2', 'fraction3']
|
||||||
|
|
||||||
|
text = ""
|
||||||
|
font = ""
|
||||||
|
fontsize = ""
|
||||||
|
linewidth = ""
|
||||||
|
|
||||||
|
|
||||||
|
if shape == "spike":
|
||||||
|
form = choice(spike)
|
||||||
|
if form == 'spike1':
|
||||||
|
text = "f/yk"
|
||||||
|
font = "Helvetica-BoldOblique"
|
||||||
|
fontsize = "60"
|
||||||
|
linewidth = "100"
|
||||||
|
elif form == 'spike2':
|
||||||
|
text = "f/yk"
|
||||||
|
font = "Helvetica-BoldOblique"
|
||||||
|
fontsize = "30"
|
||||||
|
linewidth = "100"
|
||||||
|
elif form == 'spike3':
|
||||||
|
text = "xxx"
|
||||||
|
font = "Helvetica-BoldOblique"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "100"
|
||||||
|
|
||||||
|
elif shape == "bubble":
|
||||||
|
form = choice(bubble)
|
||||||
|
if form == 'bubble1':
|
||||||
|
text = "gooo"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "160"
|
||||||
|
linewidth = "80"
|
||||||
|
elif form == 'bubble2':
|
||||||
|
text = "dP"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "160"
|
||||||
|
linewidth = "80"
|
||||||
|
elif form == 'bubble3':
|
||||||
|
text = "oOgOö"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "250"
|
||||||
|
linewidth = "80"
|
||||||
|
|
||||||
|
elif shape == "square":
|
||||||
|
form = choice(square)
|
||||||
|
if form == 'square1':
|
||||||
|
text = "FRICTION"
|
||||||
|
font = "Helvetica-BoldOblique"
|
||||||
|
fontsize = "2"
|
||||||
|
linewidth = "300"
|
||||||
|
elif form == 'square2':
|
||||||
|
text = "LLL"
|
||||||
|
font = "Helvetica-BoldOblique"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "300"
|
||||||
|
elif form == 'square3':
|
||||||
|
text = "|||"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "200"
|
||||||
|
|
||||||
|
elif shape == "fraction":
|
||||||
|
form = choice(fraction)
|
||||||
|
if form == 'fraction1':
|
||||||
|
text = "3ß"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "600"
|
||||||
|
elif form == 'fraction2':
|
||||||
|
text = "%?"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "200"
|
||||||
|
elif form == 'fraction3':
|
||||||
|
text = "WM"
|
||||||
|
font = "Courier"
|
||||||
|
fontsize = "100"
|
||||||
|
linewidth = "200"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
script = """
|
||||||
|
|
||||||
|
newpath
|
||||||
|
% FUTURE RELICS
|
||||||
|
|
||||||
|
/"""+font+"""
|
||||||
|
% fontname
|
||||||
|
|
||||||
|
"""+fontsize+""" selectfont
|
||||||
|
% fontsize in points, establishes the font as the current one
|
||||||
|
|
||||||
|
"""+x+""" """+y+""" 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
|
||||||
|
|
||||||
|
("""+text+""") true charpath
|
||||||
|
% normally text works with "show", but to use the characters in the string as a path that can be stroked and filled use "true charpath"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
"""+graytone+""" setgray
|
||||||
|
% graytone for the outline (0 = black, 1 = white)
|
||||||
|
|
||||||
|
stroke
|
||||||
|
% stroke (outline) 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
|
@ -0,0 +1,42 @@
|
|||||||
|
import re # libary to search and replace strings in the postscript file
|
||||||
|
import os
|
||||||
|
|
||||||
|
def generate_postscript(previous_module, current_module, script):
|
||||||
|
|
||||||
|
|
||||||
|
if previous_module == "" or previous_module == "dynamic_glyph":
|
||||||
|
print("use empty.ps and write to current_module.ps")
|
||||||
|
#input file
|
||||||
|
fileInput = open("empty.ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open(current_module + ".ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
content = re.sub(r"% empty file\n\nshowpage\n% print all on a page", (script), content)
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
||||||
|
# time.sleep(5)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("use previous_module.ps and write to current_module.ps")
|
||||||
|
#input file
|
||||||
|
fileInput = open(previous_module + ".ps", "rt") # a+ = read text mode and write (append) to end of file
|
||||||
|
fileOutput = open(current_module + ".ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
content = re.sub(r"showpage\n% print all on a page", (script), content)
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
||||||
|
# time.sleep(5)
|
@ -0,0 +1,19 @@
|
|||||||
|
# button setup (connect to GND and board Pin 19)
|
||||||
|
import RPi.GPIO as GPIO # GPIO pins
|
||||||
|
#import time
|
||||||
|
|
||||||
|
|
||||||
|
def preview_button():
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Use the physical board number (not GPIO numbering)
|
||||||
|
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Change pin if necessary #preview button
|
||||||
|
GPIO.setwarnings(False) #Ignore warnings
|
||||||
|
|
||||||
|
preview_button_pressed = False
|
||||||
|
|
||||||
|
if GPIO.input(19) == GPIO.LOW:
|
||||||
|
#time.sleep(1)
|
||||||
|
preview_button_pressed = True
|
||||||
|
GPIO.cleanup() #GPIO clean up
|
||||||
|
|
||||||
|
return preview_button_pressed
|
@ -0,0 +1,19 @@
|
|||||||
|
# button setup (connect to GND and board Pin 21)
|
||||||
|
import RPi.GPIO as GPIO # GPIO pins
|
||||||
|
#import time
|
||||||
|
|
||||||
|
|
||||||
|
def print_button():
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BOARD) #Use the physical board number (not GPIO numbering)
|
||||||
|
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Change pin if necessary #print button
|
||||||
|
GPIO.setwarnings(False) #Ignore warnings
|
||||||
|
|
||||||
|
print_button_pressed = False
|
||||||
|
|
||||||
|
if GPIO.input(21) == GPIO.LOW:
|
||||||
|
#time.sleep(1)
|
||||||
|
print_button_pressed = True
|
||||||
|
GPIO.cleanup() #GPIO clean up
|
||||||
|
|
||||||
|
return print_button_pressed
|
@ -0,0 +1,56 @@
|
|||||||
|
import time
|
||||||
|
import os # library to use bash commands
|
||||||
|
import keyboard
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def preview_output(preview_button_count, last_module):
|
||||||
|
|
||||||
|
#open last_module.ps, read its content and save it as print.ps
|
||||||
|
fileInput = open(last_module + ".ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("print.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
||||||
|
|
||||||
|
#on first button press: open preview
|
||||||
|
if preview_button_count == 1:
|
||||||
|
print("start preview of print.ps")
|
||||||
|
os.system("gv -fullscreen print.ps &") # open file in ghostscript viewer in fullscreen mode
|
||||||
|
|
||||||
|
#on additional button press: refresh preview
|
||||||
|
elif preview_button_count >= 2:
|
||||||
|
print("refresh preview of print.ps")
|
||||||
|
keyboard.send(".") # refresh file that is open in ghostscript viewer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def print_output(last_module):
|
||||||
|
|
||||||
|
#open last_module.ps, read its content and save it as print.ps
|
||||||
|
fileInput = open(last_module + ".ps", "rt") # rt = read text mode
|
||||||
|
#output file to write the result to
|
||||||
|
fileOutput = open("print.ps", "wt") # wt = write text mode
|
||||||
|
|
||||||
|
# read the input file, search for a patterns, replace it with new patterns (that take the values from the input sensor)
|
||||||
|
# uses regular expressions library (re)
|
||||||
|
content = fileInput.read()
|
||||||
|
|
||||||
|
# write the new text to the output file
|
||||||
|
fileOutput.write(content)
|
||||||
|
#close input and output files
|
||||||
|
fileInput.close()
|
||||||
|
fileOutput.close()
|
||||||
|
|
||||||
|
#on button press: send to printer
|
||||||
|
print("send print.ps to printer")
|
||||||
|
os.system("lp print.ps") # lp is the bash print command
|
Loading…
Reference in New Issue