forked from protonphoton/LJ
Merge branch 'master' of https://git.interhacker.space/teamlaser/LJ
This commit is contained in:
commit
0e8db219c2
201
clitools/filters/anaglyph.py
Executable file
201
clitools/filters/anaglyph.py
Executable file
@ -0,0 +1,201 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# -*- mode: Python -*-
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
anaglyph
|
||||||
|
v0.1.0
|
||||||
|
|
||||||
|
Attempts to create a valid 3D-glasses structure
|
||||||
|
|
||||||
|
LICENCE : CC
|
||||||
|
|
||||||
|
by cocoa
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
from __future__ import print_function
|
||||||
|
import argparse
|
||||||
|
import ast
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
name = "filters::cycle"
|
||||||
|
|
||||||
|
maxDist = 300
|
||||||
|
|
||||||
|
argsparser = argparse.ArgumentParser(description="Redis exporter LJ")
|
||||||
|
argsparser.add_argument("-x","--centerX",help="geometrical center X position",default=400,type=int)
|
||||||
|
argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=400,type=int)
|
||||||
|
argsparser.add_argument("-m","--min",help="Minimal displacement (default:2) ",default=1,type=int)
|
||||||
|
argsparser.add_argument("-M","--max",help="Maximal displacement (default:20) ",default=5,type=int)
|
||||||
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
|
||||||
|
|
||||||
|
args = argsparser.parse_args()
|
||||||
|
fps = args.fps
|
||||||
|
minVal = args.min
|
||||||
|
maxVal = args.max
|
||||||
|
centerX = args.centerX
|
||||||
|
centerY = args.centerY
|
||||||
|
verbose = args.verbose
|
||||||
|
|
||||||
|
optimal_looptime = 1 / fps
|
||||||
|
name = "filters::anaglyph"
|
||||||
|
|
||||||
|
def debug(*args, **kwargs):
|
||||||
|
if( verbose == False ):
|
||||||
|
return
|
||||||
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
def rgb2int(rgb):
|
||||||
|
#debug(name,"::rgb2int rbg:{}".format(rgb))
|
||||||
|
return int('0x%02x%02x%02x' % tuple(rgb),0)
|
||||||
|
|
||||||
|
def isValidColor( color, intensityColThreshold ):
|
||||||
|
if color[0] + color[1] + color[2] > intensityColThreshold:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
# These are paper colors
|
||||||
|
red = (41,24,24)
|
||||||
|
white = (95,95,95)
|
||||||
|
blue = (0,41,64)
|
||||||
|
|
||||||
|
red = (86,0,0)
|
||||||
|
blue = (0,55,86)
|
||||||
|
white = (125,125,125)
|
||||||
|
def anaglyph( pl ):
|
||||||
|
|
||||||
|
debug(name,'--------------- new loop ------------------')
|
||||||
|
# We will send one list after the other to optimize color change
|
||||||
|
blueList = list()
|
||||||
|
redList = list()
|
||||||
|
whiteList = list()
|
||||||
|
out = []
|
||||||
|
out1 = []
|
||||||
|
out2 = []
|
||||||
|
out3 = []
|
||||||
|
|
||||||
|
# The anaglyphic effect will be optained by :
|
||||||
|
# * having close objects appear as white
|
||||||
|
# * having distant objects appear as blue + red
|
||||||
|
# * having in between objects appear as distanceDecreased(white) + blue + red
|
||||||
|
for i, point in enumerate(pl):
|
||||||
|
ref_x = point[0]-centerX
|
||||||
|
ref_y = point[1]-centerY
|
||||||
|
ref_color = point[2]
|
||||||
|
angle = math.atan2( ref_x , ref_y )
|
||||||
|
dist = ref_y / math.cos(angle)
|
||||||
|
white_rvb = (0,0,0)
|
||||||
|
blue_rvb = (0,0,0)
|
||||||
|
red_rvb = (0,0,0)
|
||||||
|
|
||||||
|
# Calculate the point's spread factor (0.0 to 1.0)
|
||||||
|
# The spread is high if the point is close to center
|
||||||
|
"""
|
||||||
|
dist = 0 : spread = 1.0
|
||||||
|
dist = maxDist spread = 0.0
|
||||||
|
"""
|
||||||
|
if dist == 0:
|
||||||
|
spread = 1.0
|
||||||
|
else :
|
||||||
|
spread =( maxDist - dist ) / maxDist
|
||||||
|
if spread < 0.0:
|
||||||
|
spread = 0.0
|
||||||
|
|
||||||
|
#debug(name,"dist:{} spread:{}".format(dist,spread))
|
||||||
|
|
||||||
|
# White color is high if spread is low, i.e. point away from center
|
||||||
|
"""
|
||||||
|
spread = 1.0 : white_c = 0.0
|
||||||
|
spread = 0.0 : whice_c = 1.0
|
||||||
|
"""
|
||||||
|
if point[2] == 0:
|
||||||
|
white_color = 0
|
||||||
|
else:
|
||||||
|
white_factor = 1.0 - math.pow(spread,0.5)
|
||||||
|
white_rvb = tuple(map( lambda a: int(white_factor* a), white))
|
||||||
|
white_color = rgb2int( white_rvb)
|
||||||
|
#debug(name,"spread:{}\t white_rvb:{}\t white_color:{}".format(spread, white_rvb, white_color))
|
||||||
|
|
||||||
|
# Blue and Red colors are high if spread is high, i.e. close to center
|
||||||
|
"""
|
||||||
|
spread = 1.0 : red_c = 1.0
|
||||||
|
spread = 0.0 : red_c = 0.0
|
||||||
|
"""
|
||||||
|
color_factor = math.pow(spread,1)
|
||||||
|
if point[2] == 0:
|
||||||
|
blue_color = 0
|
||||||
|
red_color = 0
|
||||||
|
else:
|
||||||
|
blue_rvb = tuple(map( lambda a: int(color_factor * a), blue))
|
||||||
|
blue_color = rgb2int( blue_rvb)
|
||||||
|
red_rvb = tuple(map( lambda a: int(color_factor * a), red))
|
||||||
|
red_color = rgb2int( red_rvb)
|
||||||
|
|
||||||
|
#debug(name,"color_factor:{}\t\t blue_color:{}\t\t red_color:{}".format(color_factor,blue_color,red_color))
|
||||||
|
|
||||||
|
# Blue-to-Red spatial spread is high when spread is high, i.e. point close to center
|
||||||
|
"""
|
||||||
|
spread = 1.0 : spatial_spread = maxVal
|
||||||
|
spread = 0.0 : spatial_spread = minVal
|
||||||
|
"""
|
||||||
|
spatial_spread = minVal + spread * (maxVal - minVal)
|
||||||
|
#debug(name,"spatial_spread:{}".format(spatial_spread))
|
||||||
|
red_x = int(point[0] + spatial_spread)
|
||||||
|
blue_x = int(point[0] - spatial_spread )
|
||||||
|
red_y = int(point[1] )
|
||||||
|
blue_y = int(point[1])
|
||||||
|
|
||||||
|
white_point = [point[0], point[1], white_color]
|
||||||
|
blue_point = [blue_x,blue_y,blue_color]
|
||||||
|
red_point = [red_x,red_y,red_color]
|
||||||
|
|
||||||
|
#debug(name,"white[x,y,c]:{}".format(white_point))
|
||||||
|
#debug(name,"blue[x,y,c]:{}".format(blue_point))
|
||||||
|
#debug(name,"red[x,y,c]:{}".format(red_point))
|
||||||
|
# Do not append "black lines" i.e. a color where each composent is below X
|
||||||
|
# if isValidColor(white_rvb, 150):
|
||||||
|
# out1.append(white_point)
|
||||||
|
# if isValidColor(blue_rvb, 50):
|
||||||
|
# out2.append(blue_point)
|
||||||
|
# if isValidColor(red_rvb, 30):
|
||||||
|
# out3.append(red_point)
|
||||||
|
out1.append(white_point)
|
||||||
|
out2.append(blue_point)
|
||||||
|
out3.append(red_point)
|
||||||
|
|
||||||
|
#debug(name,"source pl:{}".format(pl))
|
||||||
|
debug(name,"whiteList:{}".format(out1))
|
||||||
|
debug(name,"blueList:{}".format(out2))
|
||||||
|
debug(name,"redList:{}".format(out3))
|
||||||
|
return out3 + out2
|
||||||
|
return out1 + out3 + out2
|
||||||
|
#return out1 + out2 + out3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
start = time.time()
|
||||||
|
line = sys.stdin.readline()
|
||||||
|
if line == "":
|
||||||
|
time.sleep(0.01)
|
||||||
|
line = line.rstrip('\n')
|
||||||
|
pointsList = ast.literal_eval(line)
|
||||||
|
# Do the filter
|
||||||
|
result = anaglyph( pointsList )
|
||||||
|
print( result, flush=True )
|
||||||
|
looptime = time.time() - start
|
||||||
|
# debug(name+" looptime:"+str(looptime))
|
||||||
|
if( looptime < optimal_looptime ):
|
||||||
|
time.sleep( optimal_looptime - looptime)
|
||||||
|
# debug(name+" micro sleep:"+str( optimal_looptime - looptime))
|
||||||
|
except EOFError:
|
||||||
|
debug(name+" break")# no more information
|
||||||
|
|
@ -53,7 +53,6 @@ def kaleidoscope( pl ):
|
|||||||
quad1 = []
|
quad1 = []
|
||||||
# Iterate trough the segments
|
# Iterate trough the segments
|
||||||
for i in range( 0, len(pl) ):
|
for i in range( 0, len(pl) ):
|
||||||
|
|
||||||
|
|
||||||
#debug(name+" point #", i)
|
#debug(name+" point #", i)
|
||||||
currentpoint = cp = pl[i]
|
currentpoint = cp = pl[i]
|
||||||
@ -74,8 +73,8 @@ def kaleidoscope( pl ):
|
|||||||
#debug(name+" rect: ", rect,"curr",currentpoint,"next",nextpoint )
|
#debug(name+" rect: ", rect,"curr",currentpoint,"next",nextpoint )
|
||||||
|
|
||||||
# Enumerate the points in rectangle to see
|
# Enumerate the points in rectangle to see
|
||||||
# how many right / wrong there are to add or skip early
|
# how many right / wrong there are
|
||||||
#
|
# either to add or skip early
|
||||||
for iterator, p in enumerate(rect):
|
for iterator, p in enumerate(rect):
|
||||||
if p[0] >= centerX and p[1] >= centerY:
|
if p[0] >= centerX and p[1] >= centerY:
|
||||||
right += 1
|
right += 1
|
||||||
@ -118,7 +117,7 @@ def kaleidoscope( pl ):
|
|||||||
#print("on x axis, v=",str(v)," and absnewY=",str(absnewY))
|
#print("on x axis, v=",str(v)," and absnewY=",str(absnewY))
|
||||||
crossY = [( absnewY*v[0] + cy ),( absnewY*v[1]+cy ), nc]
|
crossY = [( absnewY*v[0] + cy ),( absnewY*v[1]+cy ), nc]
|
||||||
# Inject in order
|
# Inject in order
|
||||||
# If current is valid, Add
|
# If current point is the quadrant, add it
|
||||||
if cx >= centerX and cy >= centerY :
|
if cx >= centerX and cy >= centerY :
|
||||||
quad1.append( currentpoint )
|
quad1.append( currentpoint )
|
||||||
# If absnewX smaller, it is closest to currentPoint
|
# If absnewX smaller, it is closest to currentPoint
|
||||||
@ -128,6 +127,9 @@ def kaleidoscope( pl ):
|
|||||||
else :
|
else :
|
||||||
if None != crossY : quad1.append( crossY )
|
if None != crossY : quad1.append( crossY )
|
||||||
if None != crossX : quad1.append( crossX )
|
if None != crossX : quad1.append( crossX )
|
||||||
|
# Add a black point at the end
|
||||||
|
#lastQuad1Point = quad1[-1]
|
||||||
|
#quad1.append( [lastQuad1Point[0],lastQuad1Point[1],0] )
|
||||||
|
|
||||||
## Stage 2 : Mirror points
|
## Stage 2 : Mirror points
|
||||||
#
|
#
|
||||||
@ -144,10 +146,10 @@ def kaleidoscope( pl ):
|
|||||||
point = quad3[iterator]
|
point = quad3[iterator]
|
||||||
quad4.append([ 2*centerX - point[0], point[1], point[2] ])
|
quad4.append([ 2*centerX - point[0], point[1], point[2] ])
|
||||||
|
|
||||||
debug(name+" quad1:",quad1)
|
#debug(name+" quad1:",quad1)
|
||||||
#debug(name+" quad2:", quad2 )
|
#debug(name+" quad2:", quad2 )
|
||||||
debug(name+" quad3:", quad3 )
|
#debug(name+" quad3:", quad3 )
|
||||||
debug(name+" quad4:", quad4 )
|
#debug(name+" quad4:", quad4 )
|
||||||
return quad3+quad4
|
return quad3+quad4
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -34,16 +34,18 @@ def debug(*args, **kwargs):
|
|||||||
if( verbose == False ):
|
if( verbose == False ):
|
||||||
return
|
return
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
def now():
|
def msNow():
|
||||||
return time.time() * 1000
|
return time.time()
|
||||||
|
|
||||||
# The list of available modes and the redis keys they need
|
# The list of available modes => redis keys each requires to run
|
||||||
oModeList = {
|
oModeList = {
|
||||||
"rms_noise": ["rms"],
|
"rms_noise": ["rms"],
|
||||||
"rms_size": ["rms"],
|
"rms_size": ["rms"],
|
||||||
"bpm_size": ["bpm"]
|
"bpm_size": ["bpm"],
|
||||||
|
"bpm_detect_size": ["bpm","bpm_delay","bpm_sample_interval","beats"]
|
||||||
}
|
}
|
||||||
CHAOS = 1
|
CHAOS = 1
|
||||||
|
REDISLATENCY = 30
|
||||||
REDIS_FREQ = 300
|
REDIS_FREQ = 300
|
||||||
|
|
||||||
# General Args
|
# General Args
|
||||||
@ -58,17 +60,19 @@ argsparser.add_argument("-x","--centerX",help="geometrical center X position",de
|
|||||||
argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=400,type=int)
|
argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=400,type=int)
|
||||||
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
# Modes And Common Modes Parameters
|
# Modes And Common Modes Parameters
|
||||||
|
argsparser.add_argument("-l","--redisLatency",help="Latency in ms to substract. Default:{}".format(REDISLATENCY),default=REDISLATENCY,type=float)
|
||||||
argsparser.add_argument("-m","--modelist",required=True,help="Comma separated list of modes to use from: {}".format("i, ".join(oModeList.keys())),type=str)
|
argsparser.add_argument("-m","--modelist",required=True,help="Comma separated list of modes to use from: {}".format("i, ".join(oModeList.keys())),type=str)
|
||||||
argsparser.add_argument("--chaos",help="How much disorder to bring. High value = More chaos. Default {}".format(CHAOS), default=CHAOS, type=str)
|
argsparser.add_argument("--chaos",help="How much disorder to bring. High value = More chaos. Default {}".format(CHAOS), default=CHAOS, type=str)
|
||||||
|
|
||||||
args = argsparser.parse_args()
|
args = argsparser.parse_args()
|
||||||
ip = args.ip
|
ip = args.ip
|
||||||
port = args.port
|
port = args.port
|
||||||
redisFreq = args.redis_freq
|
redisFreq = args.redis_freq / 1000
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
fps = args.fps
|
fps = args.fps
|
||||||
centerX = args.centerX
|
centerX = args.centerX
|
||||||
centerY = args.centerY
|
centerY = args.centerY
|
||||||
|
redisLatency = args.redisLatency
|
||||||
chaos = float(args.chaos)
|
chaos = float(args.chaos)
|
||||||
optimal_looptime = 1 / fps
|
optimal_looptime = 1 / fps
|
||||||
|
|
||||||
@ -82,33 +86,127 @@ for mode in modeList:
|
|||||||
redisKeys = list(set(redisKeys))
|
redisKeys = list(set(redisKeys))
|
||||||
debug(name,"Redis Keys:{}".format(redisKeys))
|
debug(name,"Redis Keys:{}".format(redisKeys))
|
||||||
redisData = {}
|
redisData = {}
|
||||||
redisLastHit = now() - redisFreq
|
redisLastHit = msNow() - 99999
|
||||||
r = redis.Redis(
|
r = redis.Redis(
|
||||||
host=ip,
|
host=ip,
|
||||||
port=port)
|
port=port)
|
||||||
|
|
||||||
# Records the last bpm
|
# Records the last bpm
|
||||||
last_bpm = time.time()
|
tsLastBeat = time.time()
|
||||||
|
|
||||||
def gauss(x, mu, sigma):
|
def gauss(x, mu, sigma):
|
||||||
return( math.exp(-math.pow((x-mu),2)/(2*math.pow(sigma,2))/math.sqrt(2*math.pi*math.pow(sigma,2))))
|
return( math.exp(-math.pow((x-mu),2)/(2*math.pow(sigma,2))/math.sqrt(2*math.pi*math.pow(sigma,2))))
|
||||||
|
|
||||||
|
previousPTTL = 0
|
||||||
|
tsNextBeatsList = []
|
||||||
|
def bpmDetect( ):
|
||||||
|
"""
|
||||||
|
An helper to compute the next beat time in milliseconds
|
||||||
|
Returns True if the cache was updated
|
||||||
|
"""
|
||||||
|
global tsNextBeatsList
|
||||||
|
global previousPTTL
|
||||||
|
global redisLastHit
|
||||||
|
global redisLatency
|
||||||
|
|
||||||
|
# Get the redis PTTL value for bpm
|
||||||
|
PTTL = redisData["bpm_pttl"]
|
||||||
|
|
||||||
def bpm_size( pl ):
|
# Skip early if PTTL < 0
|
||||||
global last_bpm
|
if PTTL < 0 :
|
||||||
|
debug(name,"bpmDetect skip detection : PTTL expired for 'bpm' key")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Skip early if the record hasn't been rewritten
|
||||||
|
if PTTL <= previousPTTL :
|
||||||
|
previousPTTL = PTTL
|
||||||
|
#debug(name,"bpmDetect skip detection : {} <= {}".format(PTTL, previousPTTL))
|
||||||
|
return False
|
||||||
|
debug(name,"bpmDetect running detection : {} > {}".format(PTTL, previousPTTL))
|
||||||
|
previousPTTL = PTTL
|
||||||
|
|
||||||
|
# Skip early if beat list is empty
|
||||||
|
beatsList = ast.literal_eval(redisData["beats"])
|
||||||
|
tsNextBeatsList = []
|
||||||
|
if( len(beatsList) == 0 ):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Read from redis
|
||||||
bpm = float(redisData["bpm"])
|
bpm = float(redisData["bpm"])
|
||||||
# Milliseconds ber beat
|
msBpmDelay = float(redisData["bpm_delay"])
|
||||||
milliSecondsPerBeat = int(60 / bpm * 1000)
|
samplingInterval = float(redisData["bpm_sample_interval"])
|
||||||
|
|
||||||
|
# Calculate some interpolations
|
||||||
|
lastBeatTiming = float(beatsList[len(beatsList) - 1])
|
||||||
|
msPTTLDelta = 2 * samplingInterval - float(PTTL)
|
||||||
|
sPerBeat = 60 / bpm
|
||||||
|
lastBeatDelay = msBpmDelay - lastBeatTiming*1000 + msPTTLDelta
|
||||||
|
countBeatsPast = math.floor( (lastBeatDelay / 1000) / sPerBeat)
|
||||||
|
#debug(name,"bpmDetect lastBeatTiming:{}\tmsPTTLDelta:{}\tsPerBeat:{}".format(lastBeatTiming,msPTTLDelta,sPerBeat))
|
||||||
|
#debug(name,"lastBeatDelay:{}\t countBeatsPast:{}".format(lastBeatDelay, countBeatsPast))
|
||||||
|
for i in range( countBeatsPast, 1000):
|
||||||
|
beatTime = i * sPerBeat - lastBeatTiming
|
||||||
|
if beatTime < 0:
|
||||||
|
continue
|
||||||
|
if beatTime * 1000 > 2 * samplingInterval :
|
||||||
|
break
|
||||||
|
#debug(name, "bpmDetect beat add beatTime:{} redisLastHit:{}".format(beatTime, redisLastHit))
|
||||||
|
tsNextBeatsList.append( redisLastHit + beatTime - redisLatency/1000)
|
||||||
|
debug(name, "bpmDetect new tsNextBeatsList:{}".format(tsNextBeatsList))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def bpm_detect_size( pl ):
|
||||||
|
bpmDetect()
|
||||||
|
|
||||||
|
# Find the next beat in the list
|
||||||
|
tsNextBeat = 0
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
msNearestBeat = None
|
||||||
|
msRelativeNextBTList = list(map( lambda a: abs(now - a) * 1000, tsNextBeatsList))
|
||||||
|
msToBeat = min( msRelativeNextBTList)
|
||||||
|
|
||||||
|
#debug(name,"bpm_detect_size msRelativeNextBTList:{} msToBeat:{}".format(msRelativeNextBTList,msToBeat))
|
||||||
# Calculate the intensity based on bpm coming/leaving
|
# Calculate the intensity based on bpm coming/leaving
|
||||||
# The curb is a gaussian
|
# The curb is a gaussian
|
||||||
mu = math.sqrt(milliSecondsPerBeat)
|
mu = 15
|
||||||
milliTimeToLastBeat = (time.time() - last_bpm) * 1000
|
intensity = gauss( msToBeat, 0 , mu)
|
||||||
milliTimeToNextBeat = (milliSecondsPerBeat - milliTimeToLastBeat)
|
#debug(name,"bpm_size","mu:{}\t msToBeat:{}\tintensity:{}".format(mu, msToBeat, intensity))
|
||||||
intensity = gauss( milliTimeToNextBeat, 0 , mu)
|
if msToBeat < 20:
|
||||||
debug(name,"bpm_size","milliSecondsPerBeat:{}\tmu:{}".format(milliSecondsPerBeat, mu))
|
debug(name,"bpm_detect_size kick:{}".format(msToBeat))
|
||||||
debug(name,"bpm_size","milliTimeToLastBeat:{}\tmilliTimeToNextBeat:{}\tintensity:{}".format(milliTimeToLastBeat, milliTimeToNextBeat, intensity))
|
pass
|
||||||
if milliTimeToNextBeat <= 0 :
|
for i, point in enumerate(pl):
|
||||||
last_bpm = time.time()
|
ref_x = point[0]-centerX
|
||||||
|
ref_y = point[1]-centerY
|
||||||
|
#debug(name,"In new ref x:{} y:{}".format(point[0]-centerX,point[1]-centerY))
|
||||||
|
angle=math.atan2( point[0] - centerX , point[1] - centerY )
|
||||||
|
l = ref_y / math.cos(angle)
|
||||||
|
new_l = l * intensity
|
||||||
|
#debug(name,"bpm_size","angle:{} l:{} new_l:{}".format(angle,l,new_l))
|
||||||
|
new_x = math.sin(angle) * new_l + centerX
|
||||||
|
new_y = math.cos(angle) * new_l + centerY
|
||||||
|
#debug(name,"x,y:({},{}) x',y':({},{})".format(point[0],point[1],new_x,new_y))
|
||||||
|
pl[i][0] = new_x
|
||||||
|
pl[i][1] = new_y
|
||||||
|
#debug( name,"bpm_detect_size output:{}".format(pl))
|
||||||
|
return( pl );
|
||||||
|
|
||||||
|
def bpm_size( pl ):
|
||||||
|
global tsLastBeat
|
||||||
|
bpm = float(redisData["bpm"])
|
||||||
|
# msseconds ber beat
|
||||||
|
msPerBeat = int(60 / bpm * 1000)
|
||||||
|
# Calculate the intensity based on bpm coming/leaving
|
||||||
|
# The curb is a gaussian
|
||||||
|
mu = math.sqrt(msPerBeat)
|
||||||
|
msTimeToLastBeat = (time.time() - tsLastBeat) * 1000
|
||||||
|
msTimeToNextBeat = (msPerBeat - msTimeToLastBeat)
|
||||||
|
intensity = gauss( msTimeToNextBeat, 0 , mu)
|
||||||
|
debug(name,"bpm_size","msPerBeat:{}\tmu:{}".format(msPerBeat, mu))
|
||||||
|
debug(name,"bpm_size","msTimeToLastBeat:{}\tmsTimeToNextBeat:{}\tintensity:{}".format(msTimeToLastBeat, msTimeToNextBeat, intensity))
|
||||||
|
if msTimeToNextBeat <= 0 :
|
||||||
|
tsLastBeat = time.time()
|
||||||
for i, point in enumerate(pl):
|
for i, point in enumerate(pl):
|
||||||
ref_x = point[0]-centerX
|
ref_x = point[0]-centerX
|
||||||
ref_y = point[1]-centerY
|
ref_y = point[1]-centerY
|
||||||
@ -158,21 +256,30 @@ def rms_noise( pl ):
|
|||||||
return pl
|
return pl
|
||||||
|
|
||||||
|
|
||||||
def updateRedis():
|
def refreshRedis():
|
||||||
global redisLastHit
|
global redisLastHit
|
||||||
global redisData
|
global redisData
|
||||||
for key in redisKeys:
|
# Skip if cache is sufficent
|
||||||
redisData[key] = r.get(key).decode('ascii')
|
diff = msNow() - redisLastHit
|
||||||
debug("name","updateRedis key:{} value:{}".format(key,redisData[key]))
|
if diff < redisFreq :
|
||||||
if key == 'bpm':
|
#debug(name, "refreshRedis not updating redis, {} < {}".format(diff, redisFreq))
|
||||||
redisData['bpm_ttl'] = r.pttl(key)
|
pass
|
||||||
debug(name,"redisData:{}".format(redisData))
|
else:
|
||||||
|
#debug(name, "refreshRedis updating redis, {} > {}".format(diff, redisFreq))
|
||||||
|
redisLastHit = msNow()
|
||||||
|
for key in redisKeys:
|
||||||
|
redisData[key] = r.get(key).decode('ascii')
|
||||||
|
#debug(name,"refreshRedis key:{} value:{}".format(key,redisData[key]))
|
||||||
|
# Only update the TTLs
|
||||||
|
if 'bpm' in redisKeys:
|
||||||
|
redisData['bpm_pttl'] = r.pttl('bpm')
|
||||||
|
#debug(name,"refreshRedis key:bpm_ttl value:{}".format(redisData["bpm_pttl"]))
|
||||||
|
#debug(name,"redisData:{}".format(redisData))
|
||||||
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
# it is time to query redis
|
refreshRedis()
|
||||||
if now() - redisLastHit > redisFreq:
|
|
||||||
updateRedis()
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
line = sys.stdin.readline()
|
line = sys.stdin.readline()
|
||||||
if line == "":
|
if line == "":
|
||||||
|
@ -34,7 +34,7 @@ argsparser = argparse.ArgumentParser(description="tunnel generator")
|
|||||||
argsparser.add_argument("-c","--color",help="Color",default=65280,type=int)
|
argsparser.add_argument("-c","--color",help="Color",default=65280,type=int)
|
||||||
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
|
||||||
argsparser.add_argument("-i","--interval",help="point per shape interval",default=30,type=int)
|
argsparser.add_argument("-i","--interval",help="point per shape interval",default=30,type=int)
|
||||||
argsparser.add_argument("-m","--max-size",help="maximum size for objects",default=500,type=int)
|
argsparser.add_argument("-m","--max-size",help="maximum size for objects",default=400,type=int)
|
||||||
argsparser.add_argument("-r","--randomize",help="center randomization",default=5,type=int)
|
argsparser.add_argument("-r","--randomize",help="center randomization",default=5,type=int)
|
||||||
argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int)
|
argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int)
|
||||||
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
|
||||||
@ -77,14 +77,19 @@ class polylineGenerator( object ):
|
|||||||
self.polylineList = [[0,[currentCenter[0],currentCenter[1]]]]
|
self.polylineList = [[0,[currentCenter[0],currentCenter[1]]]]
|
||||||
self.buf = []
|
self.buf = []
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
finished = False
|
||||||
|
while not finished:
|
||||||
|
finished = self.increment()
|
||||||
|
debug(name,"init done:{}".format(self.polylineList))
|
||||||
def draw( self ):
|
def draw( self ):
|
||||||
self.buf = []
|
self.buf = []
|
||||||
for it_pl, infoList in enumerate(self.polylineList):
|
for it_pl, infoList in enumerate(self.polylineList):
|
||||||
size = infoList[0]
|
size = infoList[0]
|
||||||
center = infoList[1]
|
center = infoList[1]
|
||||||
for it_sqr, point in enumerate(shape):
|
for it_sqr, point in enumerate(shape):
|
||||||
x = center[0] + point[0]*size
|
x = int( center[0] + point[0]*size )
|
||||||
y = center[1] + point[1]*size
|
y = int( center[1] + point[1]*size )
|
||||||
# Add an invisible point in first location
|
# Add an invisible point in first location
|
||||||
if 0 == it_sqr:
|
if 0 == it_sqr:
|
||||||
self.buf.append([x,y,0])
|
self.buf.append([x,y,0])
|
||||||
@ -114,22 +119,43 @@ class polylineGenerator( object ):
|
|||||||
speed = origSpeed
|
speed = origSpeed
|
||||||
elif speed > (origSpeed + randomize / 2) :
|
elif speed > (origSpeed + randomize / 2) :
|
||||||
speed = origSpeed + randomize / 2
|
speed = origSpeed + randomize / 2
|
||||||
debug(name, "currentCenter:{} speed:{}".format(currentCenter,speed))
|
#debug(name, "currentCenter:{} speed:{}".format(currentCenter,speed))
|
||||||
|
|
||||||
for i, shapeInfo in enumerate(self.polylineList):
|
for i, shapeInfo in enumerate(self.polylineList):
|
||||||
size = shapeInfo[0]
|
size = shapeInfo[0]
|
||||||
size += speed
|
# Augment speed with size
|
||||||
|
"""
|
||||||
|
size = 0 : += sqrt(speed)
|
||||||
|
size = half max size : +=speed
|
||||||
|
|
||||||
|
"""
|
||||||
|
if size < max_size / 4:
|
||||||
|
size += math.pow(speed, 0.1)
|
||||||
|
elif size < max_size / 3:
|
||||||
|
size += math.pow(speed, 0.25)
|
||||||
|
elif size < max_size / 2:
|
||||||
|
size += math.pow(speed, 0.5)
|
||||||
|
else:
|
||||||
|
size += math.pow(speed, 1.25)
|
||||||
if size < min_size : min_size = size
|
if size < min_size : min_size = size
|
||||||
if size > max_size : delList.append(i)
|
if size > max_size : delList.append(i)
|
||||||
self.polylineList[i][0] = size
|
self.polylineList[i][0] = size
|
||||||
for i in delList:
|
for i in delList:
|
||||||
del self.polylineList[i]
|
del self.polylineList[i]
|
||||||
if min_size >= interval: self.polylineList.append([0,[currentCenter[0],currentCenter[1]]])
|
|
||||||
#debug(name, "polyline:",self.polylineList)
|
#debug(name, "polyline:",self.polylineList)
|
||||||
|
if min_size >= interval:
|
||||||
|
debug(name, "new shape")
|
||||||
|
self.polylineList.append([0,[currentCenter[0],currentCenter[1]]])
|
||||||
|
|
||||||
|
# Return True if we delete a shape
|
||||||
|
|
||||||
|
if len(delList):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
pgen = polylineGenerator()
|
pgen = polylineGenerator()
|
||||||
|
pgen.init()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@ -140,7 +166,7 @@ while True:
|
|||||||
# send
|
# send
|
||||||
pl = pgen.draw()
|
pl = pgen.draw()
|
||||||
print(pl, flush=True)
|
print(pl, flush=True)
|
||||||
debug(name,"output:{}".format(pl))
|
#debug(name,"output:{}".format(pl))
|
||||||
|
|
||||||
looptime = time.time() - start
|
looptime = time.time() - start
|
||||||
if( looptime < optimal_looptime ):
|
if( looptime < optimal_looptime ):
|
||||||
|
201
www/simu.html
201
www/simu.html
@ -10,8 +10,8 @@
|
|||||||
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad.png">
|
<link rel="apple-touch-icon" sizes="152x152" href="touch-icon-ipad.png">
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="touch-icon-iphone-retina.png">
|
<link rel="apple-touch-icon" sizes="180x180" href="touch-icon-iphone-retina.png">
|
||||||
<link rel="apple-touch-icon" sizes="167x167" href="touch-icon-ipad-retina.png">
|
<link rel="apple-touch-icon" sizes="167x167" href="touch-icon-ipad-retina.png">
|
||||||
|
|
||||||
|
|
||||||
<!-- Page specific styles -->
|
<!-- Page specific styles -->
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
<body style="background-color:#222;">
|
<body style="background-color:#222;">
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Navigation Rack
|
Navigation Rack
|
||||||
-->
|
-->
|
||||||
@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
<a href="index.html">
|
<a href="index.html">
|
||||||
<div class="webaudiobut">
|
<div class="webaudiobut">
|
||||||
<div align="center" class="navled">
|
<div align="center" class="navled">
|
||||||
Index
|
Index
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
<a href="align.html">
|
<a href="align.html">
|
||||||
<div class="webaudiobut">
|
<div class="webaudiobut">
|
||||||
<div align="center" class="navled">
|
<div align="center" class="navled">
|
||||||
Align
|
Align
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -65,7 +65,7 @@
|
|||||||
|
|
||||||
<a href="auralls.html">
|
<a href="auralls.html">
|
||||||
<div class="webaudiobut">
|
<div class="webaudiobut">
|
||||||
<div align="center" class="navled">
|
<div align="center" class="navled">
|
||||||
Aurora
|
Aurora
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -73,15 +73,15 @@
|
|||||||
|
|
||||||
<a href="trckr/trckrcam1.html">
|
<a href="trckr/trckrcam1.html">
|
||||||
<div class="webaudiobut">
|
<div class="webaudiobut">
|
||||||
<div align="center" class="navled">
|
<div align="center" class="navled">
|
||||||
Lasercam
|
Lasercam
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="simu.html">
|
<a href="simu.html">
|
||||||
<div class="webaudiobut">
|
<div class="webaudiobut">
|
||||||
<div align="center" class="navled">
|
<div align="center" class="navled">
|
||||||
Simu
|
Simu
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -110,7 +110,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="TopRackGrid">
|
<div class="TopRackGrid">
|
||||||
<div>
|
<div>
|
||||||
<h2>
|
<h2>
|
||||||
/TL Simu
|
/TL Simu
|
||||||
@ -120,10 +120,10 @@
|
|||||||
</webaudio-switch>
|
</webaudio-switch>
|
||||||
</div>
|
</div>
|
||||||
<div class="webaudiobut" style="background-image: linear-gradient(174deg, #111,#030303);">
|
<div class="webaudiobut" style="background-image: linear-gradient(174deg, #111,#030303);">
|
||||||
<div align="center" id="line1" class="busled">
|
<div align="center" id="line1" class="busled">
|
||||||
Simu Rack
|
Simu Rack
|
||||||
</div>
|
</div>
|
||||||
<div align="center" id="status" class="busled">
|
<div align="center" id="status" class="busled">
|
||||||
/team/laser
|
/team/laser
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -149,7 +149,7 @@
|
|||||||
Laser Rack
|
Laser Rack
|
||||||
-->
|
-->
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="Rackgrid">
|
<div class="Rackgrid">
|
||||||
<div>
|
<div>
|
||||||
<h2>Lasers</h2>
|
<h2>Lasers</h2>
|
||||||
</div>
|
</div>
|
||||||
@ -171,7 +171,7 @@
|
|||||||
<!--
|
<!--
|
||||||
Simu Rack
|
Simu Rack
|
||||||
-->
|
-->
|
||||||
<div class="content" style="background-image: linear-gradient(174deg, #111,#030303);">
|
<div class="content" style="background-image: linear-gradient(174deg, #111,#030303);">
|
||||||
<canvas id="canvas" width="400" height="400" style="margin-left: 200px;margin-top : 20px;background-image:">canvas>
|
<canvas id="canvas" width="400" height="400" style="margin-left: 200px;margin-top : 20px;background-image:">canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -179,7 +179,7 @@
|
|||||||
<!--
|
<!--
|
||||||
Encoders Line
|
Encoders Line
|
||||||
|
|
||||||
# /aurora/radius layernumber radius [0-1]
|
# /aurora/radius layernumber radius [0-1]
|
||||||
# /aurora/rotdirec layer axe direc
|
# /aurora/rotdirec layer axe direc
|
||||||
# /aurora/linesize layer value
|
# /aurora/linesize layer value
|
||||||
# /aurora/rotdirec layer axe direc
|
# /aurora/rotdirec layer axe direc
|
||||||
@ -190,9 +190,9 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
JS
|
JS
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- LJ style WS : A nettoyer ! -->
|
<!-- LJ style WS : A nettoyer ! -->
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -207,7 +207,7 @@
|
|||||||
uri: LJ,
|
uri: LJ,
|
||||||
ws: null,
|
ws: null,
|
||||||
|
|
||||||
|
|
||||||
init : function (e) {
|
init : function (e) {
|
||||||
_WS.s = new WebSocket(_WS.uri);
|
_WS.s = new WebSocket(_WS.uri);
|
||||||
_WS.s.onopen = function (e) { _WS.onOpen(e); };
|
_WS.s.onopen = function (e) { _WS.onOpen(e); };
|
||||||
@ -238,7 +238,7 @@
|
|||||||
document.getElementById("on").value = 1;
|
document.getElementById("on").value = 1;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
onMessage: function (e) {
|
onMessage: function (e) {
|
||||||
var res = e.data.split(" ");
|
var res = e.data.split(" ");
|
||||||
@ -251,7 +251,7 @@
|
|||||||
|
|
||||||
|
|
||||||
switch (res[0].substring(0,6)) {
|
switch (res[0].substring(0,6)) {
|
||||||
|
|
||||||
case "/statu":
|
case "/statu":
|
||||||
_WS.showline1("connected to "+LJ);
|
_WS.showline1("connected to "+LJ);
|
||||||
if (res[2]==="Disconnected"){
|
if (res[2]==="Disconnected"){
|
||||||
@ -283,7 +283,7 @@
|
|||||||
//divtext.innerHTML="connected to "+LJ;
|
//divtext.innerHTML="connected to "+LJ;
|
||||||
divtext1.innerHTML='<span style="color: red;">'+ res[1]+" "+res[2]+'</span>';
|
divtext1.innerHTML='<span style="color: red;">'+ res[1]+" "+res[2]+'</span>';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "/plpoi":
|
case "/plpoi":
|
||||||
//console.log("plpoint");
|
//console.log("plpoint");
|
||||||
break;
|
break;
|
||||||
@ -294,29 +294,29 @@
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: function (e) {
|
onError: function (e) {
|
||||||
_WS.showstatus('<span style="color: red;">ERROR:</span> ' + e.data);
|
_WS.showstatus('<span style="color: red;">ERROR:</span> ' + e.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
showin: function (message) {
|
showin: function (message) {
|
||||||
var divtext = document.getElementById('status');
|
var divtext = document.getElementById('status');
|
||||||
divtext.innerHTML="";
|
divtext.innerHTML="";
|
||||||
divtext.innerHTML= message.toString();
|
divtext.innerHTML= message.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
showout: function (message) {
|
showout: function (message) {
|
||||||
var divtext = document.getElementById('status');
|
var divtext = document.getElementById('status');
|
||||||
divtext.innerHTML="";
|
divtext.innerHTML="";
|
||||||
divtext.innerHTML= message.toString();
|
divtext.innerHTML= message.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
showstatus: function (message) {
|
showstatus: function (message) {
|
||||||
var divtext = document.getElementById('status');
|
var divtext = document.getElementById('status');
|
||||||
divtext.innerHTML="";
|
divtext.innerHTML="";
|
||||||
divtext.innerHTML= message.toString();
|
divtext.innerHTML= message.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
showline1: function (message) {
|
showline1: function (message) {
|
||||||
var divtext = document.getElementById('line1');
|
var divtext = document.getElementById('line1');
|
||||||
divtext.innerHTML="";
|
divtext.innerHTML="";
|
||||||
@ -331,47 +331,47 @@
|
|||||||
_WS.s.send(message);
|
_WS.s.send(message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
close: function () {
|
close: function () {
|
||||||
_WS.showstatus('GOODBYE !');
|
_WS.showstatus('GOODBYE !');
|
||||||
_WS.s.close();
|
_WS.s.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('load', _WS.init, false);
|
window.addEventListener('load', _WS.init, false);
|
||||||
//
|
//
|
||||||
// Forms submits
|
// Forms submits
|
||||||
//
|
//
|
||||||
|
|
||||||
function onSubmit(clicked_id) {
|
function onSubmit(clicked_id) {
|
||||||
var input = document.getElementById(clicked_id);
|
var input = document.getElementById(clicked_id);
|
||||||
//console.log("/" + clicked_id + " " + input.value);
|
//console.log("/" + clicked_id + " " + input.value);
|
||||||
_WS.send("/" + clicked_id + " " + input.value);
|
_WS.send("/" + clicked_id + " " + input.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
web audio encoders scripts
|
web audio encoders scripts
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var message="";
|
var message="";
|
||||||
var log=[];
|
var log=[];
|
||||||
var knobs = document.getElementsByTagName('webaudio-knob');
|
var knobs = document.getElementsByTagName('webaudio-knob');
|
||||||
|
|
||||||
for(var i = 0; i < knobs.length; i++){
|
for(var i = 0; i < knobs.length; i++){
|
||||||
knobs[i].addEventListener("input",Dump,false);
|
knobs[i].addEventListener("input",Dump,false);
|
||||||
knobs[i].addEventListener("change",Dump,false);
|
knobs[i].addEventListener("change",Dump,false);
|
||||||
}
|
}
|
||||||
var sliders = document.getElementsByTagName('webaudio-slider');
|
var sliders = document.getElementsByTagName('webaudio-slider');
|
||||||
|
|
||||||
for(var i = 0; i < sliders.length; i++){
|
for(var i = 0; i < sliders.length; i++){
|
||||||
sliders[i].addEventListener("input",Dump,false);
|
sliders[i].addEventListener("input",Dump,false);
|
||||||
sliders[i].addEventListener("change",Dump,false);
|
sliders[i].addEventListener("change",Dump,false);
|
||||||
}
|
}
|
||||||
var switches = document.getElementsByTagName('webaudio-switch');
|
var switches = document.getElementsByTagName('webaudio-switch');
|
||||||
|
|
||||||
for(var i = 0; i < switches.length; i++) {
|
for(var i = 0; i < switches.length; i++) {
|
||||||
switches[i].addEventListener("change",Dump,false);
|
switches[i].addEventListener("change",Dump,false);
|
||||||
}
|
}
|
||||||
@ -418,8 +418,8 @@
|
|||||||
var x = document.getElementById("aurora/fx/0 Trckr");
|
var x = document.getElementById("aurora/fx/0 Trckr");
|
||||||
x.value = 0 ;
|
x.value = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function nocolor0() {
|
function nocolor0() {
|
||||||
console.log("nocolor0")
|
console.log("nocolor0")
|
||||||
var x = document.getElementById("aurora/color/0 red");
|
var x = document.getElementById("aurora/color/0 red");
|
||||||
@ -444,7 +444,7 @@
|
|||||||
log.unshift(str);
|
log.unshift(str);
|
||||||
log.length=1;
|
log.length=1;
|
||||||
str="";
|
str="";
|
||||||
|
|
||||||
for(var i=19;i>=0;--i) {
|
for(var i=19;i>=0;--i) {
|
||||||
if(log[i])
|
if(log[i])
|
||||||
str+=log[i]+"<br/>";
|
str+=log[i]+"<br/>";
|
||||||
@ -452,33 +452,33 @@
|
|||||||
|
|
||||||
_WS.send("/" + e.target.id + " " + e.target.value);
|
_WS.send("/" + e.target.id + " " + e.target.value);
|
||||||
|
|
||||||
var res = e.target.id.split(" ");
|
var res = e.target.id.split(" ");
|
||||||
|
|
||||||
// on off
|
// on off
|
||||||
if (e.target.id === "on" && e.type === "change") {
|
if (e.target.id === "on" && e.type === "change") {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go to index
|
// Go to index
|
||||||
if (e.target.id === "index" && e.type === "change") {
|
if (e.target.id === "index" && e.type === "change") {
|
||||||
window.location.assign("index.html");
|
window.location.assign("index.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fx
|
// Fx
|
||||||
if (res[0].substring(7,9) === "fx" && e.type === "change") {
|
if (res[0].substring(7,9) === "fx" && e.type === "change") {
|
||||||
|
|
||||||
var layer = res[0].substring(10,12);
|
var layer = res[0].substring(10,12);
|
||||||
nofx0();
|
nofx0();
|
||||||
var x = document.getElementById(e.target.id);
|
var x = document.getElementById(e.target.id);
|
||||||
x.value = 1 ;
|
x.value = 1 ;
|
||||||
_WS.showstatus(e.target.id);
|
_WS.showstatus(e.target.id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
if (res[0].substring(7,9) === "co" && e.type === "change") {
|
if (res[0].substring(7,9) === "co" && e.type === "change") {
|
||||||
|
|
||||||
var layer = res[0].substring(13,14);
|
var layer = res[0].substring(13,14);
|
||||||
console.log(layer)
|
console.log(layer)
|
||||||
nocolor0();
|
nocolor0();
|
||||||
var x = document.getElementById(e.target.id);
|
var x = document.getElementById(e.target.id);
|
||||||
@ -486,9 +486,9 @@
|
|||||||
_WS.showstatus(e.target.id);
|
_WS.showstatus(e.target.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Lasers
|
// Lasers
|
||||||
if (res[0] === "noteon" && e.type === "change") {
|
if (res[0] === "noteon" && e.type === "change") {
|
||||||
//console.log(e.target.id)
|
//console.log(e.target.id)
|
||||||
nolaser();
|
nolaser();
|
||||||
var x = document.getElementById(e.target.id);
|
var x = document.getElementById(e.target.id);
|
||||||
@ -500,88 +500,57 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Simulator Point lists drawing scripts
|
Simulator Point lists drawing scripts
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
//
|
//
|
||||||
// Simulator canvas : store Reference To The Canvas & Set Context
|
// Simulator canvas : store Reference To The Canvas & Set Context
|
||||||
//
|
//
|
||||||
|
|
||||||
var canvas = document.getElementById("canvas");
|
var canvas = document.getElementById("canvas");
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
var lastpoint = { x: 0, y: 0, color: 0};
|
var lastpoint = { x: 0, y: 0, color: 0};
|
||||||
ctx.clearRect(0,0,400,400);
|
ctx.clearRect(0,0,400,400);
|
||||||
var zoom = 0.5;
|
var zoom = 0.5;
|
||||||
//ctx.save
|
//ctx.save
|
||||||
|
|
||||||
|
// Draws every segment received, except black colored target ones
|
||||||
// Todo : laser point will have black points to go from a polyline to another. Need to discard those black points.
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
|
||||||
|
|
||||||
// Clear Canvas At The Start Of Every Frame
|
|
||||||
//ctx.restore
|
|
||||||
|
|
||||||
if (pl2.length > 0)
|
if (pl2.length > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Begin a new path
|
|
||||||
// 0.7 reduces max coordinates in a more browser compatible resolution.
|
|
||||||
ctx.clearRect(0,0,400,400);
|
ctx.clearRect(0,0,400,400);
|
||||||
ctx.beginPath();
|
lastpoint = {
|
||||||
|
x:pl2[0],
|
||||||
ctx.moveTo(pl2[0]*zoom, pl2[1]*zoom);
|
y:pl2[1],
|
||||||
lastpoint.color = pl2[2];
|
color:pl2[2]
|
||||||
|
}
|
||||||
// Draw n Lines
|
for (var i = 0; i <= pl2.length; i+=3)
|
||||||
for (var i = 0; i < pl2.length/3; i++)
|
{
|
||||||
{
|
point = {
|
||||||
|
x:pl2[i],
|
||||||
// New point has the same color -> add a new line to the new point
|
y:pl2[i+1],
|
||||||
if (pl2[2+(i*3)] === lastpoint.color)
|
color:pl2[i+2]
|
||||||
{
|
|
||||||
ctx.lineTo(pl2[i*3]*zoom, pl2[1+(i*3)]*zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
// New point has different color -> stroke with previous color
|
|
||||||
if (pl2[2+(i*3)] != lastpoint.color)
|
|
||||||
{
|
|
||||||
ctx.strokeStyle = "#"+(lastpoint.color + Math.pow(16, 6)).toString(16).slice(-6);
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.closePath()
|
|
||||||
//ctx.restore
|
|
||||||
ctx.beginPath();
|
|
||||||
//ctx.clearRect(0,0,400,400);
|
|
||||||
|
|
||||||
ctx.moveTo(pl2[i*3]*zoom, pl2[1+(i*3)]*zoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last point -> stroke with current color
|
|
||||||
if (i === (pl2.length/3)-1 )
|
|
||||||
{
|
|
||||||
ctx.moveTo(pl2[i*3]*zoom, pl2[1+(i*3)]*zoom);
|
|
||||||
ctx.strokeStyle = "#"+((pl2[2+(i*3)]) + Math.pow(16, 6)).toString(16).slice(-6);
|
|
||||||
ctx.stroke();
|
|
||||||
|
|
||||||
ctx.closePath()
|
|
||||||
//ctx.restore
|
|
||||||
//ctx.clearRect(0,0,400,400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// store point for comparison
|
|
||||||
lastpoint.x = pl2[i*3];
|
|
||||||
lastpoint.y = pl2[1+(i*3)];
|
|
||||||
lastpoint.color = pl2[2+(i*3)];
|
|
||||||
}
|
}
|
||||||
|
// console.log(lastpoint,point)
|
||||||
}
|
// if the target is black, skip drawing
|
||||||
|
if( point.color != 0){
|
||||||
|
ctx.beginPath()
|
||||||
|
ctx.strokeStyle = "#"+(point.color + Math.pow(16, 6)).toString(16).slice(-6);
|
||||||
|
ctx.moveTo(lastpoint.x * zoom, lastpoint.y * zoom);
|
||||||
|
ctx.lineTo(point.x * zoom, point.y * zoom);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.closePath()
|
||||||
|
}
|
||||||
|
lastpoint = point
|
||||||
|
}
|
||||||
|
}
|
||||||
// Call Draw Function Again To Create Animation
|
// Call Draw Function Again To Create Animation
|
||||||
window.requestAnimationFrame(draw);
|
window.requestAnimationFrame(draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize The Draw Function
|
// Initialize The Draw Function
|
||||||
draw();
|
draw();
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user