From 28b1fb71f4dd0f2db190c345ba1ae2e858d530d0 Mon Sep 17 00:00:00 2001 From: nrhck Date: Sun, 24 Mar 2019 17:24:52 +0100 Subject: [PATCH] IdiotIA anims --- LJ.conf | 10 +- cli.py | 9 +- plugins.py | 1 + plugins/VJing/idiotia.py | 297 ++++++++++++++++++++++++++++-------- plugins/VJing/lj3.py | 3 +- plugins/laserglyph.py | 13 +- plugins/livewords.py | 16 +- plugins/lj.py | 322 +++++++++++++++++++++++++++++++++++++++ plugins/lj3.py | 3 +- plugins/pysimu.py | 17 ++- plugins/textcycl.py | 12 +- webui/LJ.js | 8 +- webui/LJgrid.css | 2 +- webui/index.html | 58 ++++--- webui/knobs/bank0.png | Bin 0 -> 5239 bytes webui/knobs/idiotia.png | Bin 1832 -> 1844 bytes webui/knobs/pose.png | Bin 0 -> 4326 bytes 17 files changed, 660 insertions(+), 111 deletions(-) create mode 100644 plugins/lj.py create mode 100644 webui/knobs/bank0.png create mode 100644 webui/knobs/pose.png diff --git a/LJ.conf b/LJ.conf index 45891e5..610f3c9 100644 --- a/LJ.conf +++ b/LJ.conf @@ -1,13 +1,13 @@ [General] lasernumber = 4 -debug = 0 -ljayserverip = 192.168.2.13 +debug = 2 +ljayserverip = 127.0.0.1 nozoscip = 127.0.0.1 -bhoroscip = 192.168.2.13 +bhoroscip = 127.0.0.1 [laser0] color = -1 -ip = 127.0.0.1 +ip = 192.168.1.4 kpps = 25000 centerx = -1610 centery = 0 @@ -64,7 +64,7 @@ warpdest = [[-1500., 1500.], [laser3] color = -1 -ip = 192.168.1.4 +ip = 192.168.1.5 kpps = 25000 centerx = -12 centery = 0 diff --git a/cli.py b/cli.py index ea29177..0f22669 100644 --- a/cli.py +++ b/cli.py @@ -24,7 +24,7 @@ def handle(): #have to be done before importing bhorosc.py to get correct port assignment argsparser = argparse.ArgumentParser(description="LJ v0.8") argsparser.add_argument("-r","--redisIP",help="IP address to bind builtin servers (OSC and websocket) also must be the Redis server IP ",type=str) - argsparser.add_argument("-L","--Lasers",help="Number of lasers connected.",type=int) + argsparser.add_argument("-L","--Lasers",help="Number of lasers connected (4 by default).",type=int) argsparser.add_argument("-v","--verbose",help="Debug mode 0,1 or 2 (0 by default)",type=int) argsparser.add_argument("-x","--invx",help="Invert laser 0 X axis again",action="store_true") argsparser.add_argument("-y","--invy",help="Invert laser 0 Y axis again",action="store_true") @@ -109,12 +109,15 @@ def handle(): # Lasers = number of laser connected if args.Lasers != None: gstt.LaserNumber = args.Lasers - + else: + gstt.LaserNumber = 4 + if args.bhoroscIP != None: gstt.oscIPin = args.bhoroscIP else: - gstt.oscIPin = gstt.LjayServerIP + gstt.oscIPin = '127.0.0.1' + if args.nozoidIP != None: gstt.nozoscIP = args.nozoidIP diff --git a/plugins.py b/plugins.py index 868e4ab..ddff9dc 100644 --- a/plugins.py +++ b/plugins.py @@ -117,6 +117,7 @@ def OSCsend(name, oscaddress, oscargs =''): def Ping(name): return OSCsend(name,"/ping") + #return True def Kill(name): diff --git a/plugins/VJing/idiotia.py b/plugins/VJing/idiotia.py index 0518489..d3cbafb 100644 --- a/plugins/VJing/idiotia.py +++ b/plugins/VJing/idiotia.py @@ -9,6 +9,7 @@ IdiotIA for THSF 10 Include IdiotIA and Starfields + /pose/ljclient LICENCE : CC Sam Neurohack, Loloster, @@ -41,15 +42,22 @@ xy_center = [screen_size[0]/2,screen_size[1]/2] message = "LO" OSCinPort = 8011 -redisIP = '127.0.0.1' ljclient = 0 +idiotiaDisplay = [True,True,True,True] +liveDisplay = [False,False,False,False] +fieldsDisplay = [False,False,False,False] +currentIdiotia = 0 + print ("") print ("Arguments parsing if needed...") argsparser = argparse.ArgumentParser(description="Pose bank for LJ") argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str) +argsparser.add_argument("-m","--myIP",help="Local IP (127.0.0.1 by default) ",type=str) argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) +argsparser.add_argument("-a","--anim",help="IdiotIA anim (0 by default)",type=int) +argsparser.add_argument("-L","--Lasers",help="Number of lasers connected (4 by default).",type=int) args = argsparser.parse_args() @@ -64,12 +72,29 @@ if args.client: else: ljclient = 0 +if args.anim: + currentIdiotia = args.anim +else: + currentIdiotia = 0 + # Redis Computer IP if args.redisIP != None: redisIP = args.redisIP else: redisIP = '127.0.0.1' +# myIP +if args.myIP != None: + myIP = args.myIP +else: + myIP = '127.0.0.1' + +# Lasers = number of laser connected +if args.Lasers != None: + LaserNumber = args.Lasers +else: + LaserNumber = 4 + lj3.Config(redisIP,ljclient) @@ -135,6 +160,16 @@ def eyeL(pose_json, people): pose_points = [42,43,44,45,46,47,42] return getFACE(pose_json,pose_points, people) +def pupR(pose_json, people): + pose_points = [68,68] + print(getFACE(pose_json,pose_points, people)) + return getFACE(pose_json,pose_points, people) + +def pupL(pose_json, people): + pose_points = [69,69] + return getFACE(pose_json,pose_points, people) + + def nose(pose_json, people): pose_points = [27,28,29,30] return getFACE(pose_json,pose_points, people) @@ -145,34 +180,65 @@ def mouth(pose_json, people): -def prepareIdiotIA(): +def prepareIdiotIA(currentAnim): + - WebStatus("Init IdiotIA...") + WebStatus("Checking anims...") + print() + print("Reading available IdiotIA anims...") # anim format (name, xpos, ypos, resize, currentframe, totalframe, count, speed) # 0 1 2 3 4 5 6 7 # total frames is fetched from directory by lengthPOSE() - anims[0] = [['idiotia1', xy_center[0], xy_center[1], 300,0,0,0,5]] - anims[1] = [['idiotia1', xy_center[0], xy_center[1] + 50, 400,0,0,0,15]] - anims[2] = [['idiotia1', xy_center[0], xy_center[1] + 50, 500,0,0,0,25]] - anims[3] = [['idiotia1', xy_center[0], xy_center[1], 500,0,0,0,25]] + anims[0] = [['boredhh', xy_center[0], xy_center[1] + 130, 550,0,0,0,5]] + anims[1] = [['belka4', xy_center[0], xy_center[1] + 280, 600,0,0,0,5]] + anims[2] = [['belka3', xy_center[0], xy_center[1] + 280, 600,0,0,0,5]] + anims[3] = [['hhbored2', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]] + anims[4] = [['hhhead', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]] + anims[5] = [['hhhead2', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[6] = [['hhhead4', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[7] = [['hhred', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]] + anims[8] = [['hhred2', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]] + anims[9] = [['lady1', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[10] = [['lady2', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[11] = [['lady3', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]] + anims[12] = [['lady4', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]] + anims[13] = [['mila6', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[14] = [['mila5', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[15] = [['idiotia1', xy_center[0], xy_center[1]+ 300, 600,0,0,0,25]] + anims[16] = [['idiotia1', xy_center[0], xy_center[1]+ 300, 600,0,0,0,5]] + anims[17] = [['belka4', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + anims[18] = [['belka3', xy_center[0], xy_center[1] + 280, 600,0,0,0,30]] + for laseranims in anims: for anim in laseranims: anim[5] = lengthPOSE(anim[0]) - + WebStatus("Checking "+ anim[0] +"...") if debug > 0: - print("anim :", 'poses/' + anim[0], "length :", anim[5], "frames") + print('poses/' + anim[0], "length :", anim[5], "frames") + + print("Current IdiotIA anim is",anims[currentIdiotia][0],"("+str(currentIdiotia)+")") -# display the face animation describe in PoseDir + + +# display the currentIdiotia animation on all lasers according to display flag def IdiotIA(): - for laseranims in range(3): - for anim in anims[laseranims]: - PL = laseranims + # All laser loop + for laser in range(LaserNumber): + # for anim in anims[laseranims]: + + # if display flag is True, send the face points. + if idiotiaDisplay[laser]: + + anim = anims[currentIdiotia][0] + #print(anim) + + PL = laser #print PL, anim dots = [] @@ -189,23 +255,25 @@ def IdiotIA(): posedatas = posefile.read() pose_json = json.loads(posedatas) - # Face + # Draw Face for people in range(len(pose_json['people'])): - #lj3.rPolyLineOneColor(face(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) - lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + #lj3.rPolyLineOneColor(face(pose_json, people), c = white, PL = laser closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(browL(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(browR(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(eyeR(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + #lj3.rPolyLineOneColor(pupR(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(eyeL(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + #lj3.rPolyLineOneColor(pupL(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(nose(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) + lj3.rPolyLineOneColor(mouth(pose_json, people), c = white, PL = laser, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) lj3.DrawPL(PL) time.sleep(0.02) -# many starfields +# Init Starfields def prepareSTARFIELD(): global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth @@ -230,6 +298,9 @@ def prepareSTARFIELD(): star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)] stars2.append(star) + +# Todo : Currently compute all starfields even if field display flag is False. + def Starfield(hori=0,verti=0): global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth @@ -313,16 +384,16 @@ def Starfield(hori=0,verti=0): y2 = int(stars2[starnumber][1] * k2 + xy_center[1] + (verti*300)) - # Add star to pointlist PL 0 - if 0 <= x0 < screen_size[0] - 2 and 0 <= y0 < screen_size[1] - 2: + # Add star to pointlist PL 0 if field display flag is true + if fieldsDisplay[0] and 0 <= x0 < screen_size[0] - 2 and 0 <= y0 < screen_size[1] - 2: lj3.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c = white, PL = 0, closed = False) - # Add star to pointlist PL 1 - if 0 <= x1 < screen_size[0] - 2 and 0 <= y1 < screen_size[1] - 2: + # Add star to pointlist PL 1 if field display flag is true + if fieldsDisplay[1] and 0 <= x1 < screen_size[0] - 2 and 0 <= y1 < screen_size[1] - 2: lj3.PolyLineOneColor([(x1,y1),((x1+1),(y1+1))], c = white, PL = 1, closed = False) - # Add star to pointlist PL 2 - if 0 <= x2 < screen_size[0] - 2 and 0 <= y2 < screen_size[1] - 2: + # Add star to pointlist PL 2 if field display flag is true + if fieldsDisplay[2] and 0 <= x2 < screen_size[0] - 2 and 0 <= y2 < screen_size[1] - 2: lj3.PolyLineOneColor([(x2,y2),((x2+1),(y2+1))], c= white, PL = 2, closed = False) ''' @@ -332,41 +403,105 @@ def Starfield(hori=0,verti=0): fwork.PolyLineOneColor([(x3,y3),((x3+2),(y3+2))], c=colorify.rgb2hex([255,255,255]), PL = 3, closed = False) ''' - - lj3.Text(message, white, PL = 3, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0) - lj3.DrawPL(0) - lj3.DrawPL(1) - lj3.DrawPL(2) - lj3.DrawPL(3) - - -def OSCidiotia(address,value): - print("idiotia",address,value) + # Laser 3 Display a word. + if fieldsDisplay[3]: + lj3.Text(message, white, PL = 3, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0) + # If field display is True for each laser + for laser in range(LaserNumber): + + # Actually send the field point list. + if fieldsDisplay[laser]: + lj3.DrawPL(laser) + + +# display the Realtime open pose face according to flag. +def LiveFace(): + + # All laser loop + for laser in range(LaserNumber): + # for anim in anims[laseranims]: + + # if display flag is True, send the face points. + if liveDisplay[laser]: + pass + + + +# /pose/idiotia/lasernumber 1 +def OSCidiotia(address, value): + + print("idiotia",address,value) + + laser = int(address[14:]) + print("laser", laser, value) + + if value == 1: + + idiotiaDisplay[laser] = True + liveDisplay[laser] = False + fieldsDisplay[laser] = False + print(idiotiaDisplay,liveDisplay,fieldsDisplay) + + else: + + idiotiaDisplay[laser] = False + print(idiotiaDisplay,liveDisplay,fieldsDisplay) + + +# /pose/anim +def OSCanim(address,state): + + print("/pose/anim",address, state) + anim = int(address[12:]) + print(anim, state) + + if state == 1: + currentIdiotia = anim + + +# /pose/live/lasernumber value +def OSClive(address,value): + + print("live",address,value) + laser = int(address[11:]) + print("laser", laser, value) + + if value == "1": + idiotiaDisplay[value] = False + liveDisplay[value] = True + fieldsDisplay[value] = False + +# /pose/field/lasernumber value def OSCfield(address, value): + print("Pose bank field got", address, "with value", value) + laser = int(address[12:]) + print("laser", laser, value) + + if value == "1": + idiotiaDisplay[value] = False + liveDisplay[value] = False + fieldsDisplay[value] = True +# /pose/ljclient def OSCljclient(value): print("Pose bank got /pose/ljclient with value", value) ljclient = value lj3.LjClient(ljclient) -def OSCpl(value): - - print("Pose bank got /pose/pl with value", value) - lj3.WebStatus("Pose bank to pl "+ str(value)) - lj3.LjPl(value) - +''' # Starfield, idiotia def OSCrun(value): # Will receive message address, and message data flattened in s, x, y print("Pose bank got /run with value", value) doit = value +''' # /quit def OSCquit(): @@ -380,53 +515,85 @@ def WebStatus(message): lj3.SendLJ("/status",message) +# Update Pose webUI +def UpdatePoseUI(): + + WebStatus("Updating Pose UI...") + for laser in range(LaserNumber): + + if idiotiaDisplay[laser]: + lj3.SendLJ("pose/idiotia/" + str(laser) + " 1") + else: + lj3.SendLJ("pose/idiotia/" + str(laser) + " 0") + + if liveDisplay[laser]: + lj3.SendLJ("pose/live/" + str(laser) + " 1") + else: + lj3.SendLJ("pose/live/" + str(laser) + " 0") + + if fieldsDisplay[laser]: + lj3.SendLJ("pose/field/" + str(laser) + " 1") + else: + lj3.SendLJ("pose/field/" + str(laser) + " 0") + + + for anim in range(19): + if anim == currentIdiotia: + lj3.SendLJ("pose/anim/" + str(anim) + " 1") + else: + lj3.SendLJ("pose/anim/" + str(anim) + " 0") + + print('Loading Pose bank...') - WebStatus("Loading Pose bank...") # OSC Server callbacks -print("Starting OSC at 127.0.0.1 port",OSCinPort,"...") +print("Starting OSC server at",myIP,":",OSCinPort,"...") osc_startup() -osc_udp_server("127.0.0.1", OSCinPort, "InPort") +osc_udp_server(myIP, OSCinPort, "InPort") -osc_method("/pose/run*", OSCrun) -osc_method("/pose/ping*", lj3.OSCping) +#osc_method("/pose/run*", OSCrun) +osc_method("/ping*", lj3.OSCping) osc_method("/pose/ljclient", OSCljclient) -osc_method("/pose/ljpl", OSCpl) osc_method("/quit", OSCquit) -osc_method("/pose/idiotia*", OSCidiotia, argscheme=OSCARG_ADDRESS + OSCARG_DATA) -osc_method("/pose/field*", OSCfield, argscheme=OSCARG_ADDRESS + OSCARG_DATA) +osc_method("/pose/idiotia/*", OSCidiotia, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK) +osc_method("/pose/field/*", OSCfield,argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK) +osc_method("/pose/live/*", OSClive, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK) +osc_method("/pose/anim/*", OSCanim, argscheme=OSCARG_ADDRESS + OSCARG_DATAUNPACK) -anims =[[],[],[],[]] -color = lj3.rgb2int(255,255,255) - - - - - - -prepareIdiotIA() -#prepareSTARFIELD() +anims =[[]]*20 +#color = lj3.rgb2int(255,255,255) +prepareIdiotIA(0) +prepareSTARFIELD() #doit = Starfield -doit = IdiotIA +#doit = IdiotIA white = lj3.rgb2int(255,255,255) red = lj3.rgb2int(255,0,0) blue = lj3.rgb2int(0,0,255) green = lj3.rgb2int(0,255,0) +print("Updating Pose UI...") +UpdatePoseUI() + WebStatus("Pose bank running.") print("Pose bank running") + + + + def Run(): try: while 1: - #Starfield(hori=0,verti=0) - doit() + + Starfield(hori=0,verti=0) + IdiotIA() + LiveFace() except KeyboardInterrupt: pass diff --git a/plugins/VJing/lj3.py b/plugins/VJing/lj3.py index 5f54c26..e9159fe 100644 --- a/plugins/VJing/lj3.py +++ b/plugins/VJing/lj3.py @@ -99,6 +99,7 @@ def OSCping(value): print("Got /ping with value", value) SendLJ("/pong",value) + # /quit def OSCquit(name): @@ -225,7 +226,7 @@ def rgb2int(r,g,b): def Config(redisIP,client): - global ClientNumber + global ClientNumber, r r = redis.StrictRedis(host=redisIP, port=6379, db=0) ClientNumber = client diff --git a/plugins/laserglyph.py b/plugins/laserglyph.py index b8eb391..9d2378f 100644 --- a/plugins/laserglyph.py +++ b/plugins/laserglyph.py @@ -30,6 +30,7 @@ argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int) argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) +argsparser.add_argument("-m","--myIP",help="Local IP (127.0.0.1 by default) ",type=str) args = argsparser.parse_args() @@ -52,15 +53,23 @@ else: print("redisIP",redisIP) +# myIP +if args.myIP != None: + myIP = args.myIP +else: + myIP = '127.0.0.1' + +print("redisIP",redisIP) + if args.verbose: debug = args.verbose else: debug = 0 -r = lj3.Config(redisIP,ljclient) +lj3.Config(redisIP,ljclient) + -print("r :",r) width = 800 height = 600 centerX = width / 2 diff --git a/plugins/livewords.py b/plugins/livewords.py index d0d48c1..5f7771b 100644 --- a/plugins/livewords.py +++ b/plugins/livewords.py @@ -15,6 +15,7 @@ from osc4py3 import oscbuildparse #from osc4py3 import oscmethod as osm from osc4py3.oscmethod import * +myIP = "127.0.0.1" duration = 300 @@ -35,6 +36,7 @@ else: print ("Words is checking arguments parsing if needed...") argsparser = argparse.ArgumentParser(description="Text Cycling for LJ") argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str) +argsparser.add_argument("-m","--myIP",help="Local IP (127.0.0.1 by default) ",type=str) argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) @@ -52,6 +54,12 @@ if args.redisIP != None: else: redisIP = '127.0.0.1' +# myIP +if args.myIP != None: + myIP = args.myIP +else: + myIP = '127.0.0.1' + if args.verbose: debug = args.verbose @@ -82,10 +90,10 @@ def OSCword2(value): # Will receive message address, and message data flattened in s, x, y print("Words 2 got /words/text/2 with value", value) - Word3 = value + Word2 = value def OSCword3(value): - global Words3 + global Word3 # Will receive message address, and message data flattened in s, x, y print("Words 3 got /words/text/3 with value", value) @@ -116,9 +124,9 @@ def OSCquit(): def Run(): # OSC Server callbacks - print("Words starting its OSC server at 127.0.0.1 port",OSCinPort,"...") + print("Words starting its OSC server at", myIP, "port",OSCinPort,"...") osc_startup() - osc_udp_server("127.0.0.1", OSCinPort, "InPort") + osc_udp_server(myIP, OSCinPort, "InPort") osc_method("/words/text/0*", OSCword0) osc_method("/words/text/1*", OSCword1) osc_method("/words/text/2*", OSCword2) diff --git a/plugins/lj.py b/plugins/lj.py new file mode 100644 index 0000000..5244032 --- /dev/null +++ b/plugins/lj.py @@ -0,0 +1,322 @@ +# coding=UTF-8 + +''' +LJ v0.8.1 +Some LJ functions useful for python 2.7 clients (was framy.py) +Functions and documentation here is low priority as python 2 support will stop soon. +Better code your plugin with python 3 and lj3.py. + + +Config +PolyLineOneColor +rPolyLineOneColor +Text +SendLJ : remote control +LjClient : +LjPl : +DrawPL +WebStatus + +LICENCE : CC +Sam Neurohack + +''' + +import math +import redis +from OSC import OSCServer, OSCClient, OSCMessage + +redisIP = '127.0.0.1' +r = redis.StrictRedis(host=redisIP, port=6379, db=0) + +ClientNumber = 0 + +point_list = [] +pl = [[],[],[],[]] + + + +def SendLJ(oscaddress,oscargs=''): + + oscmsg = OSCMessage() + oscmsg.setAddress(oscaddress) + oscmsg.append(oscargs) + + print ("sending OSC message : ",oscmsg) + try: + osclientlj.sendto(oscmsg, (redisIP, 8002)) + oscmsg.clearData() + except: + print ('Connection to LJ refused : died ?') + pass + #time.sleep(0.001 + +def WebStatus(message): + SendLJ("/status", message) + + +ASCII_GRAPHICS = [ + +#implementé + + [(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)], #0 + [(-20,30), (0,-30), (-20,30)], #1 + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #2 + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #3 + [(30,10), (-30,10), (0,-30), (0,30)], #4 + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #5 + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #6 + [(-30,-30), (30,-30), (-30,30)], #7 + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #8 + [(30,0), (-30,0), (-30,-10), (0,-30), (30,-30), (30,10), (0,30), (-30,30)], #9 + +# A implementer + [(-30,10), (30,-10), (30,10), (0,30), (-30,10), (-30,-10), (0,-30), (30,-10)], #: + [(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #; + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #< + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #= + [(30,10), (-30,10), (0,-30), (0,30)], #> + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #? + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #@ + +# Implementé + + + [(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A + [(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #B + [(30,30), (-30,30), (-30,-30), (30,-30)], #C + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #D + [(30,30), (-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #E + [(-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #F + [(0,0), (30,0), (30,30), (-30,30), (-30,-30),(30,-30)], #G + [(-30,-30), (-30,30), (-30,0), (30,0), (30,30), (30,-30)], #H + [(0,30), (0,-30)], #I + [(-30,30), (0,-30), (0,-30), (-30,-30), (30,-30)], #J + [(-30,-30), (-30,30), (-30,0), (30,-30), (-30,0), (30,30)], #K + [(30,30), (-30,30), (-30,-30)], #L + [(-30,30), (-30,-30), (0,0), (30,-30), (30,30)], #M + [(-30,30), (-30,-30), (30,30), (30,-30)], #N + [(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #O + [(-30,0), (30,0), (30,-30), (-30,-30), (-30,30)], #P + [(30,30), (30,-30), (-30,-30), (-30,30), (30,30),(35,35)], #Q + [(-30,30), (-30,-30), (30,-30), (30,0), (-30,0), (30,30)], #R + [(30,-30), (-30,-30), (-30,0), (30,0), (30,30), (-30,30)], #S + [(0,30), (0,-30), (-30,-30), (30,-30)], #T + [(-30,-30), (-30,30), (30,30), (30,-30)], #U + [(-30,-30), (0,30), (30,-30)], #V + [(-30,-30), (-30,30), (0,0), (30,30), (30,-30)], #W + [(-30,30), (30,-30)], [(-30,-30), (30,30)], #X + [(0,30), (0,0), (30,-30), (0,0), (-30,-30)], #Y + [(30,30), (-30,30), (30,-30), (-30,-30)], #Z + + # A implementer + + [(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #[ + [(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #\ + [(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #] + [(30,10), (-30,10), (0,-30), (0,30)], #^ + [(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #_ + [(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #` + + # Implementé + + [(-20,20), (-20,-20), (20,-20), (20,20), (20,0), (-20,0)], #a + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20), (-20,0), (20,0)], #b + [(20,20), (-20,20), (-20,-20), (20,-20)], #c + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #d + [(20,20), (-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #e + [(-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #f + [(0,0), (20,0), (20,20), (-20,20), (-20,-20),(20,-20)], #g + [(-20,-20), (-20,20), (-20,0), (20,0), (20,20), (20,-20)], #H + [(0,20), (0,-20)], #I + [(-20,20), (0,-20), (0,-20), (-20,-20), (20,-20)], #J + [(-20,-20), (-20,20), (-20,0), (20,-20), (-20,0), (20,20)], #K + [(20,20), (-20,20), (-20,-20)], #L + [(-20,20), (-20,-20), (0,0), (20,-20), (20,20)], #M + [(-20,20), (-20,-20), (20,20), (20,-20)], #N + [(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #O + [(-20,0), (20,0), (20,-20), (-20,-20), (-20,20)], #P + [(20,20), (20,-20), (-20,-20), (-20,20), (20,20),(25,25)], #Q + [(-20,20), (-20,-20), (20,-20), (20,0), (-20,0), (20,20)], #R + [(20,-20), (-20,-20), (-20,0), (20,0), (20,20), (-20,20)], #S + [(0,20), (0,-20), (-20,-20), (20,-20)], #T + [(-20,-20), (-20,20), (20,20), (20,-20)], #U + [(-20,-20), (0,20), (20,-20)], #V + [(-20,-20), (-20,20), (0,0), (20,20), (20,-20)], #W + [(-20,20), (20,-20)], [(-20,-20), (20,20)], #X + [(0,20), (0,0), (20,-20), (0,0), (-20,-20)], #Y + [(20,20), (-20,20), (20,-20), (-20,-20)], #Z + + [(-2,15), (2,15)] # Point a la place de { +] + +def Config(redisIP,client): + global ClientNumber + + r = redis.StrictRedis(host=redisIP, port=6379, db=0) + ClientNumber = client + #print "client configured",ClientNumber + + +def LjClient(client): + global ClientNumber + + ClientNumber = client + +def LjPl(pl): + global PL + + PL = pl + + +def LineTo(xy, c, PL): + + pl[PL].append((xy + (c,))) + +def Line(xy1, xy2, c, PL): + LineTo(xy1, 0, PL) + LineTo(xy2, c , PL) + + +def PolyLineOneColor(xy_list, c, PL , closed ): + #print "--" + #print "c",c + #print "xy_list",xy_list + #print "--" + xy0 = None + for xy in xy_list: + if xy0 is None: + xy0 = xy + #print "xy0:",xy0 + LineTo(xy0,0, PL) + LineTo(xy0,c, PL) + else: + #print "xy:",xy + LineTo(xy,c, PL) + if closed: + LineTo(xy0,c, PL) + + +# Computing points coordinates for rPolyline function from 3D and around 0,0 to pygame coordinates +def Pointransf(xy, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0): + + x = xy[0] * resize + y = xy[1] * resize + z = 0 + + rad = math.radians(rotx) + cosaX = math.cos(rad) + sinaX = math.sin(rad) + + y2 = y + y = y2 * cosaX - z * sinaX + z = y2 * sinaX + z * cosaX + + rad = math.radians(roty) + cosaY = math.cos(rad) + sinaY = math.sin(rad) + + z2 = z + z = z2 * cosaY - x * sinaY + x = z2 * sinaY + x * cosaY + + rad = math.radians(rotz) + cosZ = math.cos(rad) + sinZ = math.sin(rad) + + x2 = x + x = x2 * cosZ - y * sinZ + y = x2 * sinZ + y * cosZ + + #print xy, (x + xpos,y+ ypos) + return (x + xpos,y+ ypos) + ''' + to understand why it get negative Y + + # 3D to 2D projection + factor = 4 * gstt.cc[22] / ((gstt.cc[21] * 8) + z) + print xy, (x * factor + xpos, - y * factor + ypos ) + return (x * factor + xpos, - y * factor + ypos ) + ''' + +# Send 2D point list around 0,0 with 3D rotation resizing and reposition around xpos ypos +#def rPolyLineOneColor(self, xy_list, c, PL , closed, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0): +def rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =0.7, rotx =0, roty =0 , rotz=0): + xy0 = None + for xy in xy_list: + if xy0 is None: + xy0 = xy + LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),0, PL) + LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL) + else: + LineTo(Pointransf(xy, xpos, ypos, resize, rotx, roty, rotz),c, PL) + if closed: + LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL) + + +def LinesPL(PL): + print "Stupido !! your code is to old : use DrawPL() instead of LinesPL()" + DrawPL(PL) + + +def DrawPL(PL): + #print '/pl/0/'+str(PL), str(pl[PL]) + if r.set('/pl/'+str(ClientNumber)+'/'+str(PL), str(pl[PL])) == True: + #print '/pl/'+str(ClientNumber)+'/'+str(PL), str(pl[PL]) + pl[PL] = [] + return True + else: + return False + +def ResetPL(self, PL): + pl[PL] = [] + + + +def DigitsDots(number,color): + dots =[] + for dot in ASCII_GRAPHICS[number]: + #print dot + dots.append((gstt.xy_center[0]+dot[0],gstt.xy_center[1]+dot[1],color)) + #self.point_list.append((xy + (c,))) + return dots + +def CharDots(char,color): + + dots =[] + for dot in ASCII_GRAPHICS[ord(char)-46]: + dots.append((dot[0],dot[1],color)) + return dots + +def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz): + + dots =[] + + l = len(message) + i= 0 + #print message + + for ch in message: + + #print "" + # texte centre en x automatiquement selon le nombre de lettres l + x_offset = 26 * (- (0.9*l) + 3*i) + # Digits + if ord(ch)<58: + char_pl_list = ASCII_GRAPHICS[ord(ch) - 48] + else: + char_pl_list = ASCII_GRAPHICS[ord(ch) - 46] + char_draw = [] + #dots.append((char_pl_list[0][0] + x_offset,char_pl_list[0][1],0)) + + for xy in char_pl_list: + char_draw.append((xy[0] + x_offset,xy[1],c)) + i +=1 + #print ch,char_pl_list,char_draw + rPolyLineOneColor(char_draw, c, PL , False, xpos, ypos, resize, rotx, roty, rotz) + #dots.append(char_draw) + + + + \ No newline at end of file diff --git a/plugins/lj3.py b/plugins/lj3.py index 5f54c26..e9159fe 100644 --- a/plugins/lj3.py +++ b/plugins/lj3.py @@ -99,6 +99,7 @@ def OSCping(value): print("Got /ping with value", value) SendLJ("/pong",value) + # /quit def OSCquit(name): @@ -225,7 +226,7 @@ def rgb2int(r,g,b): def Config(redisIP,client): - global ClientNumber + global ClientNumber, r r = redis.StrictRedis(host=redisIP, port=6379, db=0) ClientNumber = client diff --git a/plugins/pysimu.py b/plugins/pysimu.py index 0d28226..e65adc0 100755 --- a/plugins/pysimu.py +++ b/plugins/pysimu.py @@ -31,8 +31,10 @@ import pdb import types, ast, argparse from OSC import OSCServer, OSCClient, OSCMessage + pl = [[],[],[],[]] + print ("") print ("LJ v0.8.0 : Pygame simulator") print ("") @@ -42,8 +44,9 @@ print ("Arguments parsing if needed...") # Arguments parsing # -argsparser = argparse.ArgumentParser(description="Available commands") +argsparser = argparse.ArgumentParser(description="One laser Simulator for LJ") argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str) +argsparser.add_argument("-m","--myIP",help="Local IP (127.0.0.1 by default) ",type=str) argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int) argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) @@ -76,14 +79,22 @@ else: r = redis.StrictRedis(host=redisIP, port=6379, db=0) +# myIP +if args.myIP != None: + myIP = args.myIP +else: + myIP = '127.0.0.1' + + + # # OSC # -oscIPin = "127.0.0.1" +oscIPin = myIP oscPORTin = 8008 -ljIP = "127.0.0.1" +ljIP = redisIP ljPort = 8002 print ("") diff --git a/plugins/textcycl.py b/plugins/textcycl.py index 4ac34e6..ce33b84 100644 --- a/plugins/textcycl.py +++ b/plugins/textcycl.py @@ -35,6 +35,7 @@ else: print ("Arguments parsing if needed...") argsparser = argparse.ArgumentParser(description="Text Cycling for LJ") argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str) +argsparser.add_argument("-m","--myIP",help="Local IP (127.0.0.1 by default) ",type=str) argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int) argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) @@ -64,6 +65,14 @@ if args.redisIP != None: else: redisIP = '127.0.0.1' + +# myIP +if args.myIP != None: + myIP = args.myIP +else: + myIP = '127.0.0.1' + + lj3.Config(redisIP,ljclient) #r = redis.StrictRedis(host=redisIP, port=6379, db=0) @@ -101,8 +110,9 @@ def OSCquit(): lj3.OSCquit("cycl") +print("Cycl starting its OSC server at", myIP, "port",OSCinPort,"...") osc_startup() -osc_udp_server("127.0.0.1", OSCinPort, "InPort") +osc_udp_server(myIP, OSCinPort, "InPort") osc_method("/ping*", OSCping) osc_method("/quit", OSCquit) diff --git a/webui/LJ.js b/webui/LJ.js index 305b978..207f87d 100644 --- a/webui/LJ.js +++ b/webui/LJ.js @@ -2,6 +2,10 @@ // LJ.js v0.7.1 // +// LJ websocket address. Change here if LJ is not bind to 127.0.0.1 + + var LJ = 'ws://127.0.0.1:9001/' + // // Central horizontal menu // @@ -204,7 +208,7 @@ var pl = ""; var pl2 = new Array(); var _WS = { - uri: 'ws://192.168.2.13:9001/', + uri: LJ, ws: null, init : function (e) { @@ -238,6 +242,8 @@ var res = e.data.split(" "); //console.log(e.data) //console.log(res[0].substring(0,6)) + //console.log(res) + //console.log(res[0].slice(1)) switch (res[0].substring(0,6)) { diff --git a/webui/LJgrid.css b/webui/LJgrid.css index cb93f9c..32ccc0d 100644 --- a/webui/LJgrid.css +++ b/webui/LJgrid.css @@ -74,7 +74,7 @@ height: 400px; width: 400px; grid-template-columns: 66px 66px 66px 66px 66px 66px; - grid-template-rows: 30px 67px 67px 67px 30px; + grid-template-rows: 30px 67px 67px 67px 30px 30px; background-color: #000; justify-items: center; align-items: center; diff --git a/webui/index.html b/webui/index.html index 94a42ee..d229ac2 100644 --- a/webui/index.html +++ b/webui/index.html @@ -564,7 +564,7 @@
- +
@@ -730,11 +730,13 @@ -
+