forked from protonphoton/LJ
First commit
This commit is contained in:
commit
68b0e81a95
36 changed files with 6152 additions and 0 deletions
114
clients/framy.py
Normal file
114
clients/framy.py
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
LJay v0.8.0
|
||||
|
||||
|
||||
LICENCE : CC
|
||||
pclf, Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
|
||||
redisIP = '192.168.1.13'
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
point_list = []
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
# set all points for given laser. special behavior depends on GridDisplay flag
|
||||
# 0: point list / 1: Grid
|
||||
def LinesPL(PL):
|
||||
|
||||
if r.set('/pl/'+str(PL), str(pl[PL])) == True:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def ResetPL(self, PL):
|
||||
pl[PL] = []
|
||||
91
clients/nodeclient.js
Normal file
91
clients/nodeclient.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
// Send points lists to redis server
|
||||
// In compatible LJay string format (pythonic lists)
|
||||
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient(6379,'192.168.1.13');
|
||||
|
||||
|
||||
|
||||
function rgb2int(r,g,b) {
|
||||
// Generate color from r g b components
|
||||
var color = hex(r) + hex(g) + hex(b);
|
||||
return parseInt(color, 16)
|
||||
}
|
||||
|
||||
function hex(v) {
|
||||
// Get hexadecimal numbers.
|
||||
var hex = v.toString(16);
|
||||
if (v < 16) {
|
||||
hex = "0" + hex;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
// add one dot to Laser 0 point list
|
||||
function adddot0(dotdata){
|
||||
var dotstring = "(" + dotdata + "),";
|
||||
pl0 += dotstring;
|
||||
}
|
||||
|
||||
// add one dot to Laser 1 point list
|
||||
function adddot1(dotdata){
|
||||
var dotstring = "(" + dotdata + "),";
|
||||
pl1 += dotstring;
|
||||
}
|
||||
|
||||
// Generate same square to laser 0 and laser 1
|
||||
function GenPoints()
|
||||
{
|
||||
var pt = {};
|
||||
|
||||
// direct colors, i.e red
|
||||
pt.r = 255;
|
||||
pt.g = 0;
|
||||
pt.b = 0;
|
||||
|
||||
// named colors
|
||||
var white = rgb2int(255, 255, 255);
|
||||
|
||||
pt.x = 100;
|
||||
pt.y = 200;
|
||||
adddot0([pt.x, pt.y, rgb2int(pt.r, pt.g, pt.b)]);
|
||||
adddot1([pt.x, pt.y, rgb2int(pt.r, pt.g, pt.b)]);
|
||||
|
||||
pt.x = 100;
|
||||
pt.y = 300;
|
||||
adddot0([pt.x, pt.y, white]);
|
||||
adddot1([pt.x, pt.y, white]);
|
||||
|
||||
pt.x = 200;
|
||||
pt.y = 300;
|
||||
adddot0([pt.x, pt.y, white]);
|
||||
adddot1([pt.x, pt.y, white]);
|
||||
|
||||
pt.x = 200;
|
||||
pt.y = 200;
|
||||
adddot0([pt.x, pt.y, white]);
|
||||
adddot1([pt.x, pt.y, white]);
|
||||
|
||||
pt.x = 100;
|
||||
pt.y = 200;
|
||||
adddot0([pt.x, pt.y, white]);
|
||||
adddot1([pt.x, pt.y, white]);
|
||||
}
|
||||
|
||||
// Point lists strings
|
||||
var pl0 = "[";
|
||||
var pl1 = "[";
|
||||
GenPoints();
|
||||
pl0 = pl0.slice(0,-1) + "]"
|
||||
pl1 = pl1.slice(0,-1) + "]"
|
||||
|
||||
console.log(pl0);
|
||||
console.log(pl1);
|
||||
|
||||
// Send points lists to redis server
|
||||
client.set("/pl/0",pl0);
|
||||
client.set("/pl/1",pl1);
|
||||
|
||||
// Quit
|
||||
client.quit()
|
||||
|
||||
56
clients/pyclient.py
Normal file
56
clients/pyclient.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
Multi Laser client example
|
||||
|
||||
LICENCE : CC
|
||||
'''
|
||||
|
||||
import redis
|
||||
|
||||
# IP defined in /etd/redis/redis.conf
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
# (x,y,color in integer) 65280 is color #00FF00
|
||||
# Green rectangular shape :
|
||||
pl0 = [(100,300,65280),(200,300,65280),(200,200,65280),(100,200,65280)]
|
||||
|
||||
|
||||
# If you want to use rgb for color :
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
# White rectangular shape
|
||||
pl1 = [(100,300,rgb2int(255,255,255)),(200,300,rgb2int(255,255,255)),(200,200,rgb2int(255,255,255)),(100,200,rgb2int(255,255,255))]
|
||||
|
||||
# Send to laser 0 (see mainy.conf)
|
||||
r.set('/pl/0', str(pl0))
|
||||
|
||||
# Send to laser 1 (see mainy.conf)
|
||||
r.set('/pl/1', str(pl1))
|
||||
|
||||
r.set('/pl/2', str(pl1))
|
||||
|
||||
'''
|
||||
You can also use PolyLineOneColor or rPolylineOneColor to stack n point lists to build a "frame"
|
||||
|
||||
import framy
|
||||
|
||||
# for laser0 :
|
||||
|
||||
pl0 = [(100,300),(200,300),(200,200),(100,200)]
|
||||
framy.PolyLineOneColor(pl0, rgb2int(255,255,255), 0 , closed = False)
|
||||
# You can add as much polylineOneColor as you want = construct a "frame"
|
||||
# Then send it to the laser server :
|
||||
print "All one color lines sent to laser 0 :",framy.LinesPL(0) # Will be True is sent correctly
|
||||
|
||||
# instead of PolyLineOneColor you can use rPolylineOneColor to send 2D point list around 0,0 with 3D rotation,resizing and repositioning at xpos ypos
|
||||
# rPolylineOneColor is very useful to add different polylines to different position. Imagine different game elements.
|
||||
# rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0):
|
||||
# Send the pl0 to laser 1
|
||||
|
||||
framy.rPolyLineOneColor((pl0, c = rgb2int(255,255,255), PL = 1, closed = False, xpos = 200, ypos = 250, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
print "All one color lines sent to laser 1 :",framy.LinesPL(1) # Will be True is sent correctly
|
||||
'''
|
||||
39
clients/rebclient.r
Normal file
39
clients/rebclient.r
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
REBOL []
|
||||
|
||||
outport: open/lines tcp://localhost:13857
|
||||
on: 1
|
||||
off: 0
|
||||
|
||||
pl0: "[(100,200, 0), (100,300, 65280), (200,300, 65280), (200,200, 65280), (100,200, 65280)]"
|
||||
|
||||
|
||||
oscommand: to-string reduce ["pl/0 " pl0]
|
||||
insert outport oscommand
|
||||
|
||||
for counter 1 2 1 [
|
||||
;; print counter
|
||||
oscommand: to-string reduce ["/40h/clear " on]
|
||||
insert outport oscommand
|
||||
wait 0.3
|
||||
|
||||
]
|
||||
|
||||
for counter 1 2 1 [
|
||||
for raw 0 7 1 [
|
||||
oscommand: to-string reduce ["/40h/led_row " raw " " on]
|
||||
insert outport oscommand
|
||||
wait 0.001
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
for counter 1 2 1 [
|
||||
;; print counter
|
||||
oscommand: to-string reduce ["/40h/frame 0 126 126 126 126 126 126 0"]
|
||||
insert outport oscommand
|
||||
|
||||
wait 0.3
|
||||
|
||||
]
|
||||
|
||||
close outport
|
||||
47
clients/rebserver.py
Normal file
47
clients/rebserver.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
"""
|
||||
|
||||
TCP server for rebol links like from Amiga
|
||||
Forward /pl/lasernumber pointslist to redis server
|
||||
|
||||
|
||||
by Sam Neurohack
|
||||
from /team/laser
|
||||
|
||||
"""
|
||||
|
||||
import socket, time,random, redis
|
||||
|
||||
|
||||
r = redis.StrictRedis(host=gstt.LjayServerIP, port=6379, db=0)
|
||||
|
||||
|
||||
|
||||
# TCP listener
|
||||
|
||||
TCP_IP = '127.0.0.1'
|
||||
TCP_PORT = 13857
|
||||
BUFFER_SIZE = 1024 # Normally 1024, but we want fast response
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind((TCP_IP, TCP_PORT))
|
||||
s.listen(1)
|
||||
conn, addr = s.accept()
|
||||
print 'Connection address:', addr
|
||||
|
||||
|
||||
while 1:
|
||||
data = conn.recv(BUFFER_SIZE)
|
||||
if not data: break
|
||||
#print "received data:", data
|
||||
commands = data.split()
|
||||
nb_oscargs = len(commands)
|
||||
print commands
|
||||
|
||||
#r.set('/pl/'+str(PL), str(something to code with commands, nb_oscargs))
|
||||
#conn.send(data) # echo
|
||||
|
||||
|
||||
conn.close()
|
||||
8
clients/redclient.red
Normal file
8
clients/redclient.red
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Red []
|
||||
|
||||
|
||||
#https://github.com/red/red/wiki/[DOC]-Guru-Meditations#how-to-make-http-requests
|
||||
|
||||
pl0: "[(100,200, 0), (100,300, 65280), (200,300, 65280), (200,200, 65280), (100,200, 65280)]"
|
||||
|
||||
read http://127.0.0.1:13857/path?name="jones"
|
||||
57
clients/redserver.py
Normal file
57
clients/redserver.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
"""
|
||||
|
||||
Http server for red 0.6.4
|
||||
Forward /pl/lasernumber pointslist to redis server
|
||||
|
||||
by Sam Neurohack
|
||||
from /team/laser
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import redis
|
||||
|
||||
r = redis.StrictRedis(host=gstt.LjayServerIP, port=6379, db=0)
|
||||
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
|
||||
|
||||
PORT_NUMBER = 8080
|
||||
|
||||
#This class will handles any incoming request from
|
||||
#the browser
|
||||
class myHandler(BaseHTTPRequestHandler):
|
||||
|
||||
#Handler for the GET requests
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type','text/html')
|
||||
self.end_headers()
|
||||
|
||||
# Send the html message
|
||||
self.wfile.write("Hello World !")
|
||||
|
||||
# r.set('/pl/'+str(PL), str(self.grid_points))
|
||||
|
||||
return
|
||||
|
||||
try:
|
||||
#Create a web server and define the handler to manage the
|
||||
#incoming request
|
||||
server = HTTPServer(('', PORT_NUMBER), myHandler)
|
||||
print 'Started httpserver on port ' , PORT_NUMBER
|
||||
|
||||
#Wait forever for incoming htto requests
|
||||
server.serve_forever()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print '^C received, shutting down the web server'
|
||||
server.socket.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue