This commit is contained in:
Sam Neurohack 2019-03-19 14:24:11 +01:00
parent 89462381db
commit 172ae79105
33 changed files with 1245 additions and 311 deletions

View file

@ -7,10 +7,11 @@ VJing Bank 0
was Franken for compo laser at coockie 2018 demoparty
0 : many Starfields
0 : Starfields
1 : generic pose animations
2 : Faces
3 : Dancers
4 : IdiotIA
LICENCE : CC
Sam Neurohack, Loloster,
@ -28,6 +29,7 @@ from random import randrange
import redis
import lj3
import sys,time
import os
from osc4py3.as_eventloop import *
from osc4py3 import oscbuildparse
@ -76,11 +78,6 @@ else:
lj3.Config(redisIP,ljclient)
def OSCljclient(value):
# Will receive message address, and message data flattened in s, x, y
print("I got /bank0/ljclient with value", value)
ljclient = value
lj3.LjClient(ljclient)
def hex2rgb(hexcode):
return tuple(map(ord,hexcode[1:].decode('hex')))
@ -440,7 +437,8 @@ CurrentPose = 1
def prepareFACES():
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
# anim format (name, xpos, ypos, resize, currentframe, totalframe, count, frame repeat)
# 0 1 2 3 4 5 6 7
# total frame is fetched from directory file count
anims[0] = [['detroit1', 300,300, 100,0,0,0,1]]
@ -470,32 +468,40 @@ def prepareFACES():
#by this one
#thanks to https://stackoverflow.com/questions/19184335/is-there-a-need-for-rangelena
for laseranims in anims:
if debug > 1:
print("anims:",laseranims)
for anim in laseranims:
anim[5]=lengthPOSE(anim[0])
if debug > 1:
print(anim[5])
for anim in laseranims:
anim[5] = lengthPOSE(anim[0])
if debug > 0:
print("anim :", anim)
print("length :", anim[5])
# display the face animation describe in PoseDir
def Faces():
for laseranims in range(3):
for anim in anims[laseranims]:
PL = laseranims
#print PL, anim
dots = []
#print anim, anim[5]
# repeat anim[7] time the same frame
# increase counter [6]
# compare to repeat [7] time the same frame
anim[6] +=1
if anim[6] == anim[7]:
# reset repeat
anim[6] = 0
# increase current frame and compare to total frame
# increase current frame [4]
anim[4] += 1
# compare to total frame [5]
if anim[4] == anim[5]:
anim[4] = 0
@ -509,7 +515,7 @@ def Faces():
for people in range(len(pose_json['people'])):
#lj3.PolyLineOneColor(face(pose), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
#lj3.rPolyLineOneColor(face(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
@ -594,12 +600,107 @@ def Dancers():
PL[PL] = fwork.LinesPL(PL)
'''
# Curve 4 IdiotIA
import json
CurrentPose = 1
def prepareIdiotIA():
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
# total frame is fetched from directory file count
anims[0] = [['detroit1', 300,300, 100,0,0,0,1]]
anims[1] = [['detroit1', 400,200, 200,0,0,0,1]]
anims[2] = [['detroit1', 500,200, 300,0,0,0,1]]
'''
# read anims number of frames from disk.
for anim in range(len(anims0)):
anims0[anim][5]= lengthPOSE(anims0[anim][0])
for anim in range(len(anims1)):
anims1[anim][5]= lengthPOSE(anims1[anim][0])
for anim in range(len(anims2)):
anims2[anim][5]= lengthPOSE(anims2[anim][0])
'''
#replace code below
'''
for laseranims in range(3):
if debug > 0:
print "anims:",anims[laseranims],
for anim in range(len(anims[laseranims])):
anims[laseranims][anim][5]= lengthPOSE(anims[laseranims][anim][0])
if debug > 1:
print anims[laseranims][anim][5]
'''
#by this one
#thanks to https://stackoverflow.com/questions/19184335/is-there-a-need-for-rangelena
for laseranims in anims:
if debug > 1:
print("anims:",laseranims)
for anim in laseranims:
anim[5]=lengthPOSE(anim[0])
if debug > 1:
print(anim[5])
# display the face animation describe in PoseDir
def Faces():
for laseranims in range(3):
for anim in anims[laseranims]:
PL = laseranims
#print PL, anim
dots = []
#print anim, anim[5]
# repeat anim[7] time the same frame
anim[6] +=1
if anim[6] == anim[7]:
anim[6] = 0
# increase current frame and compare to total frame
anim[4] += 1
if anim[4] == anim[5]:
anim[4] = 0
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
posefile = open(posename , 'r')
posedatas = posefile.read()
pose_json = json.loads(posedatas)
# Face
for people in range(len(pose_json['people'])):
#lj3.rPolyLineOneColor(face(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.DrawPL(PL)
time.sleep(0.02)
def OSCljclient(value):
# Will receive message address, and message data flattened in s, x, y
print("I got /bank0/ljclient with value", value)
print("Bank0 got /bank0/ljclient with value", value)
ljclient = value
lj3.LjClient(ljclient)
def OSCpl(value):
print("Bank0 got /bank0/pl with value", value)
lj3.WebStatus("Bank0 to pl "+ str(value))
lj3.LjPl(value)
# Dancers, Starfield, Pose, Face
def OSCrun(value):
@ -619,10 +720,6 @@ def WebStatus(message):
lj3.SendLJ("/status",message)
#doit = Starfield
doit = Pose
#doit = Faces
#doit = Dancers
print('Loading Bank0...')
@ -636,15 +733,16 @@ osc_udp_server("127.0.0.1", OSCinPort, "InPort")
osc_method("/bank0/run*", OSCrun)
osc_method("/bank0/ping*", lj3.OSCping)
osc_method("/bank0/ljclient", OSCljclient)
osc_method("/bank0/ljpl", OSCpl)
osc_method("/quit", OSCquit)
'''
import pygame
pygame.init()
Nbpads = pygame.joystick.get_count()
print ("Joypads : ", str(Nbpads))
'''
if Nbpads != 2:
print ('')
@ -652,7 +750,6 @@ if Nbpads != 2:
print ("THIS VERSION NEEDS 2 PADS. PLEASE CONNECT THEM.")
print ('')
sys.exit()
'''
if Nbpads > 1:
@ -678,16 +775,22 @@ if Nbpads > 0:
#print ("Buttons Pad 1 :" , str(numButtons))
'''
anims =[[],[],[],[]]
color = lj3.rgb2int(255,255,255)
prepareSTARFIELD()
preparePOSE()
prepareDANCERS()
#prepareSTARFIELD()
#preparePOSE()
#prepareDANCERS()
prepareFACES()
#doit = Starfield
#doit = Pose
doit = Faces
#doit = Dancers
WebStatus("Bank0 ready.")
print("Bank0 ready")

439
plugins/VJing/idiotia.py Normal file
View file

@ -0,0 +1,439 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
LJ v0.8.1
IdiotIA for THSF 10
Include IdiotIA and Starfields
LICENCE : CC
Sam Neurohack, Loloster,
'''
import math
import numpy as np
import pdb
from datetime import datetime
from random import randrange
import redis
import lj3
import sys,time
import os
from osc4py3.as_eventloop import *
from osc4py3 import oscbuildparse
#from osc4py3 import oscmethod as osm
from osc4py3.oscmethod import *
import argparse
screen_size = [700,700]
xy_center = [screen_size[0]/2,screen_size[1]/2]
message = "LO"
OSCinPort = 8011
redisIP = '127.0.0.1'
ljclient = 0
print ("")
print ("Arguments parsing if needed...")
argsparser = argparse.ArgumentParser(description="Pose bank for LJ")
argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str)
argsparser.add_argument("-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.verbose:
debug = args.verbose
else:
debug = 0
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'
lj3.Config(redisIP,ljclient)
def hex2rgb(hexcode):
return tuple(map(ord,hexcode[1:].decode('hex')))
def rgb2hex(rgb):
return int('0x%02x%02x%02x' % tuple(rgb),0)
# IdiotIA
import json
CurrentPose = 1
# 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
else:
if debug > 0:
print("but it doesn't even exist!")
return 0
# get absolute face position points
def getFACE(pose_json,pose_points, people):
dots = []
for dot in pose_points:
if len(pose_json['people'][people]['face_keypoints_2d']) != 0:
#print "people 0"
if pose_json['people'][people]['face_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1] != -1:
dots.append((pose_json['people'][people]['face_keypoints_2d'][dot * 3], pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1]))
return dots
# 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]
return getFACE(pose_json,pose_points, people)
def browL(pose_json, people):
pose_points = [26,25,24,23,22]
return getFACE(pose_json,pose_points, people)
def browR(pose_json, people):
pose_points = [21,20,19,18,17]
return getFACE(pose_json,pose_points, people)
def eyeR(pose_json, people):
pose_points = [36,37,38,39,40,41,36]
return getFACE(pose_json,pose_points, people)
def eyeL(pose_json, people):
pose_points = [42,43,44,45,46,47,42]
return getFACE(pose_json,pose_points, people)
def nose(pose_json, people):
pose_points = [27,28,29,30]
return getFACE(pose_json,pose_points, people)
def mouth(pose_json, people):
pose_points = [48,59,58,57,56,55,54,53,52,51,50,49,48,60,67,66,65,64,63,62,61,60]
return getFACE(pose_json,pose_points, people)
def prepareIdiotIA():
WebStatus("Init IdiotIA...")
# anim format (name, xpos, ypos, resize, currentframe, totalframe, count, speed)
# 0 1 2 3 4 5 6 7
# total frames is fetched from directory by lengthPOSE()
anims[0] = [['detroit1', xy_center[0], xy_center[1], 300,0,0,0,5]]
anims[1] = [['detroit1', xy_center[0], xy_center[1] + 50, 400,0,0,0,15]]
anims[2] = [['detroit1', xy_center[0], xy_center[1] + 50, 500,0,0,0,25]]
anims[3] = [['detroit1', xy_center[0], xy_center[1], 500,0,0,0,25]]
for laseranims in anims:
for anim in laseranims:
anim[5] = lengthPOSE(anim[0])
if debug > 0:
print("anim :", 'poses/' + anim[0], "length :", anim[5], "frames")
# display the face animation describe in PoseDir
def IdiotIA():
for laseranims in range(3):
for anim in anims[laseranims]:
PL = laseranims
#print PL, anim
dots = []
# increase current frame [4] of speed [7] frames
anim[4] += 1
# compare to total frame [5]
if anim[4] >= anim[5]:
anim[4] = 0
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
posefile = open(posename , 'r')
posedatas = posefile.read()
pose_json = json.loads(posedatas)
# Face
for people in range(len(pose_json['people'])):
#lj3.rPolyLineOneColor(face(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
lj3.DrawPL(PL)
time.sleep(0.02)
# many starfields
def prepareSTARFIELD():
global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth
WebStatus("Init starfields...")
stars0=[]
stars1=[]
stars2=[]
#stars3=[]
num_stars = 50
max_depth = 20
stars = []
starfieldcount = 0
displayedstars = 5
starspeed = 0.05
for i in range(num_stars):
# A star is represented as a list with this format: [X,Y,Z]
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
stars0.append(star)
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
stars1.append(star)
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
stars2.append(star)
def Starfield(hori=0,verti=0):
global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth
starfieldcount += 1
#print starfieldcount
starpoints = []
#print displayedstars, 'stars displayed'
# Increase number of
if displayedstars < num_stars and starfieldcount % 15 == 0:
displayedstars += 1
if displayedstars == num_stars and starfieldcount % 10 == 0:
starspeed += 0.005
#print starspeed
for starnumber in range(0,displayedstars):
# The Z component is decreased on each frame.
stars0[starnumber][2] -= starspeed * 3
stars1[starnumber][2] -= starspeed * 3
stars2[starnumber][2] -= starspeed * 3
# If the star has past the screen (I mean Z<=0) then we
# reposition it far away from the screen (Z=max_depth)
# with random X and Y coordinates.
if stars0[starnumber][2] <= 0:
stars0[starnumber][0] = randrange(-25,25)
stars0[starnumber][1] = randrange(-25,25)
stars0[starnumber][2] = max_depth
if stars1[starnumber][2] <= 0:
stars1[starnumber][0] = randrange(-25,25)
stars1[starnumber][1] = randrange(-25,25)
stars1[starnumber][2] = max_depth
if stars2[starnumber][2] <= 0:
stars2[starnumber][0] = randrange(-25,25)
stars2[starnumber][1] = randrange(-25,25)
stars2[starnumber][2] = max_depth
# Convert the 3D coordinates to 2D using perspective projection.
k0 = 128.0 / stars0[starnumber][2]
k1 = 128.0 / stars1[starnumber][2]
k2 = 128.0 / stars2[starnumber][2]
# Move Starfield origin.
# if stars xpos/ypos is same sign (i.e left stars xpos is <0) than (joystick or code) acceleration (hori and verti moves the star field origin)
if np.sign(stars0[starnumber][0]) == np.sign(hori):
x0 = int(stars0[starnumber][0] * k0 + xy_center[0] + (hori*600))
else:
x0 = int(stars0[starnumber][0] * k0 + xy_center[0] + (hori*500))
if np.sign(stars0[starnumber][1]) == np.sign(verti):
y0 = int(stars0[starnumber][1] * k0 + xy_center[1] + (verti*600))
else:
y0 = int(stars0[starnumber][1] * k0 + xy_center[1] + (verti*500))
if np.sign(stars1[starnumber][0]) == np.sign(hori):
x1 = int(stars1[starnumber][0] * k1 + xy_center[0] + (hori*600))
else:
x1 = int(stars1[starnumber][0] * k1 + xy_center[0] + (hori*300))
if np.sign(stars1[starnumber][1]) == np.sign(verti):
y1 = int(stars1[starnumber][1] * k1 + xy_center[1] + (verti*600))
else:
y1 = int(stars1[starnumber][1] * k1 + xy_center[1] + (verti*300))
if np.sign(stars2[starnumber][0]) == np.sign(hori):
x2 = int(stars2[starnumber][0] * k2 + xy_center[0] + (hori*600))
else:
x2 = int(stars2[starnumber][0] * k2 + xy_center[0] + (hori*300))
if np.sign(stars2[starnumber][1]) == np.sign(verti):
y2 = int(stars2[starnumber][1] * k2 + xy_center[1] + (verti*600))
else:
y2 = int(stars2[starnumber][1] * k2 + xy_center[1] + (verti*300))
# Add star to pointlist PL 0
if 0 <= x0 < screen_size[0] - 2 and 0 <= y0 < screen_size[1] - 2:
lj3.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c = white, PL = 0, closed = False)
# Add star to pointlist PL 1
if 0 <= x1 < screen_size[0] - 2 and 0 <= y1 < screen_size[1] - 2:
lj3.PolyLineOneColor([(x1,y1),((x1+1),(y1+1))], c = white, PL = 1, closed = False)
# Add star to pointlist PL 2
if 0 <= x2 < screen_size[0] - 2 and 0 <= y2 < screen_size[1] - 2:
lj3.PolyLineOneColor([(x2,y2),((x2+1),(y2+1))], c= white, PL = 2, closed = False)
'''
if starfieldcount < 200:
if 0 <= x3 < screen_size[0] - 2 and 0 <= y3 < screen_size[1] - 2:
fwork.PolyLineOneColor([(x3,y3),((x3+2),(y3+2))], c=colorify.rgb2hex([255,255,255]), PL = 3, closed = False)
'''
lj3.Text(message, white, PL = 3, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
lj3.DrawPL(0)
lj3.DrawPL(1)
lj3.DrawPL(2)
lj3.DrawPL(3)
def OSCidiotia(address, value):
print("Pose bank idiotia got", address, "with value", value)
def OSCfield(address, value):
print("Pose bank field got", address, "with value", value)
def OSCljclient(value):
print("Pose bank got /pose/ljclient with value", value)
ljclient = value
lj3.LjClient(ljclient)
def OSCpl(value):
print("Pose bank got /pose/pl with value", value)
lj3.WebStatus("Pose bank to pl "+ str(value))
lj3.LjPl(value)
# Starfield, idiotia
def OSCrun(value):
# Will receive message address, and message data flattened in s, x, y
print("Pose bank got /run with value", value)
doit = value
# /quit
def OSCquit():
WebStatus("Pose bank stopping")
print("Stopping OSC...")
lj3.OSCstop()
sys.exit()
def WebStatus(message):
lj3.SendLJ("/status",message)
print('Loading Pose bank...')
WebStatus("Loading Pose bank...")
# OSC Server callbacks
print("Starting OSC at 127.0.0.1 port",OSCinPort,"...")
osc_startup()
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
osc_method("/pose/run*", OSCrun)
osc_method("/pose/ping*", lj3.OSCping)
osc_method("/pose/ljclient", OSCljclient)
osc_method("/pose/ljpl", OSCpl)
osc_method("/quit", OSCquit)
osc_method("/pose/idiotia*", OSCidiotia, argscheme=OSCARG_ADDRESS + OSCARG_DATA)
osc_method("/pose/field*", OSCfield, argscheme=OSCARG_ADDRESS + OSCARG_DATA)
anims =[[],[],[],[]]
color = lj3.rgb2int(255,255,255)
prepareIdiotIA()
#prepareSTARFIELD()
#doit = Starfield
doit = IdiotIA
white = lj3.rgb2int(255,255,255)
red = lj3.rgb2int(255,0,0)
blue = lj3.rgb2int(0,0,255)
green = lj3.rgb2int(0,255,0)
WebStatus("Pose bank running.")
print("Pose bank running")
def Run():
try:
while 1:
#Starfield(hori=0,verti=0)
doit()
except KeyboardInterrupt:
pass
# Gently stop on CTRL C
finally:
WebStatus("Pose bank Exit")
print("Stopping OSC...")
lj3.OSCstop()
print ("Pose bank Stopped.")
Run()

View file

@ -1,7 +1,9 @@
# coding=UTF-8
'''
LJ v0.8.1 in python3
lj3 v0.8.1
Some LJ functions useful for python clients (was framy.py)
OSC functions commented, waiting working on OSC in python3
@ -11,24 +13,28 @@ 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
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():
OSCstop(): Properly close the OSC system
OSCping(value): Answer to LJ pings
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):
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
CSLController : getLeftHori,getLeftVert,getRightHori, getRightVert,getLeftTrigger,getRightTrigger,getFire1,getFire2
my USB Joystick : getUp,getDown,getLeft,getRight,etLeftTrigger, getRightTrigger,getFire1, getFire2
LICENCE : CC
@ -42,6 +48,8 @@ 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'
@ -69,6 +77,7 @@ def OSCframe():
def OSCstop():
osc_terminate()
def SendLJ(oscaddress,oscargs=''):
try:
@ -80,13 +89,24 @@ def SendLJ(oscaddress,oscargs=''):
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("I got /ping with value", value)
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):
@ -216,7 +236,11 @@ def LjClient(client):
global ClientNumber
ClientNumber = client
def LjPl(pl):
global PL
PL = pl
def LineTo(xy, c, PL):
@ -320,7 +344,6 @@ def ResetPL(self, PL):
pl[PL] = []
def DigitsDots(number,color):
dots =[]
for dot in ASCII_GRAPHICS[number]:
@ -329,6 +352,7 @@ def DigitsDots(number,color):
#self.point_list.append((xy + (c,)))
return dots
def CharDots(char,color):
dots =[]
@ -336,6 +360,7 @@ def CharDots(char,color):
dots.append((dot[0],dot[1],color))
return dots
def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz):
dots =[]

View file

@ -112,7 +112,7 @@ LOGO = [
LOGO_OFFSET_X = 460
LOGO_OFFSET_Y = 250
def LogoDraw():
def LogoDraw(plnumber):
'''
Dessine le logo
'''
@ -122,8 +122,7 @@ def LogoDraw():
for xy in pl_color[0]:
xy_list.append((LOGO_OFFSET_X + xy[0], LOGO_OFFSET_Y + xy[1]))
#print xy_list
lj.PolyLineOneColor(xy_list, c,0, False)
lj.PolyLineOneColor(xy_list, c, plnumber, False)
@ -190,23 +189,23 @@ def FlipsMoveJoy(left_key,right_key,up_key,down_key,lvertax):
FlipsLy = screen_size[1] - PADDLE_height
return FlipsLy, FlipsRy
def FlipsDraw():
def FlipsDraw(plnumber):
lj.PolyLineOneColor([(FlipsLx,FlipsLy),(FlipsLx,FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width , FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width,FlipsLy)], white,0,True)
lj.PolyLineOneColor([(FlipsRx,FlipsRy),(FlipsRx,FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width , FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width,FlipsRy)], white,0,True)
lj.PolyLineOneColor([(FlipsLx,FlipsLy),(FlipsLx,FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width , FlipsLy + PADDLE_height),(FlipsLx + PADDLE_width,FlipsLy)], white, plnumber, True)
lj.PolyLineOneColor([(FlipsRx,FlipsRy),(FlipsRx,FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width , FlipsRy + PADDLE_height),(FlipsRx + PADDLE_width,FlipsRy)], white, plnumber, True)
def FiletDraw():
lj.PolyLineOneColor([(screen_size[0]/2,screen_size[1]),(screen_size[0]/2,0)], white, 0,True)
def FiletDraw(plnumber):
lj.PolyLineOneColor([(screen_size[0]/2,screen_size[1]),(screen_size[0]/2,0)], white, plnumber,True)
def Score1Draw(score):
def Score1Draw(score, plnumber):
#print "score1",score
lj.Text(str(score),white, 0, 350, 50, 1, 0, 0, 0)
lj.Text(str(score),white, plnumber, 350, 50, 1, 0, 0, 0)
def Score2Draw(score):
def Score2Draw(score, plnumber):
#print "score2",score
lj.Text(str(score),white, 0, 500, 50, 1, 0, 0, 0)
lj.Text(str(score),white, plnumber, 500, 50, 1, 0, 0, 0)
@ -235,7 +234,7 @@ def BallMove(xcoord,ycoord):
elif BallY >= screen_size[1]:
BallY = screen_size[1]
def BallDraw():
def BallDraw(plnumber):
global BallX,BallY
xmin = 0
@ -255,5 +254,5 @@ def BallDraw():
#print "ball position",xmin,xmax,ymin,ymax
lj.PolyLineOneColor([(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)], white,0,True)
lj.PolyLineOneColor([(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)], white, plnumber, True)

View file

@ -1,15 +1,21 @@
# coding=UTF-8
'''
LJ v0.8.0
Some LJ functions useful for python clients (was framy.py)
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
SendLJ : remote control
LjClient :
LjPl :
DrawPL
WebStatus
LICENCE : CC
Sam Neurohack
@ -29,21 +35,14 @@ point_list = []
pl = [[],[],[],[]]
'''
LJIP = "127.0.0.1"
osclientlj = OSCClient()
oscmsg = OSCMessage()
osclientlj.connect((redisIP, 8002))
'''
def sendlj(oscaddress,oscargs=''):
def SendLJ(oscaddress,oscargs=''):
oscmsg = OSCMessage()
oscmsg.setAddress(oscaddress)
oscmsg.append(oscargs)
#print ("sending to bhorosc : ",oscmsg)
print ("sending OSC message : ",oscmsg)
try:
osclientlj.sendto(oscmsg, (redisIP, 8002))
oscmsg.clearData()
@ -52,7 +51,8 @@ def sendlj(oscaddress,oscargs=''):
pass
#time.sleep(0.001
def WebStatus(message):
SendLJ("/status", message)
ASCII_GRAPHICS = [
@ -158,6 +158,17 @@ def Config(redisIP,client):
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):
@ -248,6 +259,7 @@ 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:

View file

@ -13,6 +13,7 @@ import math
import itertools
import sys
import os
import types
'''
is_py2 = sys.version[0] == '2'
@ -30,6 +31,9 @@ import entities
from controller import setup_controls
import argparse
from OSC import OSCServer, OSCClient, OSCMessage
OSCIP = "127.0.0.1"
OSCPort = 8020
score = None
@ -87,6 +91,9 @@ red = rgb2int(255,0,0)
blue = rgb2int(0,0,255)
green = rgb2int(0,255,0)
#
# Arguments handling
#
print ("")
print ("Arguments parsing if needed...")
@ -129,11 +136,17 @@ def StartPlaying(first_time = False):
app_path = os.path.dirname(os.path.realpath(__file__))
#
# Pads via pygame
#
print "Pygame init..."
pygame.init()
#sounds.InitSounds()
clock = pygame.time.Clock()
Nbpads = pygame.joystick.get_count()
print ("Joypads : ", str(Nbpads))
@ -184,6 +197,66 @@ y = ball_origin[1]
keystates = pygame.key.get_pressed()
#
# OSC
#
oscserver = OSCServer( (OSCIP, OSCPort) )
oscserver.timeout = 0
OSCRunning = True
def OSCljclient(path, tags, args, source):
print("LJ Pong 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):
print("LJ Pong got /ljpong/pl with value", args[0])
lj.WebStatus("LJPong to pl "+ str(args[0]))
plnumber = args[0]
# /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
oscserver.timed_out = False
# handle all pending requests then return
while not oscserver.timed_out:
oscserver.handle_request()
def handle_timeout(self):
self.timed_out = True
print ""
print "Launching OSC server..."
print "at", OSCIP, "port",str(OSCPort)
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
# OSC callbacks
oscserver.addMsgHandler( "/ljpong/ljclient", OSCljclient )
oscserver.addMsgHandler("/ljpong/pl", OSCpl)
oscserver.addMsgHandler("/ping", OSCping)
print "Running..."
#
# Game main loop
#
while fs != GAME_FS_QUIT:
@ -192,6 +265,8 @@ while fs != GAME_FS_QUIT:
if event.type == pygame.QUIT:
fs = GAME_FS_QUIT
OSC_frame()
keystates_prev = keystates[:]
keystates = pygame.key.get_pressed()[:]
@ -346,21 +421,19 @@ while fs != GAME_FS_QUIT:
if fs == GAME_FS_PLAY or fs == GAME_FS_GAMEOVER or fs == GAME_FS_LAUNCH:
entities.Score1Draw(lscore)
entities.Score2Draw(rscore)
entities.FlipsDraw()
entities.BallDraw()
entities.FiletDraw()
lj.DrawPL(0)
entities.Score1Draw(lscore, plnumber)
entities.Score2Draw(rscore, plnumber)
entities.FlipsDraw(plnumber)
entities.BallDraw(plnumber)
entities.FiletDraw(plnumber)
lj.DrawPL(plnumber)
if fs == GAME_FS_MENU:
entities.LogoDraw()
lj.DrawPL(0)
entities.LogoDraw(plnumber)
lj.DrawPL(plnumber)
# TODO : rendre indépendante la fréquence de rafraîchissement de l'écran par
# rapport à celle de l'animation du jeu
clock.tick(100)
pygame.quit()

244
plugins/laserglyph.py Normal file
View file

@ -0,0 +1,244 @@
# coding=UTF-8
'''
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
'''
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
print ("")
print ("Arguments parsing if needed...")
argsparser = argparse.ArgumentParser(description="Text Cycling for LJ")
argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str)
argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int)
argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int)
argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int)
args = argsparser.parse_args()
if args.client:
ljclient = args.client
else:
ljclient = 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'
if args.verbose:
debug = args.verbose
else:
debug = 0
lj3.Config(redisIP,ljclient)
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.
eye_spacing = 100
nadir = 0.5
observer_altitude = 30000
#observer_altitude = 10000
# elevation = z coordinate
# 0.0, -2000 pop out
map_plane_altitude = 0.0
# Cube coordinates
# Define the vertices that compose each of the 6 faces.
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),
(- 1.0, 1.0, 1.0),
( 1.0, 1.0, 1.0),
( 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)]
def LeftShift(elevation):
diff = elevation - map_plane_altitude
return nadir * eye_spacing * diff / (observer_altitude - elevation)
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):
print("Glyph got /glyph/ljclient with value", value)
lj3.WebStatus("Glyph to virtual "+ str(value))
ljclient = value
lj3.LjClient(ljclient)
def OSCpl(value):
print("Glyph got /glyph/pl with value", value)
lj3.WebStatus("Glyph to pl "+ str(value))
lj3.LjPl(value)
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)
def Run():
Left = []
Right = []
counter =0
WebStatus("LaserGlyph")
# OSC Server callbacks
print("Starting OSC at 127.0.0.1 port",OSCinPort,"...")
osc_startup()
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
osc_method("/ping*", lj3.OSCping)
osc_method("/glyph/ljclient", OSCljclient)
try:
while 1:
Left = []
Right = []
x = vertices[0][0]
y = vertices[0][1]
z = vertices[0][2]
# The cube start always with vertice 0
# 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.
# Cube Y axis rotation of 'counter' angle and 3d-2d Proj function.
#Left.append( Proj(x+LeftShift(z*5),y,z,0,counter,0))
#Right.append(Proj(x+RightShift(z*5),y,z,0,counter,0))
# Add all the cube points face by face.
for fa in faces:
for point in fa:
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))
# 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)
'''
# 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)
'''
time.sleep(0.1)
counter += 1
if counter >360:
counter =0
except KeyboardInterrupt:
pass
# Gently stop on CTRL C
finally:
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)
Run()

View file

@ -94,10 +94,12 @@ def OSCword3(value):
def OSCljclient(value):
# Will receive message address, and message data flattened in s, x, y
print("Words got /words/ljclient with value", value)
lj3.WebStatus("Words to virtual "+ str(value))
ljclient = value
lj3.LjClient(ljclient)
# /ping
def OSCping():
@ -108,7 +110,7 @@ def OSCping():
# /quit
def OSCquit():
lj3.OSCquit("Words")
lj3.OSCquit("words")
def Run():
@ -122,7 +124,7 @@ def Run():
osc_method("/words/text/2*", OSCword2)
osc_method("/words/text/3*", OSCword3)
osc_method("/ping*", OSCping)
osc_method("/words/ljclient", OSCljclient)
osc_method("/words/ljclient*", OSCljclient)
osc_method("/quit", OSCquit)
color = lj3.rgb2int(255,255,255)

View file

@ -17,6 +17,9 @@ 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
@ -233,7 +236,11 @@ def LjClient(client):
global ClientNumber
ClientNumber = client
def LjPl(pl):
global PL
PL = pl
def LineTo(xy, c, PL):

View file

@ -67,7 +67,7 @@ def SendLJ(oscaddress,oscargs=''):
# Answer to LJ pings
def OSCping(value):
# Will receive message address, and message data flattened in s, x, y
print("I got /ping with value", value)
SendLJ("/pong",value)
@ -190,6 +190,9 @@ def Config(redisIP,client):
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):
@ -308,13 +311,13 @@ def CharDots(char,color):
dots.append((dot[0],dot[1],color))
return dots
def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz):
def Text(message, c, PL, xpos, ypos, resize, rotx, roty, rotz):
dots =[]
l = len(message)
i= 0
#print message
#print (message)
for ch in message:
@ -333,10 +336,10 @@ def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz):
for xy in char_pl_list:
char_draw.append((xy[0] + x_offset,xy[1],c))
i +=1
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)
# print ("laser",PL,"message",message)
#dots.append(char_draw)

View file

@ -17,7 +17,7 @@ Todo:
- use debug mode and check altaz calculated values against online sites.
- Validate aa2radec() with online calculator. Rewrite it to remove need for Astropy.
- Findout how to use OSC in python 3.
-
- North sky is hardcoded.
- Code WebUI page.
- UpdateStars() in each laser sky. Get magnitude. See UpdateSolar for example.
- All Draw operations should also check visibility in the given laser altitude range.
@ -33,10 +33,12 @@ import lj3
import numpy as np
import math,time
print("Importing astropy...")
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
from astropy import units as u
from astropy.time import Time
print("Importing skyfield...")
from skyfield.api import Star, load, Topos,Angle
from skyfield.data import hipparcos
@ -45,10 +47,6 @@ from osc4py3 import oscbuildparse
#from osc4py3 import oscmethod as osm
from osc4py3.oscmethod import *
import json
'''
@ -65,14 +63,12 @@ else:
import argparse
print ("")
print ("Arguments parsing if needed...")
argsparser = argparse.ArgumentParser(description="Planetarium 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("-c","--client",help="LJ client number (0 by default)",type=int)
argsparser.add_argument("-L","--Lasers",help="Number of lasers connected (1 by default).",type=int)
argsparser.add_argument("-L","--Lasers",help="Number of lasers connected (4 by default).",type=int)
argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int)
argsparser.add_argument("-i","--input",help="inputs OSC Port (8005 by default)",type=int)
#argsparser.add_argument("-n","--name",help="City Name of the observer",type=str)
@ -89,7 +85,7 @@ else:
if args.Lasers:
lasernumber = args.Lasers
else:
lasernumber = 1
lasernumber = 4
if args.verbose:
debug = args.verbose
@ -178,10 +174,17 @@ def Proj(x,y,z,angleX,angleY,angleZ):
def aa2radec(azimuth, altitude, t):
#AstrObserver = EarthLocation(lat=lati * u.deg, lon=longi *u.deg, height= elevation*u.m,)
ObjectCoord = SkyCoord(alt = altitude * u.deg, az = azimuth *u.deg, obstime = t, frame = 'altaz', location = AstrObserver)
#print("Oserver",AstrObserver )
print("time",t)
ObjectCoord = SkyCoord(alt = altitude * u.deg, az = azimuth * u.deg, obstime = t, frame = 'altaz', location = AstrObserver)
#print("icrs",ObjectCoord.icrs)
print("Altitude", altitude)
print("Altitude", altitude * u.deg)
print("Azimuth", azimuth)
print("Azimuth", azimuth * u.deg)
#print("ICRS Right Ascension", ObjectCoord.icrs.ra)
#print("ICRS Declination", ObjectCoord.icrs.dec)
#print()
return ObjectCoord.icrs.ra.degree, ObjectCoord.icrs.dec.degree
@ -227,16 +230,20 @@ def RadecSkies(LaserSkies, AstroSkyTime):
print()
print("Converting", lasernumber, "LaserSkies limits in Right Ascension & Declination (radec) coordinates ")
for laser in range(lasernumber):
if debug > 0:
print ("")
print("Laser",laser)
# Left top point
LaserSkies[laser][4],LaserSkies[laser][6] = aa2radec(azimuth = LaserSkies[laser][0], altitude =LaserSkies[laser][2], t =AstroSkyTime)
if debug > 0:
print(LaserSkies[laser][4],LaserSkies[laser][6])
# Right Bottom point
LaserSkies[laser][5],LaserSkies[laser][7] = aa2radec(azimuth = LaserSkies[laser][1], altitude =LaserSkies[laser][3], t =AstroSkyTime)
if debug > 0:
print(LaserSkies[laser][5],LaserSkies[laser][7])
print("Top left Altaz :",LaserSkies[laser][2],LaserSkies[laser][0])
print("Top left radec :",LaserSkies[laser][4],LaserSkies[laser][6])
print("Bottom right Altaz :",LaserSkies[laser][3],LaserSkies[laser][1])
print("Bottom right radec :",LaserSkies[laser][5],LaserSkies[laser][7])
if debug > 0:
print(LaserSkies)
print ("Done.")
@ -248,7 +255,10 @@ def azimuth2scrX(leftAzi,rightAzi,s):
b1, b2 = 0, width
#if debug > 0:
# print(leftAzi, rightAzi, s, b1 + ((s - a1) * (b2 - b1) / (a2 - a1)))
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
if s != 0:
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
else:
return width/2
@ -297,7 +307,7 @@ def LoadSolar():
def UpdateSolar():
global SolarObjects
# Compute Alt Az coordinates for all solar objects for obsehttps://www.startpage.com/do/searchrver.
# Compute Alt Az coordinates for all solar objects for Observer.
for number,object in enumerate(SolarObjects):
#print(object[0],number)
@ -305,13 +315,11 @@ def UpdateSolar():
if debug > 0:
PrintSolar()
def PrintSolar():
for number,object in enumerate(SolarObjects):
print (SolarObjects[number][0],"is at (alt,az)",SolarObjects[number][1],SolarObjects[number][2])
# Draw the SolarShapeObject for any Solar object is in the laser Sky
def DrawSolar(laser):
@ -363,12 +371,11 @@ def StarSelect():
for index in range(len(Starnames)-1):
StarsObjects.append([Starnames[index+1],0,0])
def UpdateStars(ts):
global StarsObjects
hipparcos_epoch = ts.tt(1991.25)
# Compute Alt Az coordinates for all solar objects for obsehttps://www.startpage.com/do/searchrver.
# Compute Alt Az coordinates for all stars objects for Observer.
for number,object in enumerate(StarsObjects):
#print(object[0],number)
@ -405,7 +412,7 @@ def DrawStars(laser):
#
# Anything system. Say you want
# Template for Anything you want system.
#
AnythingObjectShape = [(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)]
@ -433,13 +440,11 @@ def UpdateAnything():
if debug > 0:
PrintAnything()
def PrintAnything():
for number,object in enumerate(AnythingObjects):
print (AnythingObjects[number][0],"is at (alt,az)",AnythingObjects[number][1],AnythingObjects[number][2])
# Draw the AnythingShapeObject for any Anything object is in the laser Sky
def DrawAnything(laser):
@ -453,12 +458,11 @@ def DrawAnything(laser):
#
# On Earth Gps positions
# from https://github.com/lutangar/cities.json
#
def LoadCities():
global world
@ -493,8 +497,7 @@ def DrawOrientation(laser):
# North direction is in given laser sky azimuth range?
if LaserSkies[laser][1] < LaserSkies[laser][0]:
#print ("N az",azimuth2scrX(LaserSkies[laser][0],LaserSkies[laser][1],0))
lj3.Text("NORTH",white,laser,azimuth2scrX(LaserSkies[laser][0],LaserSkies[laser][1],359), 770, resize = 0.5, rotx =0, roty =0 , rotz=0)
lj3.Text("NORTH",white,laser,azimuth2scrX(LaserSkies[laser][0],LaserSkies[laser][1],0), 770, resize = 0.5, rotx =0, roty =0 , rotz=0)
# East direction is in given laser sky azimuth range ?
if LaserSkies[laser][0] <= 90 < LaserSkies[laser][1]:
@ -546,7 +549,9 @@ def InitObserver(SkyCity, SkyCountryCode, time,ts):
# to later select their visible objects in radec catalogs like hipparcos.
# LaserSky definition for one laser (in decimal degrees) : [RightAzi, LeftAzi, TopAlt, BotAlt, LeftRa, RightRa, TopDec, BottomDec]
# With 4 lasers with each one a quarter of the 360 ° real sky, there is 4 LaserSky :
LaserSkies = [[45,135.0,90.0,0.0,0.0,0.0,0.0,0.0],[135,225,90,0,0,0,0,0],[225,315,90,0,0,0,0,0],[305,0,90,0,0,0,0,0]]
print()
print("LaserSkies Radec conversion")
LaserSkies = [[45,135.0,90.0,0.0,0.0,0.0,0.0,0.0],[135,225,90,0,0,0,0,0],[225,315,90.0,0,0,0,0,0],[315,45,90.0,0,0,0,0,0]]
RadecSkies(LaserSkies, AstroSkyTime)
@ -612,7 +617,7 @@ try:
osc_method("/ping*", lj3.OSCping)
osc_method("/quit", OSCquit)
WebStatus("Load Cities.")
WebStatus("Loading Cities...")
ts = load.timescale()
LoadCities()
@ -620,17 +625,17 @@ try:
SkyCountryCode = 'FR'
WebStatus(SkyCity)
WebStatus("Solar System..")
WebStatus("Loading Solar System...")
LoadSolar()
WebStatus("Observer..")
WebStatus("Finding observer position..")
InitObserver(SkyCity, SkyCountryCode, Time.now(),ts)
WebStatus("Load Stars..")
WebStatus("Loading Stars...")
LoadHipparcos(ts)
StarSelect()
WebStatus("Updating...")
WebStatus("Computing observer skies")
print("Updating solar system (de421) objects position for observer at", Skylat, Skylong, "time", SkyfieldTime.utc_iso())
UpdateSolar()

View file

@ -74,14 +74,22 @@ def rgb2int(r,g,b):
def WebStatus(message):
lj3.SendLJ("/status",message)
def OSCljclient(value):
# Will receive message address, and message data flattened in s, x, y
print("I got /cycl/ljclient with value", value)
print("Cycl got /cycl/ljclient with value", value)
lj3.WebStatus("Cycl to virtual "+ str(value))
ljclient = value
lj3.LjClient(ljclient)
def OSCpl(value):
print("Cycl got /cycl/pl with value", value)
lj3.WebStatus("Cycl to pl "+ str(value))
lj3.LjPl(value)
# /ping
def OSCping():
@ -91,15 +99,15 @@ def OSCping():
# /quit
def OSCquit():
lj3.OSCquit("Cycl")
lj3.OSCquit("cycl")
osc_startup()
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
osc_method("/ping*", OSCping)
osc_method("/quit", OSCquit)
osc_method("/cycl/ljclient", OSCljclient)
osc_method("/cycl/ljclient*", OSCljclient)
osc_method("/cycl/pl*", OSCpl)
WebStatus("Textcycl Ready")
lj3.SendLJ("/cycl/start 1")