More plugins, more doc,...
This commit is contained in:
parent
4a2d1a5773
commit
0bb0049f02
105 changed files with 15152 additions and 2757 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -24,33 +24,67 @@ import pdb
|
|||
from datetime import datetime
|
||||
from random import randrange
|
||||
import redis
|
||||
import lj3
|
||||
import sys,time,traceback
|
||||
import sys
|
||||
import ast
|
||||
import os
|
||||
|
||||
import time,traceback
|
||||
|
||||
|
||||
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
||||
|
||||
# import from shell
|
||||
|
||||
sys.path.append(ljpath +'/../../libs/')
|
||||
print(ljpath +'/../../libs/')
|
||||
#import from LJ
|
||||
sys.path.append(ljpath +'/libs/')
|
||||
print (ljpath +'/libs/')
|
||||
|
||||
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
else:
|
||||
from OSC3 import OSCServer, OSCClient, OSCMessage
|
||||
|
||||
import lj23 as lj3
|
||||
|
||||
'''
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
#from osc4py3 import oscmethod as osm
|
||||
from osc4py3.oscmethod import *
|
||||
'''
|
||||
|
||||
import argparse
|
||||
|
||||
# 0.25 : each frame will be repeated 4 times.
|
||||
animspeed = 0.25
|
||||
animspeed = 0.1
|
||||
|
||||
screen_size = [700,700]
|
||||
xy_center = [screen_size[0]/2,screen_size[1]/2]
|
||||
|
||||
message = "LO"
|
||||
message = "TEAMLASER"
|
||||
OSCinPort = 8011
|
||||
|
||||
ljclient = 0
|
||||
|
||||
idiotiaDisplay = [True,True,False,False]
|
||||
#idiotiaDisplay = [False,False,False,False]
|
||||
liveDisplay = [False,False,False,False]
|
||||
#liveDisplay = [False,False,False,False]
|
||||
|
||||
fieldsDisplay = [False,False,True,True]
|
||||
liveDisplay = [True, True, True, True]
|
||||
#fieldsDisplay = [True,True,True,True]
|
||||
idiotiaDisplay = [False, False, False, False]
|
||||
fieldsDisplay = [False, False, False, False]
|
||||
|
||||
|
||||
|
||||
'''
|
||||
fieldsDisplay = [False,False,True,True]
|
||||
'''
|
||||
|
||||
#idiotiaDisplay = [True,True,False,False]
|
||||
|
||||
currentIdiotia = 0
|
||||
|
||||
print ("")
|
||||
|
|
@ -97,10 +131,29 @@ else:
|
|||
if args.Lasers != None:
|
||||
LaserNumber = args.Lasers
|
||||
else:
|
||||
LaserNumber = 4
|
||||
LaserNumber = 1
|
||||
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
r = lj3.Config(redisIP,ljclient,"pose")
|
||||
|
||||
|
||||
#
|
||||
# OSC
|
||||
#
|
||||
|
||||
oscserver = OSCServer( (myIP, OSCinPort) )
|
||||
oscserver.timeout = 0
|
||||
#oscrun = True
|
||||
|
||||
# this method of reporting timeouts only works by convention
|
||||
# that before calling handle_request() field .timed_out is
|
||||
# set to False
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
||||
# funny python's way to add a method to an instance of a class
|
||||
import types
|
||||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
|
||||
|
|
@ -119,11 +172,14 @@ import json
|
|||
# Get frame number for pose path describe in PoseDir
|
||||
def lengthPOSE(pose_dir):
|
||||
|
||||
#if debug > 0:
|
||||
# print("Check directory",'poses/' + pose_dir)
|
||||
if os.path.exists('poses/' + pose_dir):
|
||||
numfiles = sum(1 for f in os.listdir('poses/' + pose_dir) if os.path.isfile(os.path.join('poses/' + pose_dir + '/', f)) and f[0] != '.')
|
||||
return numfiles
|
||||
if debug > 0:
|
||||
print("Checking directory",'plugins/VJing/poses/' + pose_dir)
|
||||
if os.path.exists('plugins/VJing/poses/' + pose_dir):
|
||||
|
||||
numfiles = sum(1 for f in os.listdir('plugins/VJing/poses/' + pose_dir) if os.path.isfile(os.path.join('plugins/VJing/poses/' + pose_dir + '/', f)) and f[0] != '.')
|
||||
if debug > 0:
|
||||
print(numfiles, 'frames')
|
||||
return numfiles
|
||||
else:
|
||||
if debug > 0:
|
||||
print("but it doesn't even exist!")
|
||||
|
|
@ -166,11 +222,108 @@ def prepareIdiotIA(currentAnim):
|
|||
anim[5] = lengthPOSE(anim[0])
|
||||
WebStatus("Checking "+ anim[0] +"...")
|
||||
if debug > 0:
|
||||
print('poses/' + anim[0], "length :", anim[5], "frames")
|
||||
print('plugins/VJing/poses/' + anim[0], "length :", anim[5], "frames")
|
||||
|
||||
print("Current IdiotIA anim is",anims[currentIdiotia][0],"("+str(currentIdiotia)+")")
|
||||
|
||||
|
||||
'''
|
||||
pose_keypoints_2d
|
||||
face_keypoints_2d
|
||||
hand_left_keypoints_2d
|
||||
hand_right_keypoints_2d
|
||||
pose_keypoints_3d
|
||||
face_keypoints_3d
|
||||
hand_left_keypoints_3d
|
||||
hand_right_keypoints_3d
|
||||
|
||||
"/0/face_keypoints_2d"
|
||||
"[-0.0946419, -0.521328, 0.675269, -0.0883931, -0.413923, 0.69358, -0.0758954, -0.302815, 0.73599, -0.059232, -0.191707, 0.640398, -0.0384026, -0.0917102, 0.683398, -0.00507569, -0.00652742, 0.643006, 0.0428318, 0.0601374, 0.558626, 0.0844904, 0.108284, 0.576597, 0.142813, 0.108284, 0.621916, 0.178223, 0.0749518, 0.546389, 0.207384, 0.0193979, 0.556877, 0.22613, -0.0361562, 0.660514, 0.244876, -0.102821, 0.713871, 0.267789, -0.1843, 0.706604, 0.290701, -0.265779, 0.680418, 0.307364, -0.347258, 0.617497, 0.31153, -0.428738, 0.53877, -0.0446514, -0.547253, 0.784288, -0.00715858, -0.569474, 0.873856, 0.0303342, -0.558364, 0.835336, 0.0740758, -0.543549, 0.827985, 0.111569, -0.525031, 0.809191, 0.213632, -0.543549, 0.819012, 0.242794, -0.569474, 0.884373, 0.265706, -0.5954, 0.842317, 0.292784, -0.613918, 0.804365, 0.313613, -0.625028, 0.740405, 0.163642, -0.443552, 0.805348, 0.169891, -0.362073, 0.837128, 0.169891, -0.280594, 0.839031, 0.174057, -0.213929, 0.68711, 0.111569, -0.162078, 0.725528, 0.134481, -0.154671, 0.837339, 0.159476, -0.150968, 0.887387, 0.178223, -0.158375, 0.835752, 0.196969, -0.180597, 0.698174, 0.00950491, -0.432441, 0.864517, 0.0345001, -0.458366, 0.859197, 0.0636612, -0.46207, 0.867471, 0.0907393, -0.432441, 0.852409, 0.0636612, -0.417627, 0.876186, 0.0324172, -0.413923, 0.834265, 0.21155, -0.454663, 0.875569, 0.232379, -0.491699, 0.816674, 0.26154, -0.50281, 0.878064, 0.282369, -0.476884, 0.839634, 0.263623, -0.450959, 0.912212, 0.24071, -0.450959, 0.896937, 0.0719929, -0.047267, 0.761505, 0.101154, -0.065785, 0.864081, 0.130315, -0.0694886, 0.910774, 0.159476, -0.065785, 0.895222, 0.17614, -0.0731922, 0.846551, 0.194886, -0.0731922, 0.74389, 0.209467, -0.0731922, 0.573107, 0.194886, -0.0213418, 0.677465, 0.17614, 0.0156941, 0.755373, 0.15531, 0.0231014, 0.765641, 0.124066, 0.0231014, 0.863117, 0.0928223, -0.00282377, 0.823042, 0.0928223, -0.0398598, 0.743914, 0.128232, -0.0361562, 0.932259, 0.157393, -0.0361562, 0.877732, 0.17614, -0.0398598, 0.853163, 0.196969, -0.0620813, 0.645926, 0.17614, -0.0398598, 0.80738, 0.157393, -0.0324526, 0.872388, 0.128232, -0.0361562, 0.924673, 0.0511636, -0.450959, 0.801577, 0.244876, -0.480588, 0.915322]"
|
||||
|
||||
"/peopleCount"
|
||||
"2"
|
||||
'''
|
||||
|
||||
def bodyREDIS(people):
|
||||
|
||||
dots = []
|
||||
pose = []
|
||||
redispose = []
|
||||
|
||||
pose_points = [10,9,8,1,11,12,13]
|
||||
print ("people body", people)
|
||||
|
||||
print ("/"+str(people)+"/pose_keypoints_2d")
|
||||
#pose = np.array(ast.literal_eval(r.get("/"+str(people)+"/pose_keypoints_2d")))
|
||||
redispose = r.get("/"+str(people)+"/pose_keypoints_2d")
|
||||
#print ("redispose",redispose)
|
||||
poseast = ast.literal_eval(redispose)
|
||||
#print ("poseast",poseast)
|
||||
#print (poseast[0])
|
||||
pose = np.array(poseast)
|
||||
#print (np.array((ast.literal_eval(strg))))
|
||||
#print pose
|
||||
#print(pose[0], pose[1])
|
||||
#print("len pose", len(pose))
|
||||
'''
|
||||
for dot in range(len(pose)/3):
|
||||
#print dot
|
||||
dots.append(((pose[dot * 3], pose[(dot * 3)+1])))
|
||||
#print((pose[dot * 3], pose[(dot * 3)+1]))
|
||||
'''
|
||||
for dot in range(len(pose_points)):
|
||||
bodypoint = pose_points[dot]
|
||||
if pose[bodypoint * 3] != -1 and pose[(bodypoint * 3)+1] != -1:
|
||||
|
||||
dots.append(((pose[bodypoint * 3], pose[(bodypoint * 3)+1])))
|
||||
#print((pose[dot * 3], pose[(dot * 3)+1]))
|
||||
#print "body point ", pose_points[dot],dot, (pose[bodypoint * 3], pose[(bodypoint * 3)+1])
|
||||
print dots
|
||||
return dots
|
||||
|
||||
# display the Realtime open pose face according to flag.
|
||||
def LivePose():
|
||||
|
||||
|
||||
laser = 0
|
||||
# Old style : if display flag is True for given laser, send the face points.
|
||||
# New style : should send the people points in a PL, then use the PL's dest object to describe
|
||||
# what to do with it
|
||||
|
||||
if liveDisplay[0]:
|
||||
peoplenumber = int(r.get("/peopleCount"))
|
||||
print peoplenumber
|
||||
for currentnumber in range(peoplenumber):
|
||||
PL = 0
|
||||
#print PL, anim
|
||||
# Draw Pose
|
||||
|
||||
x_offset = 26 * (- (0.9*peoplenumber) + 3*currentnumber)
|
||||
for people in range(peoplenumber):
|
||||
|
||||
print("people", people)
|
||||
x_offset = 26 * (- (0.9*peoplenumber) + 3*currentnumber)
|
||||
print x_offset
|
||||
lj3.rPolyLineOneColor(bodyREDIS(people), c= white, PL = PL, closed = False, xpos = xy_center[0]+ x_offset, ypos = xy_center[1], resize = 250)
|
||||
|
||||
lj3.DrawPL(PL)
|
||||
|
||||
|
||||
|
||||
# get relative (-1 0 1) body position points. a position -1, -1 means doesn't exist
|
||||
def getBODY(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
#print pose_points
|
||||
if len(pose_json['people'][people]['pose_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][people]['pose_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][people]['pose_keypoints_2d'][dot * 3], pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1]))
|
||||
|
||||
|
||||
return dots
|
||||
|
||||
# get absolute face position points
|
||||
def getFACE(pose_json,pose_points, people):
|
||||
|
||||
|
|
@ -185,6 +338,21 @@ def getFACE(pose_json,pose_points, people):
|
|||
return dots
|
||||
|
||||
|
||||
|
||||
# Body parts
|
||||
def bodyCOCO(pose_json, people):
|
||||
pose_points = [10,9,8,1,11,12,13]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def armCOCO(pose_json, people):
|
||||
pose_points = [7,6,5,1,2,3,4]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def headCOCO(pose_json, people):
|
||||
pose_points = [1,0]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
|
||||
# Face keypoints
|
||||
def face(pose_json, people):
|
||||
pose_points = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
|
||||
|
|
@ -239,22 +407,20 @@ def IdiotIA():
|
|||
|
||||
anim = anims[currentIdiotia]
|
||||
#print(anim)
|
||||
|
||||
PL = laser
|
||||
#print PL, anim
|
||||
|
||||
dots = []
|
||||
|
||||
# increase current frame [4] of speed [7] frames
|
||||
#print(anim[4],anim[7],anim[4]+anim[7])
|
||||
|
||||
# print(anim[4],anim[7],anim[4]+anim[7])
|
||||
# print("frame", anim[4])
|
||||
anim[4] = anim[4]+anim[7]
|
||||
|
||||
# print("animspeed",anim[7], "newframe", anim[4], "maximum frame", anim[5] )
|
||||
# compare to total frame [5]
|
||||
if anim[4] >= anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%int(anim[4]))+'.json'
|
||||
posename = 'plugins/VJing/poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%int(anim[4]))+'.json'
|
||||
# print(posename)
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
|
@ -421,12 +587,47 @@ def Starfield(hori=0,verti=0):
|
|||
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]:
|
||||
print ("laser", laser)
|
||||
|
||||
# if display flag is True, send the face points.
|
||||
if liveDisplay[laser]:
|
||||
|
||||
PL = laser
|
||||
#print PL, anim
|
||||
dots = []
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
# Draw Face
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
|
||||
r.get(n)
|
||||
lj3.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(headCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, 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)
|
||||
|
||||
|
||||
# if display flag is True, send the face points.
|
||||
if liveDisplay[laser]:
|
||||
|
|
@ -435,18 +636,20 @@ def LiveFace():
|
|||
|
||||
|
||||
# /pose/idiotia/lasernumber 1
|
||||
def OSCidiotia(address, value):
|
||||
def OSCidiotia(path, tags, args, source):
|
||||
|
||||
print("pose idiotia got ",address,value)
|
||||
laser = int(address[14:])
|
||||
print("laser", laser, value)
|
||||
print("pose idiotia got",path, args)
|
||||
laser = int(args[0])
|
||||
value = int(args[1])
|
||||
|
||||
if value == "1" or value == 1:
|
||||
|
||||
if value == 1:
|
||||
|
||||
print("switch on idiotia for laser", laser, value)
|
||||
idiotiaDisplay[laser] = True
|
||||
liveDisplay[laser] = False
|
||||
fieldsDisplay[laser] = False
|
||||
print(idiotiaDisplay,liveDisplay,fieldsDisplay)
|
||||
#print(idiotiaDisplay,liveDisplay,fieldsDisplay)
|
||||
|
||||
else:
|
||||
|
||||
|
|
@ -455,58 +658,65 @@ def OSCidiotia(address, value):
|
|||
|
||||
UpdatePoseUI()
|
||||
|
||||
# /pose/anim/animnumber 1
|
||||
def OSCanim(address, value):
|
||||
global currentIdiotia
|
||||
|
||||
print("pose anim got :", address, type(value), value)
|
||||
anim = int(address[11:])
|
||||
print("anim", anim)
|
||||
|
||||
if value == "1" or value == 1:
|
||||
|
||||
# /pose/anim
|
||||
def OSCanim(path, tags, args, source):
|
||||
|
||||
print("pose anim got",path, args)
|
||||
anim = int(args[0])
|
||||
state = int(args[1])
|
||||
|
||||
#print(anim, state)
|
||||
|
||||
if state == 1:
|
||||
print("/pose/anim switch to",anim)
|
||||
currentIdiotia = anim
|
||||
UpdatePoseUI()
|
||||
WebStatus("Running "+ anims[currentIdiotia][0]+"...")
|
||||
WebStatus("Ruuning "+ anims[currentIdiotia][0]+"...")
|
||||
|
||||
|
||||
# /pose/live/lasernumber value
|
||||
def OSClive(address, value):
|
||||
def OSClive(path, tags, args, source):
|
||||
|
||||
print("live",address,value)
|
||||
laser = int(address[11:])
|
||||
#print("laser", laser, value)
|
||||
print("pose live got",path, args)
|
||||
laser = int(args[0])
|
||||
value = int(args[1])
|
||||
|
||||
if value == "1" or value == 1:
|
||||
idiotiaDisplay[laser] = False
|
||||
liveDisplay[laser] = True
|
||||
fieldsDisplay[laser] = False
|
||||
|
||||
if value == "1":
|
||||
print("live for laser", laser)
|
||||
idiotiaDisplay[value] = False
|
||||
liveDisplay[value] = True
|
||||
fieldsDisplay[value] = False
|
||||
UpdatePoseUI()
|
||||
|
||||
# /pose/field/lasernumber value
|
||||
def OSCfield(address, value):
|
||||
def OSCfield(path, tags, args, source):
|
||||
|
||||
print("Pose field got", address, "with value", type(value), value)
|
||||
laser = int(address[12:])
|
||||
#print("laser", laser, value)
|
||||
print("pose field got",path, args)
|
||||
laser = int(args[0])
|
||||
value = int(args[1])
|
||||
|
||||
if value == "1" or value == 1:
|
||||
print("field",laser,"true")
|
||||
idiotiaDisplay[laser] = False
|
||||
liveDisplay[laser] = False
|
||||
fieldsDisplay[laser] = True
|
||||
|
||||
if value == "1":
|
||||
print("field for laser", laser)
|
||||
idiotiaDisplay[value] = False
|
||||
liveDisplay[value] = False
|
||||
fieldsDisplay[value] = True
|
||||
UpdatePoseUI()
|
||||
|
||||
|
||||
# /pose/ljclient
|
||||
def OSCljclient(value):
|
||||
print("Pose bank got /pose/ljclient with value", value)
|
||||
ljclient = value
|
||||
lj3.LjClient(ljclient)
|
||||
def OSCljclient(path, tags, args, source):
|
||||
|
||||
print("pose got /viewgen/ljclient with value", args[0])
|
||||
lj.WebStatus("viewgen to virtual "+ str(args[0]))
|
||||
ljclient = args[0]
|
||||
lj.LjClient(ljclient)
|
||||
|
||||
|
||||
|
||||
# /pose/ping value
|
||||
def OSCping(value):
|
||||
lj3.OSCping("pose")
|
||||
|
||||
'''
|
||||
# Starfield, idiotia
|
||||
|
|
@ -515,7 +725,7 @@ def OSCrun(value):
|
|||
print("Pose bank got /run with value", value)
|
||||
doit = value
|
||||
'''
|
||||
|
||||
'''
|
||||
# /quit
|
||||
def OSCquit():
|
||||
|
||||
|
|
@ -523,6 +733,7 @@ def OSCquit():
|
|||
print("Stopping OSC...")
|
||||
lj3.OSCstop()
|
||||
sys.exit()
|
||||
'''
|
||||
|
||||
def WebStatus(message):
|
||||
lj3.SendLJ("/status",message)
|
||||
|
|
@ -561,20 +772,13 @@ def UpdatePoseUI():
|
|||
print('Loading Pose bank...')
|
||||
WebStatus("Loading Pose bank...")
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Starting OSC server at", myIP, ":", OSCinPort, "...")
|
||||
osc_startup()
|
||||
osc_udp_server(myIP, OSCinPort, "InPort")
|
||||
|
||||
#osc_method("/pose/run*", OSCrun)
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/pose/ljclient", OSCljclient)
|
||||
osc_method("/quit", OSCquit)
|
||||
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)
|
||||
|
||||
oscserver.addMsgHandler("/pose/ljclient", OSCljclient)
|
||||
oscserver.addMsgHandler("/pose/idiotia", OSCidiotia)
|
||||
oscserver.addMsgHandler("/pose/field", OSCfield)
|
||||
oscserver.addMsgHandler("/pose/live", OSClive)
|
||||
oscserver.addMsgHandler("/pose/anim", OSCanim)
|
||||
# Add OSC generic plugins commands : 'default", /ping, /quit, /pluginame/obj, /pluginame/var, /pluginame/adddest, /pluginame/deldest
|
||||
lj3.addOSCdefaults(oscserver)
|
||||
|
||||
anims =[[]]*19
|
||||
|
||||
|
|
@ -593,21 +797,22 @@ green = lj3.rgb2int(0,255,0)
|
|||
print("Updating Pose UI...")
|
||||
UpdatePoseUI()
|
||||
|
||||
WebStatus("Running "+ anims[currentIdiotia][0]+"...")
|
||||
WebStatus("Pose "+ anims[currentIdiotia][0]+".")
|
||||
#WebStatus("Pose bank running.")
|
||||
#print("Pose bank running")
|
||||
print("Running "+ anims[currentIdiotia][0]+" on " + str(LaserNumber) +" lasers.")
|
||||
print("Pose "+ anims[currentIdiotia][0]+" ready on " + str(LaserNumber) +" lasers.")
|
||||
|
||||
def Run():
|
||||
|
||||
try:
|
||||
while 1:
|
||||
while lj3.oscrun:
|
||||
|
||||
lj3.OSCframe()
|
||||
# If you want an idea
|
||||
# t0 = time.time()
|
||||
Starfield(hori=0,verti=0)
|
||||
IdiotIA()
|
||||
lj3.OSCframe()
|
||||
#Starfield(hori=0,verti=0)
|
||||
#IdiotIA()
|
||||
LivePose()
|
||||
#LiveFace()
|
||||
time.sleep(0.002)
|
||||
#t1 = time.time()
|
||||
|
|
|
|||
|
|
@ -1,647 +0,0 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
|
||||
lj3 v0.8.1
|
||||
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
|
||||
OSC functions commented, waiting working on OSC in python3
|
||||
|
||||
Config(redisIP, client number)
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
|
||||
Text(word, color, PL, xpos, ypos, resize, rotx, roty, rotz) : Display a word
|
||||
SendLJ(adress,message) : LJ remote control. See commands.py
|
||||
WebStatus(message) : display message on webui
|
||||
DrawPL(point list number) : once you stacked all wanted elements, like 2 polylines, send them to lasers.
|
||||
rgb2int(r,g,b)
|
||||
LjClient(client): Change Client number in redis keys
|
||||
LjPl(pl): Change pl number in redis keys = laser target.
|
||||
|
||||
|
||||
OSCstart(): Start the OSC system.
|
||||
OSCframe(): Handle incoming OSC message. Calling the right callback
|
||||
OSCstop(): Properly close the OSC system
|
||||
OSCping(value): Answer to LJ pings by sending /pong value
|
||||
OSCquit(name): Exit calling script using name in terminal
|
||||
|
||||
setup_controls(joystick)
|
||||
|
||||
XboxController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
Ps3Controller : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger, getUp, getDown, getLeft, getRight, getFire1, getFire2(self):
|
||||
MySaitekController : getLeftHori,getLeftVert, getRightHori,getRightVert, getLeftTrigger,getRightTrigger
|
||||
MyThrustController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
CSLController : getLeftHori,getLeftVert,getRightHori, getRightVert,getLeftTrigger,getRightTrigger,getFire1,getFire2
|
||||
my USB Joystick : getUp,getDown,getLeft,getRight,etLeftTrigger, getRightTrigger,getFire1, getFire2
|
||||
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
|
||||
# Import needed modules from osc4py3
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
#from osc4py3 import oscmethod as osm
|
||||
from osc4py3.oscmethod import *
|
||||
|
||||
|
||||
#redisIP = '127.0.0.1'
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
ClientNumber = 0
|
||||
|
||||
point_list = []
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
#
|
||||
# OSC interaction with LJ
|
||||
#
|
||||
|
||||
def OSCstart():
|
||||
# Start the system.
|
||||
osc_startup()
|
||||
#osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
def OSCframe():
|
||||
#print("OSCprocess")
|
||||
osc_process()
|
||||
|
||||
# Properly close the system. Todo
|
||||
def OSCstop():
|
||||
osc_terminate()
|
||||
|
||||
|
||||
def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
# print(msg)
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
except:
|
||||
print ('Connection to LJ refused : died ?')
|
||||
pass
|
||||
|
||||
def WebStatus(message):
|
||||
SendLJ("/status", message)
|
||||
|
||||
|
||||
# Answer to LJ pings
|
||||
def OSCping(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Got /ping with value", value)
|
||||
SendLJ("/pong",value)
|
||||
|
||||
|
||||
# /quit
|
||||
def OSCquit(name):
|
||||
|
||||
WebStatus(name + " quit.")
|
||||
print("Stopping OSC...")
|
||||
|
||||
OSCstop()
|
||||
sys.exit()
|
||||
|
||||
'''
|
||||
def handlerfunction(s, x, y):
|
||||
# Will receive message data unpacked in s, x, y
|
||||
pass
|
||||
|
||||
def handlerfunction2(address, s, x, y):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
pass
|
||||
|
||||
# Make server channels to receive packets.
|
||||
osc_udp_server("127.0.0.1", 3721, "localhost")
|
||||
osc_udp_server("0.0.0.0", 3724, "anotherserver")
|
||||
'''
|
||||
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
||||
# caracteres corrects
|
||||
|
||||
[(-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
|
||||
|
||||
# caracteres 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)], #@
|
||||
|
||||
# Caracteres corrects
|
||||
|
||||
|
||||
[(-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 rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
|
||||
def Config(redisIP,client):
|
||||
global ClientNumber, r
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
ClientNumber = client
|
||||
osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
return r
|
||||
|
||||
|
||||
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 = rotx * math.pi / 180
|
||||
cosaX = math.cos(rad)
|
||||
sinaX = math.sin(rad)
|
||||
|
||||
y2 = y
|
||||
y = y2 * cosaX - z * sinaX
|
||||
z = y2 * sinaX + z * cosaX
|
||||
|
||||
rad = roty * math.pi / 180
|
||||
cosaY = math.cos(rad)
|
||||
sinaY = math.sin(rad)
|
||||
|
||||
z2 = z
|
||||
z = z2 * cosaY - x * sinaY
|
||||
x = z2 * sinaY + x * cosaY
|
||||
|
||||
rad = rotz * math.pi / 180
|
||||
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:
|
||||
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)
|
||||
#print i,x_offset
|
||||
# if digit
|
||||
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)
|
||||
#print ("laser",PL,"message",message)
|
||||
#dots.append(char_draw)
|
||||
|
||||
|
||||
|
||||
import re
|
||||
|
||||
def setup_controls(joystick):
|
||||
"""
|
||||
Joystick wrapper.
|
||||
"""
|
||||
if re.search('playstation', joystick.get_name(), re.I):
|
||||
return Ps3Controller(joystick)
|
||||
|
||||
elif re.search('X-box', joystick.get_name(), re.I):
|
||||
return XboxController(joystick)
|
||||
|
||||
elif re.search('Saitek', joystick.get_name(), re.I):
|
||||
return MySaitekController(joystick)
|
||||
|
||||
elif re.search('Thrustmaster dual analog 3.2', joystick.get_name(), re.I):
|
||||
return MyThrustController(joystick)
|
||||
|
||||
elif re.search('2n1 USB', joystick.get_name(), re.I):
|
||||
return CSLController(joystick)
|
||||
|
||||
elif re.search('Joystick', joystick.get_name(), re.I):
|
||||
return USBController(joystick)
|
||||
|
||||
return Controller(joystick)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self, joystick):
|
||||
"""Pass a PyGame joystick instance."""
|
||||
self.js = joystick
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
class XboxController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(XboxController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(4)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(11)
|
||||
|
||||
class Ps3Controller(Controller):
|
||||
|
||||
#up 4 _DOWN 6 left 7 right 5 croix 14 rond 13 triangle 12
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(Ps3Controller, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(8)
|
||||
|
||||
def getRightTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getUp(self):
|
||||
return self.js.get_button(4)
|
||||
|
||||
def getDown(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getLeft(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getRight(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(14)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(13)
|
||||
|
||||
|
||||
class MySaitekController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MySaitekController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
class MyThrustController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MyThrustController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
|
||||
class CSLController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(CSLController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(1)
|
||||
|
||||
class USBController(Controller):
|
||||
|
||||
|
||||
# my USB Joystick
|
||||
#up axis 0 -1 DOWN axis 0 1 left axis 1 1 right axis 1 -1 bouton gauche 10 bouton droite 9
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(USBController, self).__init__(joystick)
|
||||
|
||||
|
||||
def getUp(self):
|
||||
if self.js.get_axis(0) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getDown(self):
|
||||
if self.js.get_axis(0) > 0.9:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeft(self):
|
||||
if self.js.get_axis(1) == 1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getRight(self):
|
||||
if self.js.get_axis(1) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getFire1(self):
|
||||
if self.js.get_button(10) == 1:
|
||||
print ("fire 1")
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getFire2(self):
|
||||
if self.js.get_button(9) == 1:
|
||||
print ("fire 2")
|
||||
return self.js.get_button(9)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ BALL_MAX = 4
|
|||
BALL_SIZE_X = 3
|
||||
BALL_SIZE_Y = 3
|
||||
LASER_ANGLE = 0
|
||||
|
||||
plnumber = 0
|
||||
|
||||
|
||||
GRAVITY = 0.0001
|
||||
|
|
@ -122,6 +122,7 @@ def LogoDraw(plnumber):
|
|||
for xy in pl_color[0]:
|
||||
xy_list.append((LOGO_OFFSET_X + xy[0], LOGO_OFFSET_Y + xy[1]))
|
||||
#print xy_list
|
||||
#print plnumber
|
||||
lj.PolyLineOneColor(xy_list, c, plnumber, False)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,322 +0,0 @@
|
|||
# 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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,6 +14,9 @@ import itertools
|
|||
import sys
|
||||
import os
|
||||
import types
|
||||
sys.path.append('../../../libs')
|
||||
import lj
|
||||
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
|
|
@ -26,7 +29,7 @@ else:
|
|||
import thread
|
||||
import time
|
||||
import random
|
||||
import lj
|
||||
import lj23 as lj
|
||||
import entities
|
||||
from controller import setup_controls
|
||||
import argparse
|
||||
|
|
@ -116,13 +119,15 @@ if args.laser:
|
|||
else:
|
||||
plnumber = 0
|
||||
|
||||
entities.plnumber = plnumber
|
||||
|
||||
# Redis Computer IP
|
||||
if args.redisIP != None:
|
||||
redisIP = args.redisIP
|
||||
else:
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
lj.Config(redisIP,ljclient)
|
||||
lj.Config(redisIP,ljclient,"ljpong")
|
||||
|
||||
|
||||
def StartPlaying(first_time = False):
|
||||
|
|
@ -209,24 +214,26 @@ OSCRunning = True
|
|||
def OSCljclient(path, tags, args, source):
|
||||
|
||||
|
||||
print("LJ Pong got /ljpong/ljclient with value", args[0])
|
||||
print("LJPong got /ljpong/ljclient with value", args[0])
|
||||
lj.WebStatus("LJPong to virtual "+ str(args[0]))
|
||||
ljclient = args[0]
|
||||
lj.LjClient(ljclient)
|
||||
|
||||
def OSCpl(path, tags, args, source):
|
||||
global plnumber
|
||||
|
||||
print("LJ Pong got /ljpong/pl with value", args[0])
|
||||
lj.WebStatus("LJPong to pl "+ str(args[0]))
|
||||
plnumber = args[0]
|
||||
|
||||
plnumber = int(args[0])
|
||||
lj.LjPl(plnumber)
|
||||
'''
|
||||
# /ping
|
||||
def OSCping(path, tags, args, source):
|
||||
|
||||
print("LJ Pong got /ping")
|
||||
lj.SendLJ("/pong","ljpong")
|
||||
lj.SendLJ("/ljpong/start",1)
|
||||
|
||||
'''
|
||||
|
||||
def OSC_frame():
|
||||
# clear timed_out flag
|
||||
|
|
@ -246,10 +253,10 @@ print "at", OSCIP, "port",str(OSCPort)
|
|||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
# OSC callbacks
|
||||
|
||||
lj.addOSCdefaults(oscserver)
|
||||
oscserver.addMsgHandler( "/ljpong/ljclient", OSCljclient )
|
||||
oscserver.addMsgHandler("/ljpong/pl", OSCpl)
|
||||
oscserver.addMsgHandler("/ping", OSCping)
|
||||
#oscserver.addMsgHandler("/ping", lj.OSCping)
|
||||
|
||||
print "Running..."
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +1,55 @@
|
|||
# coding=UTF-8
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
|
||||
'''
|
||||
|
||||
Laserglyph
|
||||
v0.1.0
|
||||
|
||||
Anaglyphed rotating cube (for red and green glasses)
|
||||
|
||||
This client uses the drawing functions (polyline) provided by LJ in lj.py
|
||||
You must check in lj.py if the redis server IP is correct.
|
||||
|
||||
LICENCE : CC
|
||||
'''
|
||||
|
||||
by Sam Neurohack
|
||||
|
||||
|
||||
'''
|
||||
import sys
|
||||
import os
|
||||
print()
|
||||
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
||||
|
||||
# import from shell
|
||||
|
||||
sys.path.append(ljpath +'/../libs/')
|
||||
|
||||
#import from LJ
|
||||
sys.path.append(ljpath +'/libs/')
|
||||
print (ljpath+'/../libs/')
|
||||
|
||||
import lj23 as lj
|
||||
|
||||
from OSC3 import OSCServer, OSCClient, OSCMessage
|
||||
import redis
|
||||
import lj3
|
||||
import math
|
||||
import time
|
||||
import argparse
|
||||
|
||||
'''
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
#from osc4py3 import oscmethod as osm
|
||||
from osc4py3.oscmethod import *
|
||||
'''
|
||||
|
||||
OSCinPort = 8004
|
||||
myIP = "192.168.2.52"
|
||||
oscrun = True
|
||||
# myIP = "127.0.0.1"
|
||||
PL = 0
|
||||
|
||||
print ("")
|
||||
print ("Arguments parsing if needed...")
|
||||
|
|
@ -59,7 +87,7 @@ if args.myIP != None:
|
|||
else:
|
||||
myIP = '127.0.0.1'
|
||||
|
||||
print("redisIP",redisIP)
|
||||
print("myIP",myIP)
|
||||
|
||||
if args.verbose:
|
||||
debug = args.verbose
|
||||
|
|
@ -67,8 +95,12 @@ else:
|
|||
debug = 0
|
||||
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
lj.Config(redisIP,ljclient,"glyph")
|
||||
|
||||
white = lj.rgb2int(255,255,255)
|
||||
red = lj.rgb2int(255,0,0)
|
||||
blue = lj.rgb2int(0,0,255)
|
||||
green = lj.rgb2int(0,255,0)
|
||||
|
||||
width = 800
|
||||
height = 600
|
||||
|
|
@ -87,7 +119,7 @@ observer_altitude = 30000
|
|||
#observer_altitude = 10000
|
||||
# elevation = z coordinate
|
||||
# 0.0, -2000 pop out
|
||||
map_plane_altitude = 0.0
|
||||
map_plane_altitude = 0.0
|
||||
|
||||
# Cube coordinates
|
||||
# Define the vertices that compose each of the 6 faces.
|
||||
|
|
@ -101,9 +133,29 @@ vertices = [
|
|||
( 1.0,- 1.0, 1.0),
|
||||
(- 1.0,- 1.0, 1.0)
|
||||
]
|
||||
faces = [(0,1,2,3),(0,4,5,1),(1,5,6,2),(2,3,7,6),(6,5,4,7),(7,3,0,4)]
|
||||
#faces = [(0,1,2,3),(0,4,5,1),(1,5,6,2),(2,3,7,6),(6,5,4,7),(7,3,0,4)]
|
||||
faces = [(0,1,2,3),(0,4,5,1),(1,5,6,2),(2,3,7,6),(7,3,0,4),(7,3,0,4)]
|
||||
# name, intensity, active, xy, color, red, green, blue, PL , closed):
|
||||
Leftcube = lj.FixedObject('Leftcube', True, 255, [], red, 255, 0, 0, PL , True)
|
||||
Rightcube = lj.FixedObject('Rightcube', True, 255, [], green, 0, 255, 0, PL , True)
|
||||
|
||||
# 'Destination' for each PL
|
||||
# name, number, active, PL , scene, laser
|
||||
# PL 0
|
||||
Dest0 = lj.DestObject('0', 0, True, 0 , 0, 0)
|
||||
Dest1 = lj.DestObject('1', 1, True, 0 , 1, 1)
|
||||
|
||||
'''
|
||||
viewgen3Lasers = [True,False,False,False]
|
||||
# Add here, one by one, as much destination as you want for each PL.
|
||||
# LJ and OSC can remotely add/delete destinations here.
|
||||
|
||||
lj.Dests = {
|
||||
"0": {"PL": 0, "scene": 0, "laser": 0},
|
||||
"1": {"PL": 0, "scene": 1, "laser": 1}
|
||||
}
|
||||
|
||||
'''
|
||||
|
||||
def LeftShift(elevation):
|
||||
|
||||
|
|
@ -115,29 +167,36 @@ def RightShift(elevation):
|
|||
diff = map_plane_altitude - elevation
|
||||
return (1 - nadir) * eye_spacing * diff / (observer_altitude - elevation)
|
||||
|
||||
# If you want to use rgb for color :
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
|
||||
def OSCljclient(value):
|
||||
# OSC
|
||||
#
|
||||
|
||||
print("Glyph got /glyph/ljclient with value", value)
|
||||
lj3.WebStatus("Glyph to virtual "+ str(value))
|
||||
ljclient = value
|
||||
lj3.LjClient(ljclient)
|
||||
oscserver = OSCServer( (myIP, OSCinPort) )
|
||||
oscserver.timeout = 0
|
||||
#oscrun = True
|
||||
|
||||
def OSCpl(value):
|
||||
# this method of reporting timeouts only works by convention
|
||||
# that before calling handle_request() field .timed_out is
|
||||
# set to False
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
||||
print("Glyph got /glyph/pl with value", value)
|
||||
lj3.WebStatus("Glyph to pl "+ str(value))
|
||||
lj3.LjPl(value)
|
||||
# funny python's way to add a method to an instance of a class
|
||||
import types
|
||||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
# OSC callbacks
|
||||
|
||||
# /viewgen/ljclient
|
||||
def OSCljclient(path, tags, args, source):
|
||||
|
||||
print("Got /viewgen/ljclient with value", args[0])
|
||||
lj.WebStatus("viewgen to virtual "+ str(args[0]))
|
||||
ljclient = args[0]
|
||||
lj.LjClient(ljclient)
|
||||
|
||||
# /pose/ping value
|
||||
def OSCping(value):
|
||||
lj3.OSCping("glyph")
|
||||
|
||||
'''
|
||||
def Proj(x,y,z,angleX,angleY,angleZ):
|
||||
|
||||
rad = angleX * math.pi / 180
|
||||
|
|
@ -174,18 +233,28 @@ def Run():
|
|||
Left = []
|
||||
Right = []
|
||||
counter =0
|
||||
lj3.WebStatus("LaserGlyph")
|
||||
lj.WebStatus("LaserGlyph")
|
||||
lj.SendLJ("/glyph/start 1")
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Starting OSC at",myIP," port",OSCinPort,"...")
|
||||
print("Starting OSC server at",myIP," port",OSCinPort,"...")
|
||||
'''
|
||||
osc_startup()
|
||||
osc_udp_server(myIP, OSCinPort, "InPort")
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/ping", lj.OSCping)
|
||||
osc_method("/quit*", quit)
|
||||
osc_method("/glyph/ljclient", OSCljclient)
|
||||
'''
|
||||
oscserver.addMsgHandler( "/glyph/ljclient", OSCljclient )
|
||||
|
||||
# Add OSC generic plugins commands : 'default", /ping, /quit, /pluginame/obj, /pluginame/var, /pluginame/adddest, /pluginame/deldest
|
||||
lj.addOSCdefaults(oscserver)
|
||||
|
||||
try:
|
||||
|
||||
while 1:
|
||||
while lj.oscrun:
|
||||
|
||||
lj.OSCframe()
|
||||
Left = []
|
||||
Right = []
|
||||
|
||||
|
|
@ -216,24 +285,31 @@ def Run():
|
|||
# Drawing step, 2 possibilities
|
||||
|
||||
# Red and Green drawn by laser 0
|
||||
lj3.PolyLineOneColor(Left, c = red, PL = 0, closed = True)
|
||||
lj3.PolyLineOneColor(Right, c = green, PL = 0, closed = True)
|
||||
lj3.DrawPL(0)
|
||||
#lj.PolyLineOneColor(Left, c = red, PL = PL, closed = True)
|
||||
#lj.PolyLineOneColor(Right, c = green, PL = PL, closed = True)
|
||||
|
||||
lj.PolyLineOneColor(Left, c = Leftcube.color , PL = Leftcube.PL, closed = Leftcube.closed)
|
||||
lj.PolyLineOneColor(Right, c = Rightcube.color , PL = Rightcube.PL, closed = Rightcube.closed)
|
||||
#print(len(Left))
|
||||
|
||||
#lj.DrawPL(PL)
|
||||
#print(Dest0.name, Dest1.name)
|
||||
lj.DrawDests()
|
||||
|
||||
'''
|
||||
# Red on laser 1 and green on laser 2
|
||||
lj3.PolyLineOneColor(Left, c = red, PL = 1, closed = True)
|
||||
lj3.PolyLineOneColor(Right, c = green, PL = 2, closed = True)
|
||||
lj3.DrawPL(1)
|
||||
lj3.DrawPL(2)
|
||||
lj.PolyLineOneColor(Left, c = red, PL = 1, closed = True)
|
||||
lj.PolyLineOneColor(Right, c = green, PL = 2, closed = True)
|
||||
lj.DrawPL(1)
|
||||
lj.DrawPL(2)
|
||||
|
||||
'''
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
counter += 1
|
||||
if counter >360:
|
||||
counter =0
|
||||
if counter > 360:
|
||||
counter = 0
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
|
@ -242,18 +318,7 @@ def Run():
|
|||
|
||||
finally:
|
||||
|
||||
lj3.WebStatus("Glyph Exit")
|
||||
print("Stopping OSC...")
|
||||
lj3.OSCstop()
|
||||
pass
|
||||
|
||||
print ("LaserGlyph Stopped.")
|
||||
|
||||
|
||||
white = rgb2int(255,255,255)
|
||||
red = rgb2int(255,0,0)
|
||||
blue = rgb2int(0,0,255)
|
||||
green = rgb2int(0,255,0)
|
||||
lj.ClosePlugin()
|
||||
|
||||
|
||||
Run()
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ LICENCE : CC
|
|||
'''
|
||||
|
||||
import redis
|
||||
import lj3
|
||||
|
||||
import sys,time
|
||||
import argparse
|
||||
sys.path.append('../libs')
|
||||
import lj3
|
||||
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
|
|
@ -20,11 +22,12 @@ myIP = "127.0.0.1"
|
|||
duration = 300
|
||||
|
||||
OSCinPort = 8006
|
||||
oscrun = True
|
||||
|
||||
Word0 = "LASER"
|
||||
Word1 = "LASER"
|
||||
Word2 = "LASER"
|
||||
Word3 = "LASER"
|
||||
Word0 = "ONE"
|
||||
Word1 = "TWO"
|
||||
Word2 = "THREE"
|
||||
Word3 = "FOUR"
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
|
|
@ -67,7 +70,7 @@ else:
|
|||
debug = 0
|
||||
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
lj3.Config(redisIP,ljclient,"words")
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
|
||||
|
|
@ -108,17 +111,15 @@ def OSCljclient(value):
|
|||
|
||||
|
||||
|
||||
# /ping
|
||||
def OSCping():
|
||||
|
||||
lj3.OSCping("words")
|
||||
lj3.SendLJ("words/text/0",Word0)
|
||||
lj3.SendLJ("words/text/1",Word1)
|
||||
# /quit dummyvalue
|
||||
def quit(value):
|
||||
# don't do this at home (or it'll quit blender)
|
||||
global oscrun
|
||||
|
||||
# /quit
|
||||
def OSCquit():
|
||||
|
||||
lj3.OSCquit("words")
|
||||
oscrun = False
|
||||
print("Stopped by /quit.")
|
||||
lj3.ClosePlugin()
|
||||
|
||||
|
||||
def Run():
|
||||
|
|
@ -131,9 +132,9 @@ def Run():
|
|||
osc_method("/words/text/1*", OSCword1)
|
||||
osc_method("/words/text/2*", OSCword2)
|
||||
osc_method("/words/text/3*", OSCword3)
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/words/ljclient*", OSCljclient)
|
||||
osc_method("/quit", OSCquit)
|
||||
osc_method("/ping", lj3.OSCping)
|
||||
osc_method("/quit*", quit)
|
||||
|
||||
color = lj3.rgb2int(255,255,255)
|
||||
lj3.WebStatus("Loading Words...")
|
||||
|
|
@ -145,7 +146,7 @@ def Run():
|
|||
|
||||
try:
|
||||
|
||||
while 1:
|
||||
while oscrun:
|
||||
|
||||
lj3.OSCframe()
|
||||
|
||||
|
|
@ -170,11 +171,8 @@ def Run():
|
|||
|
||||
finally:
|
||||
|
||||
lj3.WebStatus("Words Exit")
|
||||
print("Stopping Words OSC...")
|
||||
lj3.OSCstop()
|
||||
lj3.ClosePlugin()
|
||||
|
||||
print ("Words Stopped.")
|
||||
|
||||
|
||||
Run()
|
||||
|
|
|
|||
241
plugins/livewords3.py
Normal file
241
plugins/livewords3.py
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
Live words on different lasers
|
||||
LICENCE : CC
|
||||
'''
|
||||
|
||||
import redis
|
||||
|
||||
import sys,time
|
||||
import argparse
|
||||
|
||||
import os
|
||||
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
||||
# import from shell
|
||||
sys.path.append('../libs')
|
||||
|
||||
#import from LJ
|
||||
sys.path.append(ljpath +'/libs/')
|
||||
#print (ljpath+'/libs')
|
||||
import lj23 as lj
|
||||
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
print ("Importing lj23 and OSC from libs...")
|
||||
else:
|
||||
from OSC3 import OSCServer, OSCClient, OSCMessage
|
||||
print ("Importing lj23 and OSC3 from libs...")
|
||||
|
||||
myIP = "127.0.0.1"
|
||||
|
||||
duration = 300
|
||||
|
||||
OSCinPort = 8006
|
||||
oscrun = True
|
||||
|
||||
Word0 = "BRAINFUCK"
|
||||
Word1 = "D"
|
||||
Word2 = "CAPTCHA"
|
||||
Word3 = "D"
|
||||
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
from Queue import Queue
|
||||
else:
|
||||
from queue import Queue
|
||||
'''
|
||||
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)
|
||||
|
||||
args = argsparser.parse_args()
|
||||
|
||||
|
||||
if args.client:
|
||||
ljclient = args.client
|
||||
else:
|
||||
ljclient = 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'
|
||||
|
||||
|
||||
if args.verbose:
|
||||
debug = args.verbose
|
||||
else:
|
||||
debug = 0
|
||||
|
||||
|
||||
lj.Config(redisIP,ljclient,"words")
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
# 'Destination' for each PL
|
||||
# name, number, active, PL , scene, laser
|
||||
# PL 0
|
||||
Dest0 = lj.DestObject('0', 0, True, 0, 0, 0)
|
||||
# PL 1
|
||||
Dest1 = lj.DestObject('1', 1, True, 1, 0, 1)
|
||||
# PL 2
|
||||
Dest2 = lj.DestObject('2', 2, True, 2, 0, 2)
|
||||
# PL 3
|
||||
Dest3 = lj.DestObject('3', 3, True, 3, 0, 3)
|
||||
|
||||
#
|
||||
# OSC
|
||||
#
|
||||
|
||||
oscserver = OSCServer( (myIP, OSCinPort) )
|
||||
oscserver.timeout = 0
|
||||
#oscrun = True
|
||||
|
||||
# this method of reporting timeouts only works by convention
|
||||
# that before calling handle_request() field .timed_out is
|
||||
# set to False
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
||||
# funny python's way to add a method to an instance of a class
|
||||
import types
|
||||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
# RAW OSC Frame available ?
|
||||
def OSCframe():
|
||||
# clear timed_out flag
|
||||
#print "oscframe"
|
||||
oscserver.timed_out = False
|
||||
# handle all pending requests then return
|
||||
while not oscserver.timed_out:
|
||||
oscserver.handle_request()
|
||||
|
||||
|
||||
# Stop osc server
|
||||
def OSCstop():
|
||||
|
||||
oscserver.close()
|
||||
|
||||
|
||||
|
||||
def OSCword0(value):
|
||||
global Word0
|
||||
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Words 0 got /words/text/0 with value", value)
|
||||
Word0 = value
|
||||
|
||||
def OSCword1(value):
|
||||
global Word1
|
||||
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Words 1 got /words/text/1 with value", value)
|
||||
Word1 = value
|
||||
|
||||
def OSCword2(value):
|
||||
global Word2
|
||||
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Words 2 got /words/text/2 with value", value)
|
||||
Word2 = value
|
||||
|
||||
def OSCword3(value):
|
||||
global Word3
|
||||
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Words 3 got /words/text/3 with value", value)
|
||||
Word3 = value
|
||||
|
||||
def OSCljclient(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("Words got /words/ljclient with value", value)
|
||||
lj.WebStatus("Words to virtual "+ str(value))
|
||||
ljclient = value
|
||||
lj.LjClient(ljclient)
|
||||
|
||||
|
||||
|
||||
|
||||
# /quit dummyvalue
|
||||
def quit(value):
|
||||
# don't do this at home (or it'll quit blender)
|
||||
global oscrun
|
||||
|
||||
oscrun = False
|
||||
print("Stopped by /quit.")
|
||||
lj.ClosePlugin()
|
||||
|
||||
|
||||
def Run():
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Words starting its OSC server at", myIP, "port",OSCinPort,"...")
|
||||
#oscserver.addMsgHandler( "default", lj.OSChandler )
|
||||
#oscserver.addMsgHandler( "/words/ljclient", OSCljclient )
|
||||
oscserver.addMsgHandler( "/words/text/0", OSCword0)
|
||||
oscserver.addMsgHandler( "/words/text/1", OSCword1)
|
||||
oscserver.addMsgHandler( "/words/text/2", OSCword2)
|
||||
oscserver.addMsgHandler( "/words/text/3", OSCword3)
|
||||
#oscserver.addMsgHandler( "/ping", lj.OSCping)
|
||||
#oscserver.addMsgHandler( "/quit", lj.OSCquit)
|
||||
# Add OSC generic plugins commands : 'default", /ping, /quit, /pluginame/obj, /pluginame/var, /pluginame/adddest, /pluginame/deldest
|
||||
lj.addOSCdefaults(oscserver)
|
||||
|
||||
color = lj.rgb2int(0,255,0)
|
||||
lj.WebStatus("Loading Words...")
|
||||
lj.WebStatus("Words ready.")
|
||||
lj.SendLJ("/words/start 1")
|
||||
|
||||
lj.SendLJ("words/text/0",Word0)
|
||||
lj.SendLJ("words/text/1",Word1)
|
||||
|
||||
try:
|
||||
|
||||
while lj.oscrun:
|
||||
|
||||
OSCframe()
|
||||
|
||||
lj.Text(Word0, color, PL = 0, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
#lj.DrawPL(0)
|
||||
|
||||
lj.Text(Word1, color, PL = 1, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
#lj.DrawPL(1)
|
||||
|
||||
lj.Text(Word2, color, PL = 2, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
#lj.DrawPL(2)
|
||||
|
||||
lj.Text(Word3, color, PL = 3, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
#lj.DrawPL(3)
|
||||
|
||||
lj.DrawDests()
|
||||
time.sleep(0.01)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
# Gently stop on CTRL C
|
||||
|
||||
finally:
|
||||
|
||||
lj.ClosePlugin()
|
||||
OSCstop()
|
||||
|
||||
|
||||
|
||||
Run()
|
||||
|
||||
|
||||
322
plugins/lj.py
322
plugins/lj.py
|
|
@ -1,322 +0,0 @@
|
|||
# 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)
|
||||
|
||||
|
||||
|
||||
|
||||
645
plugins/lj3.py
645
plugins/lj3.py
|
|
@ -1,645 +0,0 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
|
||||
lj3 v0.8.1
|
||||
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
|
||||
OSC functions commented, waiting working on OSC in python3
|
||||
|
||||
Config(redisIP, client number)
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
|
||||
Text(word, color, PL, xpos, ypos, resize, rotx, roty, rotz) : Display a word
|
||||
SendLJ(adress,message) : LJ remote control. See commands.py
|
||||
WebStatus(message) : display message on webui
|
||||
DrawPL(point list number) : once you stacked all wanted elements, like 2 polylines, send them to lasers.
|
||||
rgb2int(r,g,b)
|
||||
LjClient(client): Change Client number in redis keys
|
||||
LjPl(pl): Change pl number in redis keys = laser target.
|
||||
|
||||
|
||||
OSCstart(): Start the OSC system.
|
||||
OSCframe(): Handle incoming OSC message. Calling the right callback
|
||||
OSCstop(): Properly close the OSC system
|
||||
OSCping(value): Answer to LJ pings by sending /pong value
|
||||
OSCquit(name): Exit calling script using name in terminal
|
||||
|
||||
setup_controls(joystick)
|
||||
|
||||
XboxController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
Ps3Controller : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger, getUp, getDown, getLeft, getRight, getFire1, getFire2(self):
|
||||
MySaitekController : getLeftHori,getLeftVert, getRightHori,getRightVert, getLeftTrigger,getRightTrigger
|
||||
MyThrustController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
CSLController : getLeftHori,getLeftVert,getRightHori, getRightVert,getLeftTrigger,getRightTrigger,getFire1,getFire2
|
||||
my USB Joystick : getUp,getDown,getLeft,getRight,etLeftTrigger, getRightTrigger,getFire1, getFire2
|
||||
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
|
||||
# Import needed modules from osc4py3
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
#from osc4py3 import oscmethod as osm
|
||||
from osc4py3.oscmethod import *
|
||||
|
||||
|
||||
#redisIP = '127.0.0.1'
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
ClientNumber = 0
|
||||
|
||||
point_list = []
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
#
|
||||
# OSC interaction with LJ
|
||||
#
|
||||
|
||||
def OSCstart():
|
||||
# Start the system.
|
||||
osc_startup()
|
||||
#osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
def OSCframe():
|
||||
#print("OSCprocess")
|
||||
osc_process()
|
||||
|
||||
# Properly close the system. Todo
|
||||
def OSCstop():
|
||||
osc_terminate()
|
||||
|
||||
|
||||
def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
# print(msg)
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
except:
|
||||
print ('Connection to LJ refused : died ?')
|
||||
pass
|
||||
|
||||
def WebStatus(message):
|
||||
SendLJ("/status", message)
|
||||
|
||||
|
||||
# Answer to LJ pings with /pong pluginame
|
||||
def OSCping(value):
|
||||
SendLJ("/pong",value)
|
||||
|
||||
|
||||
# /quit
|
||||
def OSCquit(name):
|
||||
|
||||
WebStatus(name + " quit.")
|
||||
print("Stopping OSC...")
|
||||
|
||||
OSCstop()
|
||||
sys.exit()
|
||||
|
||||
'''
|
||||
def handlerfunction(s, x, y):
|
||||
# Will receive message data unpacked in s, x, y
|
||||
pass
|
||||
|
||||
def handlerfunction2(address, s, x, y):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
pass
|
||||
|
||||
# Make server channels to receive packets.
|
||||
osc_udp_server("127.0.0.1", 3721, "localhost")
|
||||
osc_udp_server("0.0.0.0", 3724, "anotherserver")
|
||||
'''
|
||||
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
||||
# caracteres corrects
|
||||
|
||||
[(-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
|
||||
|
||||
# caracteres 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)], #@
|
||||
|
||||
# Caracteres corrects
|
||||
|
||||
|
||||
[(-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 rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
|
||||
def Config(redisIP,client):
|
||||
global ClientNumber, r
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
ClientNumber = client
|
||||
osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
return r
|
||||
|
||||
|
||||
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 = rotx * math.pi / 180
|
||||
cosaX = math.cos(rad)
|
||||
sinaX = math.sin(rad)
|
||||
|
||||
y2 = y
|
||||
y = y2 * cosaX - z * sinaX
|
||||
z = y2 * sinaX + z * cosaX
|
||||
|
||||
rad = roty * math.pi / 180
|
||||
cosaY = math.cos(rad)
|
||||
sinaY = math.sin(rad)
|
||||
|
||||
z2 = z
|
||||
z = z2 * cosaY - x * sinaY
|
||||
x = z2 * sinaY + x * cosaY
|
||||
|
||||
rad = rotz * math.pi / 180
|
||||
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:
|
||||
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)
|
||||
#print i,x_offset
|
||||
# if digit
|
||||
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)
|
||||
#print ("laser",PL,"message",message)
|
||||
#dots.append(char_draw)
|
||||
|
||||
|
||||
|
||||
import re
|
||||
|
||||
def setup_controls(joystick):
|
||||
"""
|
||||
Joystick wrapper.
|
||||
"""
|
||||
if re.search('playstation', joystick.get_name(), re.I):
|
||||
return Ps3Controller(joystick)
|
||||
|
||||
elif re.search('X-box', joystick.get_name(), re.I):
|
||||
return XboxController(joystick)
|
||||
|
||||
elif re.search('Saitek', joystick.get_name(), re.I):
|
||||
return MySaitekController(joystick)
|
||||
|
||||
elif re.search('Thrustmaster dual analog 3.2', joystick.get_name(), re.I):
|
||||
return MyThrustController(joystick)
|
||||
|
||||
elif re.search('2n1 USB', joystick.get_name(), re.I):
|
||||
return CSLController(joystick)
|
||||
|
||||
elif re.search('Joystick', joystick.get_name(), re.I):
|
||||
return USBController(joystick)
|
||||
|
||||
return Controller(joystick)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self, joystick):
|
||||
"""Pass a PyGame joystick instance."""
|
||||
self.js = joystick
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
class XboxController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(XboxController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(4)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(11)
|
||||
|
||||
class Ps3Controller(Controller):
|
||||
|
||||
#up 4 _DOWN 6 left 7 right 5 croix 14 rond 13 triangle 12
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(Ps3Controller, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(8)
|
||||
|
||||
def getRightTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getUp(self):
|
||||
return self.js.get_button(4)
|
||||
|
||||
def getDown(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getLeft(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getRight(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(14)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(13)
|
||||
|
||||
|
||||
class MySaitekController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MySaitekController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
class MyThrustController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MyThrustController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
|
||||
class CSLController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(CSLController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(1)
|
||||
|
||||
class USBController(Controller):
|
||||
|
||||
|
||||
# my USB Joystick
|
||||
#up axis 0 -1 DOWN axis 0 1 left axis 1 1 right axis 1 -1 bouton gauche 10 bouton droite 9
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(USBController, self).__init__(joystick)
|
||||
|
||||
|
||||
def getUp(self):
|
||||
if self.js.get_axis(0) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getDown(self):
|
||||
if self.js.get_axis(0) > 0.9:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeft(self):
|
||||
if self.js.get_axis(1) == 1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getRight(self):
|
||||
if self.js.get_axis(1) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getFire1(self):
|
||||
if self.js.get_button(10) == 1:
|
||||
print ("fire 1")
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getFire2(self):
|
||||
if self.js.get_button(9) == 1:
|
||||
print ("fire 2")
|
||||
return self.js.get_button(9)
|
||||
|
||||
|
||||
|
||||
|
||||
1035
plugins/maxwell.py
Normal file
1035
plugins/maxwell.py
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,347 +0,0 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
LJ v0.8.1 in python3
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
|
||||
OSC functions commented, waiting working on OSC in python3
|
||||
|
||||
Config(redisIP, client number)
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
|
||||
Text(word, color, PL, xpos, ypos, resize, rotx, roty, rotz) : Display a word
|
||||
Send(adress,message) : remote control. See commands.py
|
||||
WebStatus(message) : display message on webui
|
||||
DrawPL(point list number) : once you stacked all wanted elements, like 2 polylines, send them to lasers.
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
|
||||
# Import needed modules from osc4py3
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
|
||||
|
||||
#redisIP = '127.0.0.1'
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
ClientNumber = 0
|
||||
|
||||
point_list = []
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
#
|
||||
# OSC interaction with LJ
|
||||
#
|
||||
|
||||
def OSCstart():
|
||||
# Start the system.
|
||||
osc_startup()
|
||||
#osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
def OSCframe():
|
||||
#print("OSCprocess")
|
||||
osc_process()
|
||||
|
||||
# Properly close the system. Todo
|
||||
def OSCstop():
|
||||
osc_terminate()
|
||||
|
||||
|
||||
def SendLJ(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
except:
|
||||
print ('Connection to LJ refused : died ?')
|
||||
pass
|
||||
|
||||
# Answer to LJ pings
|
||||
def OSCping(value):
|
||||
|
||||
print("I got /ping with value", value)
|
||||
SendLJ("/pong",value)
|
||||
|
||||
'''
|
||||
def handlerfunction(s, x, y):
|
||||
# Will receive message data unpacked in s, x, y
|
||||
pass
|
||||
|
||||
def handlerfunction2(address, s, x, y):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
pass
|
||||
|
||||
# Make server channels to receive packets.
|
||||
osc_udp_server("127.0.0.1", 3721, "localhost")
|
||||
osc_udp_server("0.0.0.0", 3724, "anotherserver")
|
||||
'''
|
||||
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
||||
# caracteres corrects
|
||||
|
||||
[(-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
|
||||
|
||||
# caracteres 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)], #@
|
||||
|
||||
# Caracteres corrects
|
||||
|
||||
|
||||
[(-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
|
||||
osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
# If you want to use rgb for color :
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
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 = rotx * math.pi / 180
|
||||
cosaX = math.cos(rad)
|
||||
sinaX = math.sin(rad)
|
||||
|
||||
y2 = y
|
||||
y = y2 * cosaX - z * sinaX
|
||||
z = y2 * sinaX + z * cosaX
|
||||
|
||||
rad = roty * math.pi / 180
|
||||
cosaY = math.cos(rad)
|
||||
sinaY = math.sin(rad)
|
||||
|
||||
z2 = z
|
||||
z = z2 * cosaY - x * sinaY
|
||||
x = z2 * sinaY + x * cosaY
|
||||
|
||||
rad = rotz * math.pi / 180
|
||||
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:
|
||||
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)
|
||||
#print i,x_offset
|
||||
# if digit
|
||||
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)
|
||||
# print ("laser",PL,"message",message)
|
||||
#dots.append(char_draw)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -29,6 +29,8 @@ Remember : LJ will automatically warp geometry according to alignement data. See
|
|||
'''
|
||||
|
||||
import redis
|
||||
import sys
|
||||
sys.path.append('../../libs')
|
||||
import lj3
|
||||
import numpy as np
|
||||
import math,time
|
||||
|
|
@ -48,7 +50,7 @@ from osc4py3 import oscbuildparse
|
|||
from osc4py3.oscmethod import *
|
||||
|
||||
import json
|
||||
|
||||
oscrun = True
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
|
|
@ -103,7 +105,7 @@ if args.redisIP != None:
|
|||
else:
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
lj3.Config(redisIP,ljclient,"planet")
|
||||
|
||||
#
|
||||
# Inits Laser
|
||||
|
|
@ -164,6 +166,42 @@ def Proj(x,y,z,angleX,angleY,angleZ):
|
|||
# All the coordinates base functions
|
||||
#
|
||||
|
||||
#Transforming coordinates functions by Povik martin.povik@gmail.com
|
||||
import math
|
||||
import datetime
|
||||
|
||||
def cartesian_to_horizontal(x, y, z):
|
||||
ele = math.degrees(math.atan2(z, math.sqrt(x * x + y * y)))
|
||||
az = math.degrees(math.atan2(y, x))
|
||||
return math.sqrt(x * x + y * y + z * z), ele, az
|
||||
|
||||
def horizontal_to_equatorial(az, ele, lat):
|
||||
az, ele = math.radians(az), math.radians(ele)
|
||||
lat = math.radians(lat)
|
||||
cd_ct = math.cos(ele) * math.cos(az) * math.sin(lat) \
|
||||
+ math.sin(ele) * math.cos(lat)
|
||||
cd_st = math.cos(ele) * math.sin(az)
|
||||
sd = -math.cos(ele) * math.cos(az) * math.cos(lat) + math.sin(ele) * math.sin(lat)
|
||||
cd = math.sqrt(cd_ct * cd_ct + cd_st * cd_st)
|
||||
return math.atan2(cd_st / cd, cd_ct / cd) * 12 / math.pi, \
|
||||
math.degrees(math.atan2(sd, cd))
|
||||
|
||||
def timestamp_to_jd(timestamp):
|
||||
return float(timestamp) / 86400 + 2440587.5
|
||||
|
||||
def timestamp_to_lst(timestamp, lon):
|
||||
timestamp = float(timestamp)
|
||||
timeofday = timestamp % 86400
|
||||
jd0 = timestamp_to_jd(timestamp - timeofday)
|
||||
T = (jd0 - 2451545) / 36525
|
||||
s0 = 6.697374558 + 2400.05133691 * T + 0.000025862 * T**2 \
|
||||
- 0.0000000017 * T**3
|
||||
return (s0 + 1.0027379093 * (timeofday / 86400) * 24.0 + float(lon) / 15) % 24
|
||||
|
||||
def horizontal_to_equatorial2(az, ele, lat, lon, timestamp):
|
||||
t, d = horizontal_to_equatorial(az, ele, lat)
|
||||
return d, (timestamp_to_lst(timestamp, lon) - t) % 24
|
||||
|
||||
'''
|
||||
To minize number of sky objects coordinates conversion : Change planetarium FOV in Ra Dec to select objects
|
||||
(planets, hipparcos,..). Then get only those objects in AltAz coordinates.
|
||||
|
|
@ -586,13 +624,14 @@ def NewTime(timeshift):
|
|||
if DisplayAnything:
|
||||
UpdateAnything()
|
||||
|
||||
# /quit
|
||||
def OSCquit():
|
||||
# /quit dummyvalue
|
||||
def quit(value):
|
||||
# don't do this at home (or it'll quit blender)
|
||||
global oscrun
|
||||
|
||||
WebStatus("Planet stopping")
|
||||
print("Stopping OSC...")
|
||||
lj3.OSCstop()
|
||||
sys.exit()
|
||||
oscrun = False
|
||||
print("Stopped by /quit.")
|
||||
lj3.ClosePlugin()
|
||||
|
||||
def OSCUI(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
|
|
@ -615,7 +654,7 @@ try:
|
|||
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
|
||||
osc_method("/planet/planetUI*", OSCUI)
|
||||
osc_method("/ping*", lj3.OSCping)
|
||||
osc_method("/quit", OSCquit)
|
||||
osc_method("/quit", quit)
|
||||
|
||||
WebStatus("Loading Cities...")
|
||||
ts = load.timescale()
|
||||
|
|
@ -654,7 +693,7 @@ try:
|
|||
DisplayAnything = False
|
||||
print("Start displaying on",lasernumber,"lasers")
|
||||
|
||||
while 1:
|
||||
while oscrun:
|
||||
|
||||
for laser in range(lasernumber):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2.7
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
|
|
@ -15,21 +15,42 @@ OSC server with :
|
|||
/simu/quit
|
||||
/simu/newpl new pl number to draw
|
||||
/simu/newclient new client number to draw
|
||||
/ping
|
||||
|
||||
'''
|
||||
|
||||
#from __future__ import print_function
|
||||
import time
|
||||
import math
|
||||
import random
|
||||
import itertools
|
||||
import traceback
|
||||
import sys
|
||||
import os
|
||||
#import thread
|
||||
import redis
|
||||
import pygame
|
||||
|
||||
import pdb
|
||||
import types, ast, argparse
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
import types, ast, argparse, struct
|
||||
import numpy as np
|
||||
|
||||
sys.path.append('../libs')
|
||||
|
||||
# import from LJ
|
||||
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
||||
sys.path.append(ljpath +'/libs/')
|
||||
#print ljpath+'/libs/'
|
||||
|
||||
import lj23 as lj
|
||||
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
from OSC import OSCServer, OSCClient, OSCMessage
|
||||
#print ("Importing lj23 and OSC from libs...")
|
||||
else:
|
||||
from OSC3 import OSCServer, OSCClient, OSCMessage
|
||||
|
||||
|
||||
|
||||
screen_size = [750,750]
|
||||
pl = [[],[],[],[]]
|
||||
|
|
@ -38,8 +59,11 @@ pl = [[],[],[],[]]
|
|||
print ("")
|
||||
print ("LJ v0.8.0 : Pygame simulator")
|
||||
print ("")
|
||||
import pygame
|
||||
print ("Arguments parsing if needed...")
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Arguments parsing
|
||||
#
|
||||
|
|
@ -77,7 +101,7 @@ else:
|
|||
redisIP = '127.0.0.1'
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
lj.Config(redisIP,0,"simu")
|
||||
|
||||
# myIP
|
||||
if args.myIP != None:
|
||||
|
|
@ -101,7 +125,7 @@ print ("")
|
|||
print ("Receiving on ", oscIPin, ":",str(oscPORTin))
|
||||
oscserver = OSCServer( (oscIPin, oscPORTin) )
|
||||
oscserver.timeout = 0
|
||||
OSCRunning = True
|
||||
oscrun = True
|
||||
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
|
@ -109,10 +133,10 @@ def handle_timeout(self):
|
|||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
def sendLJ(address, args):
|
||||
def SendLJ(address, args):
|
||||
|
||||
if debug >0:
|
||||
print "Sending to LJ...", address, args
|
||||
print("Sending to LJ...", address, args)
|
||||
|
||||
osclientlj = OSCClient()
|
||||
osclientlj.connect((ljIP, ljPort))
|
||||
|
|
@ -127,9 +151,13 @@ def sendLJ(address, args):
|
|||
return True
|
||||
|
||||
except:
|
||||
print 'Connection to LJ IP', ljIP,'port', ljPort, 'refused : died ?'
|
||||
print('Connection to LJ IP', ljIP,'port', ljPort, 'refused : died ?')
|
||||
return False
|
||||
|
||||
def WebStatus(message):
|
||||
|
||||
SendLJ("/status",message)
|
||||
|
||||
|
||||
# RAW OSC Frame available ?
|
||||
def osc_frame():
|
||||
|
|
@ -142,52 +170,42 @@ def osc_frame():
|
|||
|
||||
# /quit
|
||||
def quit(path, tags, args, source):
|
||||
global oscrun
|
||||
|
||||
oscrun = False
|
||||
pygame.quit()
|
||||
print "pySimu Stopped by /quit."
|
||||
sys.exit()
|
||||
|
||||
# /start : 0 exit
|
||||
def start(path, tags, args, source):
|
||||
|
||||
print args, type(args)
|
||||
if args[0] == 0:
|
||||
pygame.quit()
|
||||
print "pySimu stopped by /start 0"
|
||||
sys.exit()
|
||||
|
||||
# Answer to LJ pings
|
||||
def ping(path, tags, args, source):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print "Simu got /ping with value", args[0]
|
||||
print "Simu replied with /pong simu"
|
||||
sendLJ("/pong","simu")
|
||||
|
||||
|
||||
lj.ClosePlugin()
|
||||
|
||||
|
||||
# /newPL pointlistnumber
|
||||
def newPL(path, tags, args, source):
|
||||
|
||||
user = ''.join(path.split("/"))
|
||||
print ""
|
||||
print user,path,args
|
||||
print "Simulator got a new point list number :", args[0]
|
||||
print ("")
|
||||
print (user,path,args)
|
||||
print ("Simulator got a new point list number :", args[0])
|
||||
simuPL = args[0]
|
||||
|
||||
# /newClient clientnumber
|
||||
def newClient(path, tags, args, source):
|
||||
|
||||
user = ''.join(path.split("/"))
|
||||
print ""
|
||||
print user,path,args
|
||||
print "Simulator got a new client number : ", args[0]
|
||||
print ("")
|
||||
print (user,path,args)
|
||||
print ("Simulator got a new client number : ", args[0])
|
||||
ljclient = args[0]
|
||||
|
||||
oscserver.addMsgHandler( "/quit", quit )
|
||||
oscserver.addMsgHandler( "/ping", ping )
|
||||
oscserver.addMsgHandler( "/pysimu/start", start )
|
||||
oscserver.addMsgHandler( "/pysimu/newpl", newPL )
|
||||
oscserver.addMsgHandler( "/pysimu/newclient", newClient )
|
||||
|
||||
# Redis key 'n' -> numpy array a
|
||||
# array 2 dimensions is also store in redis key : h time w values
|
||||
def fromRedis(n):
|
||||
|
||||
print ("get key", n)
|
||||
encoded = r.get(n)
|
||||
h, w = struct.unpack('>II',encoded[:8])
|
||||
print(h,w)
|
||||
a = np.frombuffer(encoded, dtype=np.int16, offset=8).reshape(h,w)
|
||||
return a
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -205,15 +223,26 @@ def RenderScreen(surface):
|
|||
c = int(xyc[2])
|
||||
if c: pygame.draw.line(surface,c,xyc_prev[:2],xyc[:2],3)
|
||||
xyc_prev = xyc
|
||||
#
|
||||
# Startup
|
||||
#
|
||||
|
||||
|
||||
SendLJ("/simu/start",1)
|
||||
WebStatus("pysimu startup...")
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode(screen_size)
|
||||
pygame.display.set_caption("LJ Simulator")
|
||||
clock = pygame.time.Clock()
|
||||
update_screen = False
|
||||
|
||||
oscserver.addMsgHandler( "/quit", lj.OSCquit )
|
||||
oscserver.addMsgHandler( "/ping", lj.OSCping )
|
||||
#oscserver.addMsgHandler( "/simu/start", start )
|
||||
oscserver.addMsgHandler( "/simu/newpl", newPL )
|
||||
oscserver.addMsgHandler( "/simu/newclient", newClient )
|
||||
|
||||
print ("Simulator displays client", ljclient, "point list", str(simuPL))
|
||||
WebStatus("pySimu "+ str(ljclient) + " " + str(simuPL))
|
||||
|
||||
#
|
||||
# Main
|
||||
|
|
@ -221,7 +250,7 @@ print ("Simulator displays client", ljclient, "point list", str(simuPL))
|
|||
|
||||
try:
|
||||
|
||||
while True:
|
||||
while lj.oscrun:
|
||||
|
||||
# pending osc message ?
|
||||
osc_frame()
|
||||
|
|
@ -232,8 +261,15 @@ try:
|
|||
break
|
||||
|
||||
screen.fill(0)
|
||||
pl[simuPL] = ast.literal_eval(r.get("/pl/"+ str(ljclient) + "/" + str(simuPL)))
|
||||
|
||||
#print("/pl/"+ str(ljclient) + "/" + str(simuPL))
|
||||
#print r.get("/pl/"+ str(ljclient) + "/" + str(simuPL))
|
||||
if is_py2:
|
||||
pl[simuPL] = ast.literal_eval(r.get("/pl/"+ str(ljclient) + "/" + str(simuPL)))
|
||||
else:
|
||||
pl[simuPL] = eval(r.get("/pl/"+ str(ljclient) + "/" + str(simuPL)))
|
||||
|
||||
#pl[simuPL] = fromRedis("/pl/"+ str(ljclient) + "/" + str(simuPL))
|
||||
|
||||
if update_screen:
|
||||
update_screen = False
|
||||
RenderScreen(screen)
|
||||
|
|
@ -242,14 +278,19 @@ try:
|
|||
update_screen = True
|
||||
|
||||
clock.tick(30)
|
||||
# time.sleep(0.001)
|
||||
time.sleep(0.001)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
finally:
|
||||
pygame.quit()
|
||||
print "pySimu Stopped."
|
||||
lj.ClosePlugin()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
331
plugins/square.py
Normal file
331
plugins/square.py
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
|
||||
'''
|
||||
|
||||
Square
|
||||
v0.1.0
|
||||
|
||||
Anaglyphed rotating square (for red and green glasses)
|
||||
|
||||
This scene uses the drawing functions (polyline) provided by LJ in lj23.py
|
||||
|
||||
LICENCE : CC
|
||||
|
||||
by Sam Neurohack
|
||||
|
||||
|
||||
'''
|
||||
import sys
|
||||
import os
|
||||
print()
|
||||
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
||||
|
||||
# import from shell
|
||||
|
||||
sys.path.append(ljpath +'/../libs/')
|
||||
|
||||
#import from LJ
|
||||
sys.path.append(ljpath +'/libs/')
|
||||
print (ljpath+'/../libs/')
|
||||
|
||||
import lj23layers as lj
|
||||
|
||||
sys.path.append('../libs')
|
||||
from OSC3 import OSCServer, OSCClient, OSCMessage
|
||||
import redis
|
||||
import math
|
||||
import time
|
||||
import argparse
|
||||
|
||||
OSCinPort = 8013
|
||||
|
||||
print ("")
|
||||
print ("Arguments parsing if needed...")
|
||||
argsparser = argparse.ArgumentParser(description="Square example 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("-s","--scene",help="LJ scene 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()
|
||||
|
||||
if args.scene:
|
||||
ljscene = args.scene
|
||||
else:
|
||||
ljscene = 0
|
||||
'''
|
||||
if args.laser:
|
||||
plnumber = args.laser
|
||||
else:
|
||||
plnumber = 0
|
||||
'''
|
||||
|
||||
# Redis Computer IP
|
||||
if args.redisIP != None:
|
||||
redisIP = args.redisIP
|
||||
else:
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
print("redisIP",redisIP)
|
||||
|
||||
# myIP
|
||||
if args.myIP != None:
|
||||
myIP = args.myIP
|
||||
else:
|
||||
myIP = '127.0.0.1'
|
||||
|
||||
print("myIP",myIP)
|
||||
|
||||
if args.verbose:
|
||||
debug = args.verbose
|
||||
else:
|
||||
debug = 0
|
||||
|
||||
# Useful variables init.
|
||||
white = lj.rgb2int(255,255,255)
|
||||
red = lj.rgb2int(255,0,0)
|
||||
blue = lj.rgb2int(0,0,255)
|
||||
green = lj.rgb2int(0,255,0)
|
||||
|
||||
width = 800
|
||||
height = 600
|
||||
centerX = width / 2
|
||||
centerY = height / 2
|
||||
|
||||
# 3D to 2D projection parameters
|
||||
fov = 256
|
||||
viewer_distance = 2.2
|
||||
|
||||
# Anaglyph computation parameters for right and left eyes.
|
||||
# algorythm come from anaglyph geo maps
|
||||
eye_spacing = 100
|
||||
nadir = 0.5
|
||||
observer_altitude = 30000
|
||||
map_layerane_altitude = 0.0
|
||||
|
||||
# square coordinates : vertices that compose each of the square.
|
||||
vertices = [
|
||||
(- 1.0, 1.0,- 1.0),
|
||||
( 1.0, 1.0,- 1.0),
|
||||
( 1.0,- 1.0,- 1.0),
|
||||
(- 1.0,- 1.0,- 1.0)
|
||||
]
|
||||
|
||||
face = [0,1,2,3]
|
||||
|
||||
#
|
||||
# LJ inits
|
||||
#
|
||||
|
||||
layer = 0
|
||||
|
||||
# Setup LJ library mandatory properties for this layerugin
|
||||
lj.Config(redisIP, ljscene, "square")
|
||||
|
||||
# Define properties for each drawn "element" : name, intensity, active, xy, color, red, green, blue, layer , closed
|
||||
Leftsquare = lj.FixedObject('Leftsquare', True, 255, [], red, 255, 0, 0, layer , True)
|
||||
Rightsquare = lj.FixedObject('Rightsquare', True, 255, [], green, 0, 255, 0, layer , True)
|
||||
|
||||
# 'Destination' for given layer : name, number, active, layer , scene, laser
|
||||
Dest0 = lj.DestObject('0', 0, True, 0 , 0, 0) # Dest0 will send layer 0 points to scene 0, laser 0
|
||||
|
||||
'''
|
||||
TRICKS:
|
||||
|
||||
1/ How to have another laser drawing the same thing ?
|
||||
|
||||
That's a destination problem : just add another destination !
|
||||
|
||||
Dest1 = lj.DestObject('1', 1, True, 0 , 1, 1) # Dest1 will also send layer 0 points to scene 1, laser 1
|
||||
|
||||
|
||||
2/ Different layers to different lasers ?
|
||||
|
||||
Say because of too much points you want Left element drawn by scene 0, laser 0 and right element by scene 0, laser 1
|
||||
|
||||
First define a different object/layer for each drawn element :
|
||||
|
||||
Leftsquare = lj.FixedObject('Leftsquare', True, 255, [], red, 255, 0, 0, 0 , True) # Left goes to layer 0
|
||||
Rightsquare = lj.FixedObject('Rightsquare', True, 255, [], green, 0, 255, 0, 1 , True) # Right goes to layer 1
|
||||
|
||||
Define 2 destinations :
|
||||
|
||||
Dest0 = lj.DestObject('0', 0, True, 0 , 0, 0) # Dest0 will send layer 0 points to scene 0, laser 0
|
||||
Dest1 = lj.DestObject('1', 1, True, 1 , 0, 1) # Dest1 will send layer 1 points to scene 0, laser 1
|
||||
|
||||
|
||||
|
||||
3/ Different layers to one laser ?
|
||||
|
||||
You should consider adding all your points to one layer, but same as 1/ it's a destination problem,
|
||||
just add another destination with the same scene/laser for each layer
|
||||
|
||||
Dest1 = lj.DestObject('1', 1, True, 1 , 0, 0) # Dest1 will also send layer 1 points to scene 0, laser 0
|
||||
|
||||
|
||||
4/ I want to animate/modify anything on the fly : I'm doing a game and suddenly my hero change color.
|
||||
|
||||
It's a declared object problem : say Hero is a Fixed Object, you can directly change value of
|
||||
|
||||
Hero.name, Hero.active, Hero.intensity, Hero.xy, Hero.color, Hero.red, Hero.green, Hero.blue, Hero.layer, Hero.closed
|
||||
|
||||
For a character vanishing in one point you can decrease it's size : RelativeObjects has graphics computation.
|
||||
PNC.name, PNC.active, PNC.intensity, PNC.xy, PNC.color, PNC.red, PNC.green, PNC.blue, PNC.layer, PNC.closed, PNC.xpos, PNC.ypos, PNC.resize, PNC.rotx, PNC.roty, PNC.rotz
|
||||
|
||||
|
||||
Same for Dest0 if it's a destObject :
|
||||
Dest0.name, Dest0.number, Dest0.active, Dest0.layer, Dest0.scene, Dest0.laser
|
||||
|
||||
|
||||
DrawDests() will take care of all your declared drawn elements and Destinations.
|
||||
|
||||
'''
|
||||
|
||||
|
||||
#
|
||||
# Anaglyph computation : different X coordinate for each eye
|
||||
#
|
||||
|
||||
def LeftShift(elevation):
|
||||
|
||||
diff = elevation - map_layerane_altitude
|
||||
return nadir * eye_spacing * diff / (observer_altitude - elevation)
|
||||
|
||||
def RightShift(elevation):
|
||||
|
||||
diff = map_layerane_altitude - elevation
|
||||
return (1 - nadir) * eye_spacing * diff / (observer_altitude - elevation)
|
||||
|
||||
#
|
||||
# OSC
|
||||
#
|
||||
|
||||
oscserver = OSCServer( (myIP, OSCinPort) )
|
||||
oscserver.timeout = 0
|
||||
|
||||
|
||||
# this method of reporting timeouts only works by convention
|
||||
# that before calling handle_request() field .timed_out is
|
||||
# set to False
|
||||
def handle_timeout(self):
|
||||
self.timed_out = True
|
||||
|
||||
# funny python's way to add a method to an instance of a class
|
||||
import types
|
||||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
# OSC callbacks
|
||||
|
||||
# /square/ljscene
|
||||
def OSCljscene(path, tags, args, source):
|
||||
|
||||
print("Got /square/ljscene with value", args[0])
|
||||
lj.WebStatus("square to virtual "+ str(args[0]))
|
||||
ljscene = args[0]
|
||||
lj.Ljscene(ljscene)
|
||||
|
||||
|
||||
def Proj(x,y,z,angleX,angleY,angleZ):
|
||||
|
||||
rad = angleX * math.pi / 180
|
||||
cosa = math.cos(rad)
|
||||
sina = math.sin(rad)
|
||||
y2 = y
|
||||
y = y2 * cosa - z * sina
|
||||
z = y2 * sina + z * cosa
|
||||
|
||||
rad = angleY * math.pi / 180
|
||||
cosa = math.cos(rad)
|
||||
sina = math.sin(rad)
|
||||
z2 = z
|
||||
z = z2 * cosa - x * sina
|
||||
x = z2 * sina + x * cosa
|
||||
|
||||
rad = angleZ * math.pi / 180
|
||||
cosa = math.cos(rad)
|
||||
sina = math.sin(rad)
|
||||
x2 = x
|
||||
x = x2 * cosa - y * sina
|
||||
y = x2 * sina + y * cosa
|
||||
|
||||
|
||||
""" Transforms this 3D point to 2D using a perspective projection. """
|
||||
factor = fov / (viewer_distance + z)
|
||||
x = x * factor + centerX
|
||||
y = - y * factor + centerY
|
||||
return (x,y)
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
||||
def Run():
|
||||
|
||||
|
||||
Left = []
|
||||
Right = []
|
||||
counter =0
|
||||
lj.WebStatus("Square")
|
||||
lj.SendLJ("/square/start 1")
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Starting OSC server at",myIP," port",OSCinPort,"...")
|
||||
oscserver.addMsgHandler( "/square/ljscene", OSCljscene )
|
||||
|
||||
# Add OSC generic layerugins commands : 'default", /ping, /quit, /pluginame/obj, /pluginame/var, /pluginame/adddest, /pluginame/deldest
|
||||
lj.addOSCdefaults(oscserver)
|
||||
|
||||
try:
|
||||
|
||||
while lj.oscrun:
|
||||
|
||||
lj.OSCframe()
|
||||
Left = []
|
||||
Right = []
|
||||
|
||||
x = vertices[0][0]
|
||||
y = vertices[0][1]
|
||||
z = vertices[0][2]
|
||||
|
||||
# LJ tracers will "move" the laser to this first point in black, then move to the next with second point color.
|
||||
# For more accuracy in dac emulator, repeat this first point.
|
||||
|
||||
# Generate all points in square.
|
||||
for point in face:
|
||||
x = vertices[point][0]
|
||||
y = vertices[point][1]
|
||||
z = vertices[point][2]
|
||||
|
||||
Left.append(Proj(x+LeftShift(z*25),y,z,0,counter,0))
|
||||
Right.append(Proj(x+RightShift(z*25),y,z,0,counter,0))
|
||||
|
||||
|
||||
lj.PolyLineOneColor(Left, c = Leftsquare.color , layer = Leftsquare.layer, closed = Leftsquare.closed)
|
||||
lj.PolyLineOneColor(Right, c = Rightsquare.color , layer = Rightsquare.layer, closed = Rightsquare.closed)
|
||||
|
||||
lj.DrawDests()
|
||||
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
counter += 1
|
||||
if counter > 360:
|
||||
counter = 0
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
# Gently stop on CTRL C
|
||||
|
||||
finally:
|
||||
|
||||
lj.ClosePlugin()
|
||||
|
||||
|
||||
Run()
|
||||
|
|
@ -8,11 +8,13 @@ Cycling text on one LJ laser.
|
|||
LICENCE : CC
|
||||
|
||||
'''
|
||||
|
||||
import sys,time
|
||||
sys.path.append('../libs')
|
||||
import redis
|
||||
import lj3
|
||||
import sys,time
|
||||
|
||||
import argparse
|
||||
import traceback
|
||||
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
|
|
@ -24,6 +26,8 @@ OSCinPort = 8007
|
|||
duration = 300
|
||||
lasertext = ["TEAMLASER","FANFAN","LOLOSTER","SAM"]
|
||||
|
||||
PL = 0
|
||||
|
||||
'''
|
||||
is_py2 = sys.version[0] == '2'
|
||||
if is_py2:
|
||||
|
|
@ -73,9 +77,10 @@ else:
|
|||
myIP = '127.0.0.1'
|
||||
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
lj3.Config(redisIP,ljclient,"cycl")
|
||||
#r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
oscrun = True
|
||||
|
||||
# If you want to use rgb for color :
|
||||
def rgb2int(r,g,b):
|
||||
|
|
@ -93,29 +98,38 @@ def OSCljclient(value):
|
|||
ljclient = value
|
||||
lj3.LjClient(ljclient)
|
||||
|
||||
|
||||
def OSCpl(value):
|
||||
global PL
|
||||
|
||||
print("Cycl got /cycl/pl with value", value)
|
||||
lj3.WebStatus("Cycl to pl "+ str(value))
|
||||
lj3.LjPl(value)
|
||||
PL = int(value)
|
||||
lj3.LjPl(PL)
|
||||
|
||||
|
||||
# /quit dummyvalue
|
||||
def quit(value):
|
||||
global oscrun
|
||||
|
||||
lj3.ClosePlugin()
|
||||
oscrun = False
|
||||
|
||||
'''
|
||||
# /ping
|
||||
def OSCping():
|
||||
|
||||
lj3.OSCping("cycl")
|
||||
|
||||
# /quit
|
||||
def OSCquit():
|
||||
|
||||
lj3.OSCquit("cycl")
|
||||
'''
|
||||
|
||||
print("Cycl starting its OSC server at", myIP, "port",OSCinPort,"...")
|
||||
osc_startup()
|
||||
osc_udp_server(myIP, OSCinPort, "InPort")
|
||||
|
||||
osc_method("/ping*", OSCping)
|
||||
osc_method("/quit", OSCquit)
|
||||
osc_method("/ping*", lj3.OSCping)
|
||||
osc_method("/quit", quit)
|
||||
#osc_method("/ping*", OSCping)
|
||||
#osc_method("/quit", OSCquit)
|
||||
osc_method("/cycl/ljclient*", OSCljclient)
|
||||
osc_method("/cycl/pl*", OSCpl)
|
||||
|
||||
|
|
@ -130,12 +144,13 @@ def Run():
|
|||
color = rgb2int(255,255,255)
|
||||
|
||||
try:
|
||||
while 1:
|
||||
while oscrun:
|
||||
|
||||
if timing == duration or timing == -1:
|
||||
message = lasertext[step]
|
||||
lj3.Text(message, color, PL = 0, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
lj3.DrawPL(0)
|
||||
#print ('PL',PL)
|
||||
lj3.Text(message, color, PL = PL, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
lj3.DrawPL(PL)
|
||||
timing = 0
|
||||
|
||||
else:
|
||||
|
|
@ -143,7 +158,11 @@ def Run():
|
|||
if step >3:
|
||||
step =0
|
||||
timing += 1
|
||||
lj3.OSCframe()
|
||||
time.sleep(0.01)
|
||||
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
|
@ -151,13 +170,7 @@ def Run():
|
|||
|
||||
finally:
|
||||
|
||||
WebStatus("Textcycl stop")
|
||||
print("Stopping OSC...")
|
||||
lj3.OSCstop()
|
||||
|
||||
print ("Textcycl Stopped.")
|
||||
|
||||
|
||||
quit()
|
||||
|
||||
Run()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue