Clean up some stuff, add effect cli option, add cli help, make things more beginnner friendly
This commit is contained in:
parent
a001e41a8b
commit
dd72459b24
1 changed files with 35 additions and 16 deletions
51
client.py
51
client.py
|
|
@ -1,11 +1,21 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
"""This is an udp / binary client
|
"""This is the client for Pixelvloed
|
||||||
|
|
||||||
Inspired by the PixelFlut projector on eth0:winter 2016 and
|
https://github.com/janklopper/pixelvloed
|
||||||
code from https://github.com/defnull/pixelflut/
|
|
||||||
|
We've given you an example of a function that randomly places randomly colored
|
||||||
|
pixels somewhere on the screen.
|
||||||
|
|
||||||
|
# Copy the function RandomFill,
|
||||||
|
# give it a new name by replacing the word "RandomFill" By your own name
|
||||||
|
# Think of your own creative pixel packages.
|
||||||
|
|
||||||
|
Then you can run the client with the -e flag (for effect)
|
||||||
|
|
||||||
|
./client.py -e MyColorPusher
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = 0.3
|
__version__ = 0.4
|
||||||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
@ -13,9 +23,7 @@ from vloed import PixelVloedClient, Packet, RGBPixel, MAX_PIXELS
|
||||||
|
|
||||||
def RandomFill(screen, width, height):
|
def RandomFill(screen, width, height):
|
||||||
"""Generates a random number of pixels with a random color"""
|
"""Generates a random number of pixels with a random color"""
|
||||||
for _x in xrange(1, # at least one pixel
|
for _x in xrange(1, MAX_PIXELS): # lets loop over the amount of pixels
|
||||||
random.randint(10, MAX_PIXELS) # at most the max number of pixels
|
|
||||||
):
|
|
||||||
pixel = RGBPixel(random.randint(0, width), # select a random position on the width of the screen
|
pixel = RGBPixel(random.randint(0, width), # select a random position on the width of the screen
|
||||||
random.randint(0, height), # select a random position on the height of the screen
|
random.randint(0, height), # select a random position on the height of the screen
|
||||||
random.randint(0, 255), # select a random value for red
|
random.randint(0, 255), # select a random value for red
|
||||||
|
|
@ -26,7 +34,6 @@ def RandomFill(screen, width, height):
|
||||||
|
|
||||||
def RunClient(options):
|
def RunClient(options):
|
||||||
"""Discover the servers and start sending to the first one"""
|
"""Discover the servers and start sending to the first one"""
|
||||||
|
|
||||||
client = PixelVloedClient(True, # start as soon as we find a server
|
client = PixelVloedClient(True, # start as soon as we find a server
|
||||||
options.debug, # show debugging output
|
options.debug, # show debugging output
|
||||||
options.ip, # ip of the server, None for autodetect
|
options.ip, # ip of the server, None for autodetect
|
||||||
|
|
@ -38,28 +45,40 @@ def RunClient(options):
|
||||||
# Lets create a screen which buffers the pixels we add to it, and sends them to the actual screen.
|
# Lets create a screen which buffers the pixels we add to it, and sends them to the actual screen.
|
||||||
screen = Packet(client)
|
screen = Packet(client)
|
||||||
# loop the effect until we cancel by pressing ctrl+c / exit the program
|
# loop the effect until we cancel by pressing ctrl+c / exit the program
|
||||||
|
|
||||||
|
# we run the effect that has been given trough the -e flag.
|
||||||
|
# This defaults to RandomFill
|
||||||
|
if options.effect:
|
||||||
|
effect = locals()[options.effect]
|
||||||
|
else:
|
||||||
|
effect = RandomFill
|
||||||
|
|
||||||
while screen:
|
while screen:
|
||||||
|
|
||||||
# add some pixels to the screen with our functions
|
# add some pixels to the screen with our functions
|
||||||
# the width/height are read from the client's config
|
# the width/height are read from the client's config
|
||||||
RandomFill(screen, client.width, client.height)
|
effect(screen, client.width, client.height)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# if this script is called from the command line, 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
|
||||||
import optparse
|
import optparse
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
parser.add_option('-v', action="store_true", dest="debug", default=False,
|
||||||
parser.add_option('-i', action="store", dest="ip", default=None)
|
help="Enable debugging output")
|
||||||
parser.add_option('-p', action="store", dest="port", default=None,
|
parser.add_option('-i', action="store", dest="ip", default=None,
|
||||||
type="int")
|
help="Ip of the server, leave empty for auto-discovery")
|
||||||
|
parser.add_option('-p', action="store", dest="port", default=None, type="int",
|
||||||
|
help="Port of the server, leave empty for default")
|
||||||
parser.add_option('-x', action="store", dest="width", default=None,
|
parser.add_option('-x', action="store", dest="width", default=None,
|
||||||
type="int")
|
type="int", help="Width of the server's screen")
|
||||||
parser.add_option('-y', action="store", dest="height", default=None,
|
parser.add_option('-y', action="store", dest="height", default=None,
|
||||||
type="int")
|
type="int", help="Height of the server's screen")
|
||||||
|
parser.add_option('-e', action="store", dest="effect", default=None,
|
||||||
|
type="str", help="Which effect to run.")
|
||||||
options, remainder = parser.parse_args()
|
options, remainder = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
RunClient(options)
|
RunClient(options)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print 'Closing client'
|
print('Closing client')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue