Ejemplo n.º 1
0
def main(args):

    parser = argparse.ArgumentParser()
    parser.add_argument("address", type=str, help="UDP address")
    parser.add_argument("-p", "--port", type=int, help="UDP port number")
    aa = parser.parse_args()

    #	print repr(aa)

    port = DEFAULT_PORT
    address = "127.0.0.1"
    if aa.port is not None:
        port = aa.port

    if port <= 0 or port == 0xFFFF:
        sys.stderr.write("bad port number %u\n" % port)
        return 1

    if aa.address is not None:
        address = aa.address

    # create main 'framebuffer'
    mainbuff = hex.HexBuff(20, 14, 0, 0, (0.2, 0.2, 0.2))

    # now connect to socket.
    LedClientBase.connect(address, port)

    img = PIL.Image.open(os.path.join("data", "nyan.gif"))
    img.seek(0)
    w, h = img.size
    colors = getPaletteInRgb(img)

    buffer = hex.HexBuff(w * 2, h * 2, 0, 0, (0.2, 0.2, 0.2))

    get_image(img, colors, buffer)

    for i in xrange(0x7FFF0000):
        for x in xrange(-w + 14, 0, 1):
            for i in xrange(3):
                img.seek(x % 4 * 3 + i)
                get_image(img, colors, buffer)

                mainbuff.blit(buffer, x, -1)
                # now prepare and send
                lin = list()
                for j in xrange(LedClientBase.NUMLEDS):
                    (xx, yy) = LedClientBase.seq_2_pos(j)
                    rgb_tuple = mainbuff.get_xy(xx, yy)
                    r, g, b = rgb_tuple

                    lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
                LedClientBase.send("".join(lin))

                time.sleep(0.08)

            time.sleep(0.05)

    LedClientBase.closedown()

    return 0
Ejemplo n.º 2
0
def get_matching_HexBuff(defVal=0, border=0):
    # simply scan seq2pos and find minimum match. No efficient, but consistent if the format changes.
    res = hex.HexBuff(2, 2)  # dummy to get xy2wh function
    W, H = 0, 0
    for xy in SEQ2POS.values():
        w, h = res.xy2wh(xy & 0xFFFF, xy >> 16)
        W = max(w, W)
        H = max(h, H)
    res = hex.HexBuff(W + 1 + 2 * border, H + 1 + 2 * border, border, border,
                      None)
    # fill in all valid spaces with the defVal
    for xy in SEQ2POS.values():
        res.set_xy(xy & 0xFFFF, xy >> 16, defVal)
    return res
Ejemplo n.º 3
0
def read_image(name):
    if not isinstance(name, basestring):
        raise ValueError("expect string as name.")
    im = PIL.Image.open(name)
    W, H = im.size

    W = int(W * 0.4 + 0.5)
    H = int(H * 0.4)
    W = W + (14 - W % 14)
    H = H + (14 - H % 14)

    #	im = im.resize((int(W),int(H)))
    maxsize = (14 * 8, 14 * 8)
    im.thumbnail(maxsize)
    W, H = im.size

    im.convert("RGB")
    #	im.show()

    buffer = hex.HexBuff(W, H, 0, 0, (0.2, 0.2, 0.2))

    print W, H
    for x in xrange(W):
        for y in xrange(H):
            p = im.getpixel((x, y))
            rgb = (float(p[0] / 255.0), float(p[1] / 255.0),
                   float(p[2] / 255.0))
            buffer.set_xy(x, H - y, rgb)
            if rgb != buffer.get_xy(x, H - y):
                print x, y

    return W, H, buffer
Ejemplo n.º 4
0
def main(args):


	parser = argparse.ArgumentParser()
	parser.add_argument("address",type=str,help="UDP address")
	parser.add_argument("-p","--port",type=int,help="UDP port number")
	aa = parser.parse_args()

#	print repr(aa)

	port = DEFAULT_PORT
	address = "127.0.0.1"
	if aa.port is not None:
		port = aa.port

	if port<=0 or port==0xFFFF:
		sys.stderr.write("bad port number %u\n"%port)
		return 1

	if aa.address is not None:
		address = aa.address

	LedClientBase.connect(address,port)
	
	mainbuff = hex.HexBuff(20,14,0,0,(0.0,0.0,0.0))
	mainbuff.fill_val((0.2,0.2,0.2))
		
	l = list()
	for i in range(10):
		l.append(read_hex_file(os.path.join("data","erlenmeier"+str(i)+".hex")))

	t = 0.0
	lr = -1
	for i in xrange(0x7FFF0000):

		# play
		mainbuff.fill_val((0.0,0.0,0.0))
		ii = (i%10)
		mainbuff.blit(l[ii],0,0,None)

		# now prepare and send
		lin = list()
		for j in xrange(LedClientBase.NUMLEDS):
			(xx,yy) = LedClientBase.seq_2_pos(j)
			rgb_tuple = mainbuff.get_xy(xx,yy)

			lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
		LedClientBase.send("".join(lin))

		time.sleep(0.100)
		t += 0.100

	LedClientBase.closedown()

	return 0
