2016-03-02 12:21:03 +01:00
|
|
|
#!/usr/bin/python
|
2016-03-31 14:18:39 +02:00
|
|
|
"""This is an udp / binary client
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-04-28 16:46:03 +02:00
|
|
|
Inspired by the PixelFlut projector on eth0:winter 2016 and
|
2016-03-02 12:21:03 +01:00
|
|
|
code from https://github.com/defnull/pixelflut/
|
|
|
|
|
"""
|
|
|
|
|
|
2016-04-28 15:34:57 +02:00
|
|
|
__version__ = 0.3
|
2016-03-02 12:21:03 +01:00
|
|
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
|
|
|
|
|
|
|
|
|
import random
|
2017-05-21 17:44:30 +02:00
|
|
|
from vloed import PixelVloedClient, InitMessage, RGBPixel, MAX_PIXELS
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2017-05-21 17:44:30 +02:00
|
|
|
def RandomFill(pixels, width, height):
|
2016-03-02 12:21:03 +01:00
|
|
|
"""Generates a random number of pixels with a random color"""
|
2016-04-28 20:26:21 +02:00
|
|
|
for pixel in xrange(0, random.randint(10, MAX_PIXELS)):
|
2016-04-05 21:54:22 +02:00
|
|
|
pixel = RGBPixel(random.randint(0, width),
|
|
|
|
|
random.randint(0, height),
|
|
|
|
|
random.randint(0, 255),
|
|
|
|
|
random.randint(0, 255),
|
|
|
|
|
random.randint(0, 255))
|
2017-05-21 17:44:30 +02:00
|
|
|
pixels.append(pixel)
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-07-12 18:37:32 +02:00
|
|
|
def RunClient(options):
|
2016-04-28 15:34:57 +02:00
|
|
|
"""Discover the servers and start sending to the first one"""
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-04-28 15:34:57 +02:00
|
|
|
client = PixelVloedClient(True, # start as soon as we find a server
|
2016-07-12 18:37:32 +02:00
|
|
|
options.debug, # show debugging output
|
|
|
|
|
options.ip, # ip of the server, None for autodetect
|
|
|
|
|
options.port, # port of the server None for autodetect
|
|
|
|
|
options.width, # Screen pixels wide, None for autodetect
|
|
|
|
|
options.height # Screen pixels height, None for autodetect
|
2016-04-28 15:34:57 +02:00
|
|
|
)
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-04-28 16:46:03 +02:00
|
|
|
# loop the effect until we cancel by pressing ctrl+c / exit the program
|
2016-03-02 12:21:03 +01:00
|
|
|
while True:
|
2017-05-21 17:44:30 +02:00
|
|
|
pixels = [] # list to store the pixels we want to send
|
|
|
|
|
|
|
|
|
|
# add some pixels to the output with our functions
|
2016-04-28 15:34:57 +02:00
|
|
|
# the width/height are read from the client's config
|
2017-05-21 17:44:30 +02:00
|
|
|
RandomFill(pixels, client.width, client.height)
|
|
|
|
|
|
|
|
|
|
# send our pixels in packets including a message header and less than
|
|
|
|
|
# MAX_PIXELS pixels
|
|
|
|
|
for part in SplitList(MAX_PIXELS, pixels):
|
|
|
|
|
packet = InitMessage([]) + part
|
|
|
|
|
client.SendPacket(''.join(packet))
|
|
|
|
|
|
|
|
|
|
def SplitList(max_size, lis):
|
|
|
|
|
"""Splits a list into equal-sized chunks"""
|
|
|
|
|
for i in xrange(0, len(lis), max_size):
|
|
|
|
|
yield lis[i:i+max_size]
|
2016-03-02 12:21:03 +01:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-04-28 16:46:03 +02:00
|
|
|
# if this script is called from the command line, and thus not imported
|
|
|
|
|
# start a client and start sending messages
|
2016-07-12 18:37:32 +02:00
|
|
|
import optparse
|
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
|
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
|
|
|
|
parser.add_option('-i', action="store", dest="ip", default=None)
|
|
|
|
|
parser.add_option('-p', action="store", dest="port", default=None,
|
|
|
|
|
type="int")
|
|
|
|
|
parser.add_option('-x', action="store", dest="width", default=None,
|
|
|
|
|
type="int")
|
|
|
|
|
parser.add_option('-y', action="store", dest="height", default=None,
|
|
|
|
|
type="int")
|
|
|
|
|
options, remainder = parser.parse_args()
|
|
|
|
|
|
2016-06-22 12:44:44 +02:00
|
|
|
try:
|
2016-07-12 18:37:32 +02:00
|
|
|
RunClient(options)
|
2016-06-22 12:44:44 +02:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
print 'Closing client'
|