Compare commits

...

9 Commits

Author SHA1 Message Date
b9f0c632d1 Add idle message 2022-09-28 15:05:03 +13:00
74d7354593 Add printer stuff 2022-09-24 12:53:32 +12:00
c996650414 What happens when you don't have a pen 2022-09-21 00:51:44 +12:00
653257b787 Production version 2022-09-21 00:50:57 +12:00
15e79e67df Remove mqtt 2022-07-23 05:27:29 +12:00
a58f11ac0e Remove multiprocessing 2022-07-23 04:08:20 +12:00
56d4b8c371 Fix identation 2022-07-23 02:07:20 +12:00
3d14ba3dd6 Add printer to mqtt 2022-07-23 01:58:57 +12:00
1dd5117e1f Add printing to mqtt 2022-07-23 01:40:33 +12:00
11 changed files with 200 additions and 73 deletions

BIN
controller/press.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

55
printer/actions.txt Normal file
View File

@@ -0,0 +1,55 @@
ask a stranger for a dance
ask a stranger what their biggest fear is
smell a strangers hair
show off your impression of a duck
spank a consenting individual
kiss a consenting individual
reveal a secret
tell a creative story
compliment someone on their smile
hold Tanos hands
request a 20 second eye gaze
serve a drink for someone from another faction
ask a stranger for a dance
ask a stranger what their biggest fear is
smell a strangers hair
spank a consenting individual
kiss a consenting individualas
reveal a secret
do a handstand across the dance floor
tell a creative story
compliment someone on their smile
request a 20 second eye gaze
change character
find an animal to stroke
make an instrument out of something odd
tell a stranger that you love them
tell a stranger that you love yourself
start a game of leapfrog
hold someones hand
bow to someone respectable
embrace yo-ur spirit animal
give someone a foot massage
learn to code
warn someone of a grave danger
ask a question with no answer
be a fairy
find the snail
press any key to continue
swap an object with a stranger
go for an adventure
find sally the snail
find something furry and appreciate it
introduce two strangers to each other
nominate a stranger to be your friends
wingman someone that could use your help
give someone a shoulder rub
make it a party
serve someone a drink from another faction
run on the spot for 1 minute
find the pharoah
hug a consenting stranger
hug 3 consenting people in a row
strut around
consetually give someone a hug
tell someone they are the most beautiful person you have ever seen

29
printer/adverbs.txt Normal file
View File

@@ -0,0 +1,29 @@
graciously
heroically
confidently
ferociously
happily
emotionally
spritely
majestically
boldly
brightly
cheerfully
eagerly
elegantly
gleefully
innocently
politely
powerfully
victoriously
boastfully
occasionally
casually
mysteriously
seriously
dramatically
flamboyantly
sexually
flirtatiously
awkwardly
saintly

BIN
printer/image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

BIN
printer/image2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

7
printer/locations.txt Normal file
View File

@@ -0,0 +1,7 @@
on the steps
outdoors
in the boiler room
by the DJ
in a dark area
in the auditorium
by a window

28
printer/press.py Normal file
View File

@@ -0,0 +1,28 @@
import StarTSPImage
from PIL import Image, ImageDraw, ImageFont, ImageOps
import textwrap
import random
im = Image.new('RGB', (500, 1600), color = 'white')
# f = ImageFont.load_default()
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 100)
txt=Image.new('L', (1600,500))
d = ImageDraw.Draw(txt)
d.text((50, 50), "(When flashing)", font=f, fill=255)
w=txt.rotate(-90, expand=1)
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), (-100, 60), w)
im.show()
# im.save("image_tmp.jpg")
raster = StarTSPImage.imageToRaster(im, cut=True)
printer = open('/dev/usb/lp0', "wb")
printer.write(raster)

View File

@@ -1,5 +1,7 @@
import StarTSPImage
from PIL import Image, ImageDraw
from PIL import Image, ImageDraw, ImageFont, ImageOps
import textwrap
import random
@@ -15,24 +17,65 @@ def on_connect(client, userdata, flags, rc):
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
image = Image.new('RGB', (2000, 2000), color='White')
draw = ImageDraw.Draw(image)
draw.ellipse((0, 0, 500, 500), fill='Black')
draw.ellipse((10, 10, 490, 490), fill='White')
image.show()
image.save("image.jpg")
print("Print")
with open("printer/locations.txt") as locations:
lines = locations.read().splitlines()
location = random.choice(lines)
# raster = StarTSPImage.imageToRaster(image, cut=True)
with open("printer/actions.txt") as actions:
lines = actions.read().splitlines()
action = random.choice(lines)
with open("printer/adverbs.txt") as adverb:
lines = adverb.read().splitlines()
adverb = random.choice(lines)
if random.randint(0,1):
im=Image.open("printer/image.jpg")
else:
im=Image.open("printer/image2.jpg")
# f = ImageFont.load_default()
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 40)
txt=Image.new('L', (1000,230))
d = ImageDraw.Draw(txt)
text = "While {}, {}, {}".format(location, action, adverb)
text_short = "By the DJ, offer a stranger a drink"
text_long = "In the outdoor area, ask someone would you rather be known for always being honest or always being kind"
lines = textwrap.wrap(text, width=23)
if random.randint(0,1) == 0:
im=Image.open("printer/image.jpg")
else:
im=Image.open("printer/image2.jpg")
y = 0
n = 0
for line in lines:
n += 1
width, height = f.getsize(line)
d.text(((1000-width)/2, y), line, font=f, fill=255)
y += height
w=txt.rotate(-90, expand=1)
print(n)
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
# im.show()
# im.save("image_tmp.jpg")
raster = StarTSPImage.imageToRaster(im, cut=True)
printer = open('/dev/usb/lp0', "wb")
printer.write(raster)
# printer = open('/dev/usb/lp0', "wb")
# printer.write(raster)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("10.1.1.162", 1883, 60)
client.connect("192.168.240.231", 1883, 60)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.

