Merge pull request #7 from CodePanter/master
Changed a few small things to improve ease of use.
This commit is contained in:
commit
5d4c250f89
2 changed files with 27 additions and 23 deletions
22
client.py
22
client.py
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
"""This is an udp / binary client
|
"""This is an udp / binary client
|
||||||
|
|
||||||
Inspired by the PixelFlut beamer on eth0:winter 2016 and
|
Inspired by the PixelFlut projector on eth0:winter 2016 and
|
||||||
code from https://github.com/defnull/pixelflut/
|
code from https://github.com/defnull/pixelflut/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -9,11 +9,11 @@ __version__ = 0.3
|
||||||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from vloed import PixelVloedClient, NewMessage, RGBPixel
|
from vloed import PixelVloedClient, NewMessage, RGBPixel, MAX_PIXELS
|
||||||
|
|
||||||
def RandomFill(message, width, height):
|
def RandomFill(message, width, height):
|
||||||
"""Generates a random number of pixels with a random color"""
|
"""Generates a random number of pixels with a random color"""
|
||||||
for pixel in xrange(0, random.randint(10, 140)):
|
for pixel in xrange(0, random.randint(10, MAX_PIXELS)):
|
||||||
pixel = RGBPixel(random.randint(0, width),
|
pixel = RGBPixel(random.randint(0, width),
|
||||||
random.randint(0, height),
|
random.randint(0, height),
|
||||||
random.randint(0, 255),
|
random.randint(0, 255),
|
||||||
|
|
@ -23,7 +23,7 @@ def RandomFill(message, width, height):
|
||||||
message.append(pixel)
|
message.append(pixel)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
yield ''.join(message)
|
yield ''.join(message)
|
||||||
message[2:] = []
|
message[2:] = [pixel]
|
||||||
yield ''.join(message)
|
yield ''.join(message)
|
||||||
|
|
||||||
def RunClient():
|
def RunClient():
|
||||||
|
|
@ -33,20 +33,20 @@ def RunClient():
|
||||||
False, # show debugging output
|
False, # show debugging output
|
||||||
None, # ip of the server, None for autodetect
|
None, # ip of the server, None for autodetect
|
||||||
None, # port of the server None for autodetect
|
None, # port of the server None for autodetect
|
||||||
None, # Screen pixels wide, or Autodetect
|
None, # Screen pixels wide, None for autodetect
|
||||||
None # Screen pixels height, or Autodetect
|
None # Screen pixels height, None for autodetect
|
||||||
)
|
)
|
||||||
message = NewMessage() #create a new message that buffers the output etc
|
message = NewMessage() #create a new message that buffers the output etc
|
||||||
|
|
||||||
# loop the effect untill we cancel by pressing ctrl+c / exit the program
|
# loop the effect until we cancel by pressing ctrl+c / exit the program
|
||||||
while True:
|
while True:
|
||||||
# create a new message and send if everytime the buffer is full
|
# create a new message and send it every time the buffer is full
|
||||||
# the width/height are read from the client's config
|
# the width/height are read from the client's config
|
||||||
for packet in RandomFill(message, client.width, client.height):
|
for packet in RandomFill(message, client.width, client.height):
|
||||||
# send the message we just filled with random pixelfs
|
# send the message we just filled with random pixels
|
||||||
client.SendPacket(packet)
|
client.SendPacket(packet)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# if this script is called from the commandline, and thus not imported
|
# if this script is called from the command line, and thus not imported
|
||||||
# Start a client and start sending messages
|
# start a client and start sending messages
|
||||||
RunClient()
|
RunClient()
|
||||||
|
|
|
||||||
28
vloed.py
28
vloed.py
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
"""This is a udp / binary version of PixelFlut
|
"""This is a udp / binary version of PixelFlut
|
||||||
|
|
||||||
Inspired by the PixelFlut beamer on eth0:winter 2016 and
|
Inspired by the PixelFlut projector on eth0:winter 2016 and
|
||||||
code from https://github.com/defnull/pixelflut/
|
code from https://github.com/defnull/pixelflut/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ class Canvas(object):
|
||||||
def Draw(self):
|
def Draw(self):
|
||||||
"""Draws pixels specified in the received packages in the queue"""
|
"""Draws pixels specified in the received packages in the queue"""
|
||||||
if self.queue.empty():
|
if self.queue.empty():
|
||||||
# indicat that nothing was done, and w can skip flipping the screen
|
# indicate that nothing was done, and we can skip flipping the screen
|
||||||
return False
|
return False
|
||||||
#access the pixel array and lock it
|
#access the pixel array and lock it
|
||||||
self.pixels = pygame.surfarray.pixels2d(self.screen)
|
self.pixels = pygame.surfarray.pixels2d(self.screen)
|
||||||
|
|
@ -145,13 +145,17 @@ class Canvas(object):
|
||||||
|
|
||||||
def SendDiscoveryPacket(self):
|
def SendDiscoveryPacket(self):
|
||||||
"""Lets send out our ip/port/resolution to any listening clients"""
|
"""Lets send out our ip/port/resolution to any listening clients"""
|
||||||
self.broadcastsocket.sendto(
|
try:
|
||||||
'%s:%f %s:%d %d*%d' % (PROTOCOL_PREAMBLE, PROTOCOL_VERSION,
|
self.broadcastsocket.sendto(
|
||||||
UDP_IP, UDP_PORT,
|
'%s:%f %s:%d %d*%d' % (PROTOCOL_PREAMBLE, PROTOCOL_VERSION,
|
||||||
self.width, self.height),
|
UDP_IP, UDP_PORT,
|
||||||
('<broadcast>', DISCOVER_PORT))
|
self.width, self.height),
|
||||||
if self.debug:
|
('<broadcast>', DISCOVER_PORT))
|
||||||
print 'sending discovery packet'
|
if self.debug:
|
||||||
|
print 'sending discovery packet'
|
||||||
|
except Exception as error:
|
||||||
|
if self.debug:
|
||||||
|
print error
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""Clean up any sockets we created"""
|
"""Clean up any sockets we created"""
|
||||||
|
|
@ -204,7 +208,7 @@ class PixelVloedClient(object):
|
||||||
servers[0])
|
servers[0])
|
||||||
else:
|
else:
|
||||||
self.ipaddress = ip
|
self.ipaddress = ip
|
||||||
self.port = port
|
self.port = port if port else UDP_IP
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
|
@ -230,7 +234,7 @@ class PixelVloedClient(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def DiscoverServers(returnfirst=False, timeout=5):
|
def DiscoverServers(returnfirst=False, timeout=5):
|
||||||
"""Discover servers that send out the pixelfvloed preample"""
|
"""Discover servers that send out the pixelvloed preample"""
|
||||||
discoverysock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
discoverysock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
discoverysock.bind(('', DISCOVER_PORT))
|
discoverysock.bind(('', DISCOVER_PORT))
|
||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
|
|
@ -296,9 +300,9 @@ class MaxSizeList(list):
|
||||||
|
|
||||||
def append(self, item):
|
def append(self, item):
|
||||||
"""Appends an item to the list"""
|
"""Appends an item to the list"""
|
||||||
super(MaxSizeList, self).append(item)
|
|
||||||
if self.__len__() == self.maxsize:
|
if self.__len__() == self.maxsize:
|
||||||
raise IndexError('max size reached')
|
raise IndexError('max size reached')
|
||||||
|
super(MaxSizeList, self).append(item)
|
||||||
|
|
||||||
def RunServer():
|
def RunServer():
|
||||||
"""Runs a pixelvloed server"""
|
"""Runs a pixelvloed server"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue