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
|
2016-04-28 20:26:21 +02:00
|
|
|
from vloed import PixelVloedClient, NewMessage, RGBPixel, MAX_PIXELS
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-04-28 15:34:57 +02:00
|
|
|
def RandomFill(message, 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))
|
|
|
|
|
try:
|
|
|
|
|
message.append(pixel)
|
|
|
|
|
except IndexError:
|
|
|
|
|
yield ''.join(message)
|
2016-04-28 20:24:37 +02:00
|
|
|
message[2:] = [pixel]
|
2016-04-05 21:54:22 +02:00
|
|
|
yield ''.join(message)
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2016-04-28 15:34:57 +02:00
|
|
|
def RunClient():
|
|
|
|
|
"""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
|
|
|
|
|
False, # show debugging output
|
|
|
|
|
None, # ip of the server, None for autodetect
|
|
|
|
|
None, # port of the server None for autodetect
|
2016-04-28 16:46:03 +02:00
|
|
|
None, # Screen pixels wide, None for autodetect
|
|
|
|
|
None # Screen pixels height, None for autodetect
|
2016-04-28 15:34:57 +02:00
|
|
|
)
|
|
|
|
|
message = NewMessage() #create a new message that buffers the output etc
|
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:
|
2016-04-28 16:46:03 +02:00
|
|
|
# create a new message and send it every time the buffer is full
|
2016-04-28 15:34:57 +02:00
|
|
|
# the width/height are read from the client's config
|
|
|
|
|
for packet in RandomFill(message, client.width, client.height):
|
2016-04-28 16:46:03 +02:00
|
|
|
# send the message we just filled with random pixels
|
2016-04-28 15:34:57 +02:00
|
|
|
client.SendPacket(packet)
|
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-06-22 12:44:44 +02:00
|
|
|
try:
|
|
|
|
|
RunClient()
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
print 'Closing client'
|