Ejemplo n.º 5
0
def main(args):

    parser = argparse.ArgumentParser()
    parser.add_argument("address", type=str, help="UDP address")
    parser.add_argument("-p", "--port", type=int, help="UDP port number")
    aa = parser.parse_args()

    #	print repr(aa)

    port = DEFAULT_PORT
    address = "127.0.0.1"
    if aa.port is not None:
        port = aa.port

    if port <= 0 or port == 0xFFFF:
        sys.stderr.write("bad port number %u\n" % port)
        return 1

    if aa.address is not None:
        address = aa.address

    # create main 'framebuffer'
    mainbuff = hex.HexBuff(20, 14, 0, 0, (0.2, 0.2, 0.2))

    # read image
    w, h, im = read_image(os.path.join("data", "nyan.png"))

    # now connect to socket.
    LedClientBase.connect(address, port)

    w = w / 2
    for i in xrange(0x7FFF0000):
        for y in xrange(-int(h) + 42, 1, 14):
            for x in xrange(-w + 14, 0, 1):
                mainbuff.blit(im, int(y * 0.5 - 0.5) + x, y)

                # now prepare and send
                lin = list()
                for j in xrange(LedClientBase.NUMLEDS):
                    (xx, yy) = LedClientBase.seq_2_pos(j)
                    rgb_tuple = mainbuff.get_xy(xx, yy)
                    r, g, b = rgb_tuple

                    lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
                LedClientBase.send("".join(lin))

                time.sleep(0.05)

    LedClientBase.closedown()

    return 0
Ejemplo n.º 6
0
def read_hex_file(name):
	v = hex.read_hex_file(name,True)
	w0,w1,h0,h1 = 0x10000,0,0x10000,0
	for x,y in v:
		h = y>>1
		w = ((x+h)>>1)
		w0=min(w,w0);w1=max(w,w1)
		h0=min(h,h0);h1=max(h,h1)
	res = hex.HexBuff(w1+1-w0,h1+1-h0,0,0,None)
	#res.fill_val((0.0,0.0,0.0))
	(ox,oy) = res.wh2xy(w,h)
	for x,y in v:
		h = y>>1
		w = ((x+h)>>1)
		col = v[(x,y)]
		if col is not None:
			res.set_wh(w-w0,h-h0,col)
	return res
Ejemplo n.º 7
0
def main(args):

    parser = argparse.ArgumentParser()
    parser.add_argument("address", type=str, help="UDP address")
    parser.add_argument("text", type=str, help="Text")
    parser.add_argument("-p", "--port", type=int, help="UDP port number")
    args = parser.parse_args()

    #	print repr(aa)

    port = DEFAULT_PORT
    address = "127.0.0.1"
    if args.port is not None:
        port = args.port

    if port <= 0 or port == 0xFFFF:
        sys.stderr.write("bad port number %u\n" % port)
        return 1

    if args.address is not None:
        address = args.address

    LedClientBase.connect(address, port)

    mainbuff = hex.HexBuff(20, 14, 0, 0, (0.0, 0.0, 0.0))
    mainbuff.fill_val((0.2, 0.2, 0.2))

    l = list()
    for i in range(len(args.text)):
        if (args.text[i] == "/"):
            l.append(read_hex_file(os.path.join("data", "slash.hex")))
        else:
            l.append(read_hex_file(os.path.join("data",
                                                args.text[i] + ".hex")))

    t = 0.0
    lr = -1
    length = 13 + len(l) * 7
    r = 0.5
    g = 0
    b = 0
    for i in xrange(0x7FFF0000):

        # play
        ii = (i % length)
        if (ii == 0):
            if (r == 0.5):
                g = 0.5
                r = 0
            elif (g == 0.5):
                b = 0.5
                g = 0
            elif (b == 0.5):
                r = 0.5
                b = 0
        mainbuff.fill_val((r, g, b))
        distance = 13
        for j in range(len(l)):
            mainbuff.blit(l[j], distance - ii, 4, None)
            distance += 7

        # now prepare and send
        lin = list()
        for j in xrange(LedClientBase.NUMLEDS):
            (xx, yy) = LedClientBase.seq_2_pos(j)
            rgb_tuple = mainbuff.get_xy(xx, yy)

            lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
        LedClientBase.send("".join(lin))

        time.sleep(0.03)
        t += 0.100

    LedClientBase.closedown()

    return 0
