2016-03-02 12:21:03 +01:00
|
|
|
#!/usr/bin/python
|
2017-07-20 11:14:17 +02:00
|
|
|
"""This is the client for Pixelvloed
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2017-07-20 11:14:17 +02:00
|
|
|
https://github.com/janklopper/pixelvloed
|
|
|
|
|
|
|
|
|
|
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
|
2016-03-02 12:21:03 +01:00
|
|
|
"""
|
|
|
|
|
|
2017-07-20 11:14:17 +02:00
|
|
|
__version__ = 0.4
|
2016-03-02 12:21:03 +01:00
|
|
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
|
|
|
|
|
|
|
|
|
import random
|
2017-06-15 20:20:20 +02:00
|
|
|
from vloed import PixelVloedClient, Packet, RGBPixel, MAX_PIXELS
|
2016-03-02 12:21:03 +01:00
|
|
|
|
2017-06-16 15:14:11 +02:00
|
|
|
def RandomFill(screen, width, height):
|
2016-03-02 12:21:03 +01:00
|
|
|
"""Generates a random number of pixels with a random color"""
|
2017-07-20 11:14:17 +02:00
|
|
|
for _x in xrange(1, MAX_PIXELS): # lets loop over the amount of pixels
|
2017-06-16 15:14:11 +02:00
|
|
|
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, 255), # select a random value for red
|
|
|
|
|
random.randint(0, 255), # select a random value for green
|
|
|
|
|
random.randint(0, 255) # select a random value for blue
|
|
|
|
|
)
|
|
|
|
|
screen.show(pixel) # lets push the pixel to the screen!
|
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"""
|
|
|
|
|
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
|
|
|
|
2017-06-16 15:14:11 +02:00
|
|
|
# Lets create a screen which buffers the pixels we add to it, and sends them to the actual screen.
|
|
|
|
|
screen = Packet(client)
|
2016-04-28 16:46:03 +02:00
|
|
|
# loop the effect until we cancel by pressing ctrl+c / exit the program
|
2017-07-20 11:14:17 +02:00
|
|
|
|
2017-06-16 15:14:11 +02:00
|
|
|
while screen:
|
2017-06-15 20:20:20 +02:00
|
|
|
|
2017-06-16 15:14:11 +02:00
|
|
|
# add some pixels to the screen with our functions
|
2016-04-28 15:34:57 +02:00
|
|
|
# the width/height are read from the client's config
|
2018-04-03 16:15:26 +02:00
|
|
|
options.effect(screen, client.width, client.height)
|
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()
|
2018-04-03 16:15:26 +02:00
|
|
|
parser.add_option('-v', action="store_true", dest="debug", default=False,
|
2017-07-20 11:14:17 +02:00
|
|
|
help="Enable debugging output")
|
|
|
|
|
parser.add_option('-i', action="store", dest="ip", default=None,
|
|
|
|
|
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")
|
2016-07-12 18:37:32 +02:00
|
|
|
parser.add_option('-x', action="store", dest="width", default=None,
|
2017-07-20 11:14:17 +02:00
|
|
|
type="int", help="Width of the server's screen")
|
2016-07-12 18:37:32 +02:00
|
|
|
parser.add_option('-y', action="store", dest="height", default=None,
|
2017-07-20 11:14:17 +02:00
|
|
|
type="int", help="Height of the server's screen")
|
2018-04-03 16:15:26 +02:00
|
|
|
parser.add_option('-e', action="store", dest="effect", default='RandomFill',
|
2017-07-20 11:14:17 +02:00
|
|
|
type="str", help="Which effect to run.")
|
2016-07-12 18:37:32 +02:00
|
|
|
options, remainder = parser.parse_args()
|
|
|
|
|
|
2018-04-03 16:15:26 +02:00
|
|
|
# we run the effect that has been given trough the -e flag.
|
|
|
|
|
# This defaults to RandomFill
|
|
|
|
|
options.effect = locals()[options.effect]
|
|
|
|
|
|
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:
|
2017-07-20 11:14:17 +02:00
|
|
|
print('Closing client')
|