View File

@@ -3,6 +3,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageOps
import textwrap
import random
print("Print")
with open("printer/locations.txt") as locations:
lines = locations.read().splitlines()
location = random.choice(lines)
@@ -15,6 +16,9 @@ with open("printer/adverbs.txt") as adverb:
lines = adverb.read().splitlines()
adverb = random.choice(lines)
if random.randint(0,1):
im=Image.open("printer/image.jpg")
else:
im=Image.open("printer/image2.jpg")
# f = ImageFont.load_default()
@@ -28,7 +32,7 @@ text_long = "In the outdoor area, ask someone would you rather be known for alwa
lines = textwrap.wrap(text, width=23)
if len(lines) > 2:
if random.randint(0,1) == 0:
im=Image.open("printer/image.jpg")
else:
im=Image.open("printer/image2.jpg")
@@ -44,10 +48,10 @@ w=txt.rotate(-90, expand=1)
print(n)
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
im.show()
im.save("image_tmp.jpg")
# im.show()
# im.save("image_tmp.jpg")
raster = StarTSPImage.imageToRaster(im, cut=True)
printer = open('/dev/usb/lp0', "wb")
#printer.write(raster)
printer.write(raster)

View File

@@ -13,12 +13,9 @@ from image import Image
import multiprocessing
class App:
def __init__(self, client, x, y):
def __init__(self, x, y):
self.x = x
self.y = y
self.client = client
self.video = Video(x, y)
self.image = Image(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
@@ -28,34 +25,10 @@ class App:
print(self.videos)
print(self.videos[randint(0, len(self.videos)-1)])
def on_connect(self, client, userdata, flags, rc):
print("Connected with result code "+str(rc))
self.client.subscribe("slave")
def on_message(self, client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
if msg.payload == b'idle':
print("Idle")
self.x = multiprocessing.Process(target = self.idle)
self.x.start()
elif msg.payload == b'stop':
print("Stop")
try:
self.x.terminate()
except:
pass
def idle(self):
last = -1
while True:
try:
self.x.terminate()
except:
pass
# if i == last:
# continue
if randint(0,5) == 0:
@@ -72,7 +45,7 @@ class App:
i = 0
self.lastimage = i
self.image.show(self.images[i])
cv2.waitKey(1000)
cv2.waitKey(10000)
def playvideo(self):
totalvideos = len(self.videos)-1
@@ -90,15 +63,8 @@ class App:
def main():
client = mqtt.Client()
app = App(client, int(sys.argv[1]), int(sys.argv[2]))
client.on_connect = app.on_connect
client.on_message = app.on_message
client.connect("10.1.1.162", 1883, 60)
client.loop_forever()
app = App(int(sys.argv[1]), int(sys.argv[2]))
app.idle()
if __name__ == "__main__":
main()

View File

@@ -2,6 +2,7 @@ from random import randint
import cv2
import multiprocessing
import time
import sys
class Video:
def __init__(self, x, y):
@@ -27,7 +28,7 @@ class Video:
delay = 1/fps * 1000
print(fps, delay)
i = 0
playframes = randint(50, 200)
playframes = randint(300, 500)
while(self.cap.isOpened() ):
i += 1
if i > playframes:
@@ -45,26 +46,20 @@ class Video:
cv2.imshow("window", frame)
cv2.waitKey(int(delay))
if cv2.waitKey(int(delay)) & 0xFF == ord('q'):
self.cap.release()
cv2.destroyAllWindows()
sys.exit(0)
# Break the loop
else:
break
#self.cap.release()
self.cap.release()
# Closes all the frames
#cv2.destroyAllWindows()
if __name__ == "__main__":
video = Video(0, 0)
x = multiprocessing.Process(target = video.start, args=("slave/videos/sample-mp4-file.mp4",))
x.start()
time.sleep(2)
x.terminate()
time.sleep(1)
video = Video(4000, 0)
x = multiprocessing.Process(target = video.start, args=("slave/videos/sample-mp4-file.mp4",))
x.start()
time.sleep(1)
x.terminate()
video.start("slave/videos/sample-mp4-file.mp4")