Ejemplo n.º 8
0
def main(args):

    parser = argparse.ArgumentParser()
    parser.add_argument("address", type=str, help="UDP address")
    parser.add_argument("text", type=str, help="Text")
    parser.add_argument("-p", "--port", type=int, help="UDP port number")
    parser.add_argument("-r", "--revert", default=False, action="store_true")
    parser.add_argument("-d", "--dynamic", default=False, action="store_true")
    aa = parser.parse_args()

    print repr(aa)

    port = DEFAULT_PORT
    address = "127.0.0.1"
    if aa.port is not None:
        port = aa.port

    if port <= 0 or port == 0xFFFF:
        sys.stderr.write("bad port number %u\n" % port)
        return 1

    if aa.address is not None:
        address = aa.address

    if not LedClientBase.connect(address, port):
        return 1

    mainbuff = hex.HexBuff(20, 14, 0, 0, (0.0, 0.0, 0.0))
    mainbuff.fill_val((0.2, 0.2, 0.2))
    l = list()
    for i in range(len(aa.text)):
        if (aa.text[i] == "/"):
            l.append(read_hex_file(os.path.join("data", "slash.hex")))
        elif (aa.text[i] == "."):
            l.append(read_hex_file(os.path.join("data", "dot.hex")))
        else:
            l.append(read_hex_file(os.path.join("data", aa.text[i] + ".hex")))

    t = 0.0
    length = 13 + len(l) * 7

    for i in xrange(0x7FFF0000):
        ii = (i % length)
        distance = 13
        mainbuff.fill_val((0, 0, 0.01))
        for j in range(len(l)):
            f = 0.96
            if (aa.dynamic):
                y = 4 * math.sin(2 * math.pi * f * (distance - ii) + t) + 4
            else:
                y = 4
            if (aa.revert):
                mainbuff.blit(l[j], distance - ii, int(y),
                              hex.HexBuff.XFORM_FLIP_X)
            else:
                mainbuff.blit(l[j], distance - ii, int(y), None)
            distance += 7

        lin = list()
        for j in xrange(LedClientBase.NUMLEDS):
            (xx, yy) = LedClientBase.seq_2_pos(j)
            rgb_tuple = mainbuff.get_xy(xx, yy)
            if (rgb_tuple == (1, 1, 1)):
                rgb_tuple = (0, 0, 0)
            if (rgb_tuple == (0, 0, 0.01)):
                rgb_tuple = color_calc_func_1(i, j, xx, yy)

            lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
        LedClientBase.send("".join(lin))

        time.sleep(0.06)
        t += 0.1

    LedClientBase.closedown()

    return 0
Ejemplo n.º 9
0
def main(args):
	parser = argparse.ArgumentParser()
	parser.add_argument("address",type=str,help="UDP address")
	parser.add_argument("-p","--port",type=int,help="UDP port number")
	args = parser.parse_args()

#	print repr(aa)

	cap = cv2.VideoCapture(0)

        port = DEFAULT_PORT
	address = "127.0.0.1"
        

        if args.port is not None:
		port = args.port

	if port<=0 or port==0xFFFF:
		sys.stderr.write("bad port number %u\n"%port)
		return 1

	if args.address is not None:
		address = args.address

	LedClientBase.connect(address,port)

	mainbuff = hex.HexBuff(21,16,0,0,(0.0,0.0,0.0))
	l = list()

        for i in range(1+LedClientBase.NUMLEDS):
		# now prepare and send
                if(i == 0):
	            mainbuff.fill_val((0,0,0.2))
                if(i>0):
	            mainbuff.fill_val((0,0,0))
		    (xx,yy) = LedClientBase.seq_2_pos(i-1)
                    mainbuff.set_xy(xx,yy,(0,0,0.1))
                    print(i)
		lin = list()
		for j in xrange(LedClientBase.NUMLEDS):
			(xx,yy) = LedClientBase.seq_2_pos(j)
			rgb_tuple = mainbuff.get_xy(xx,yy)

			lin.append(LedClientBase.rgbF_2_bytes(rgb_tuple))
		LedClientBase.send("".join(lin))
                if(i == 0):
                    #im=ImageGrab.grab(bbox=(640,20,1280,800)) # X1,Y1,X2,Y2
                    #im.save('a.png')
                    #im = cv2.imread('a.png')
                    ret, im =cap.read()
                    lower=[200,0,0]
                    lower=np.array(lower,dtype="uint8")
                    upper=[255,250,250]
                    upper = np.array(upper,dtype="uint8")
                    allmask = cv2.inRange(im,lower,upper)
                else:
                    time.sleep(1)
                    im = cv2.bitwise_and(im,im,mask=allmask)
                    #cv2.imwrite('b.png',im)
                    cv2.imshow("Image",im)
                    cv2.waitKey()
	LedClientBase.closedown()
	return 0