Compare commits

...

16 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
e784983f99 Stuff 2022-07-22 00:09:36 +12:00
b60b02e223 Ignore pycache 2022-07-22 00:09:20 +12:00
1bcb39820c Dynamically generate 2022-07-21 19:48:30 +12:00
573f300fea Add font 2022-07-21 19:16:36 +12:00
0f9dc7a886 Select image based on number of lines 2022-07-21 19:16:18 +12:00
a48c3ab596 Tweak 2022-07-21 18:58:27 +12:00
df590dbf19 Add printer test 2022-07-21 18:16:33 +12:00
14 changed files with 301 additions and 102 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
audio
videos
images
images
__pycache__

BIN
controller/press.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

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,27 +17,68 @@ 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.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()
client.loop_forever()

57
printer/test.py Normal file
View File

@@ -0,0 +1,57 @@
import StarTSPImage
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)
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)

View File

@@ -1,23 +1,22 @@
from PIL import Image, ImageDraw
import cv2
import numpy
import numpy as np
from time import sleep
def blank(x, y):
image = Image.new('RGB', (1920, 1080), color='black')
draw = ImageDraw.Draw(image)
draw.ellipse((0, 0, 500, 500), fill='Black')
draw.ellipse((10, 10, 490, 490), fill='White')
class Image:
def __init__(self, x, y):
self.x = x
self.y = y
def show(self, path):
image = cv2.imread(path)
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", self.x, self.y)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", image)
opencvImage = cv2.cvtColor(numpy.array(image), cv2.COLOR_RGB2BGR)
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", 0, 0)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", opencvImage)
if __name__ == "__main__":
blank(0, 0)
cv2.waitKey(1000)
def blank(self):
blank_image = np.zeros(shape=[512, 512, 3], dtype=np.uint8)
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", self.x, self.y)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", blank_image)

View File

@@ -6,81 +6,65 @@ from random import randint
from time import sleep
import paho.mqtt.client as mqtt
from video import Video
import multiprocessing
import sys
from random import randint
from PIL import Image, ImageDraw
import cv2
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))]
self.images = [join("slave/images", f) for f in listdir("slave/images") if isfile(join("slave/images", f))]
self.lastvideo = -1
self.lastimage = -1
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
secondlast = -1
while True:
try:
self.x.terminate()
except:
pass
i = randint(0, len(self.videos)-1)
if i == last or i == secondlast:
continue
secondlast = last
last = i
video = self.videos[i]
print(video)
self.video.start(video)
self.blank()
sleep(1)
def blank(self):
image = Image.new('RGB', (2000, 2000), color='black')
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", self.x, self.y)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", image)
while True:
# if i == last:
# continue
if randint(0,5) == 0:
self.showimage()
else:
self.playvideo()
def showimage(self):
totalimages = len(self.images)-1
i = randint(0, totalimages)
if i == self.lastimage:
i += 1
if i > totalimages:
i = 0
self.lastimage = i
self.image.show(self.images[i])
cv2.waitKey(10000)
def playvideo(self):
totalvideos = len(self.videos)-1
i = randint(0, totalvideos)
if i == self.lastvideo:
i += 1
if i > totalvideos:
i = 0
self.lastvideo = i
video = self.videos[i]
print(video)
self.video.start(video)
self.image.blank()
cv2.waitKey(1)
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,9 +28,10 @@ class Video:
delay = 1/fps * 1000
print(fps, delay)
i = 0
playframes = randint(300, 500)
while(self.cap.isOpened() ):
i += 1
if i > 100:
if i > playframes:
break
# Capture frame-by-frame
@@ -44,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()
# 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")