diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/ColorOps.py | 17 | ||||
-rw-r--r-- | util/Geo.py | 6 | ||||
-rw-r--r-- | util/NetworkOps.py | 6 | ||||
-rw-r--r-- | util/PacketComposition.py | 15 |
4 files changed, 41 insertions, 3 deletions
diff --git a/util/ColorOps.py b/util/ColorOps.py index 037957a..4b1162a 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -1,4 +1,5 @@ import random +import colorsys from util.TimeOps import Stopwatch def randomColor(): return [random.randint(0,255) for i in range(3)] @@ -11,6 +12,8 @@ def safeColor(c): c[0] = c[0] if c[0] < 255 else 255 c[1] = c[1] if c[1] < 255 else 255 c[2] = c[2] if c[2] < 255 else 255 + + return c def combineColors(colors): @@ -23,3 +26,17 @@ def combineColors(colors): def multiplyColor(color, percent): return safeColor([channel*(percent) for channel in color]) + +def floatToIntColor(rgb): + rgb[0] = int(rgb[0]*256 + .5) + rgb[1] = int(rgb[1]*256 + .5) + rgb[2] = int(rgb[2]*256 + .5) + return safeColor(rgb) + +def randomBrightColor(): + hue = random.random() + sat = random.random()/2.0 + .5 + val = 1.0 + hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val) + ret = [hue, sat, val] + return floatToIntColor(ret) diff --git a/util/Geo.py b/util/Geo.py index 05ea9fe..0dde80b 100644 --- a/util/Geo.py +++ b/util/Geo.py @@ -26,3 +26,9 @@ def randomLoc(boundingBox): #TODO: make less shitty def approxexp(x): """Approximates exp with a 3 term Taylor Series.""" return 1+x+x**2/2+x**3/6 + +def windtrail(x,y,height,center,width): + a=height + b=center + c=width + return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2 diff --git a/util/NetworkOps.py b/util/NetworkOps.py index 8894b78..3ece763 100644 --- a/util/NetworkOps.py +++ b/util/NetworkOps.py @@ -8,3 +8,9 @@ def getConnectedSocket(ip,port): except Exception as inst: main_log.error('Network down. All network based renderers and sensors will not function.', inst) + +def getBroadcastSocket(port): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + return s diff --git a/util/PacketComposition.py b/util/PacketComposition.py index 7b4fe95..75ef917 100644 --- a/util/PacketComposition.py +++ b/util/PacketComposition.py @@ -5,7 +5,7 @@ PORTOUT = 0x0108 UNI = 0 import pdb import util.TimeOps as timeops -argDict = {'flags': 0, 'startcode': 0, 'pad':0} +argDict = {'flags': 0, 'startcode': 0x0fff, 'pad':0} def composePixelStripData(pixelStrip,currentTime=timeops.time()): packet = bytearray() @@ -33,10 +33,10 @@ def memoize(f): def cachePacketHeader(port): packet = bytearray() subDict = dict(argDict) - subDict['len'] = 38500 #I have no idea why this works. + subDict['len'] = 150 #I have no idea why this works. subDict['port'] = port packet.extend(portOutPacket(subDict)) - packet.append(0x0) +# packet.append(0x0) return packet def composePixelStripPacket(pixelStrip,port, currentTime): @@ -61,10 +61,19 @@ def portOut(): def portOutPayload(argDict): payload = bytearray() payload.extend(struct.pack('B', argDict['port'])) + payload.extend(struct.pack('B',0)) payload.extend(struct.pack('H', argDict['flags'])) payload.extend(struct.pack('H', argDict['len'])) payload.extend(struct.pack('H', argDict['startcode'])) return payload +def composeSynchPacket(): + header = bytearray() + header.extend(struct.pack('L', MAGIC)) + header.extend(struct.pack('H', VERSION)) + header.extend(struct.pack('H', 0x0109)) + header.extend(struct.pack('L', 0)) + header.extend(struct.pack('L', 0)) + return header def portOutPacket(payloadArgs): packet = bytearray() |