def Sine(fwork): global f_sine dots = [] amp = 200 nb_point = 40 for t in range(0, nb_point + 1): y = 0 - amp * math.sin(2 * PI * (float(t) / float(nb_point))) x = 0 - amp * math.cos(2 * PI * f_sine * (float(t) / float(nb_point))) dots.append(proj(int(x), int(y), 0, 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=1, closed=False) if f_sine > 24: f_sine = 0 f_sine += 0.01 gstt.PL[0] = fwork.LinesPL(0) gstt.PL[1] = fwork.LinesPL(1)
def Pose(fwork): for anim in gstt.anims0: PL = 0 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) for people in range(len(pose_json['people'])): fwork.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(headCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) # Face ''' #fwork.rPolyLineOneColor(face(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) ''' gstt.PL[PL] = fwork.LinesPL(PL) time.sleep(0.02) # decrease current frame if gstt.keystates[pygame.K_w]: # and not gstt.keystates_prev[pygame.K_w]: gstt.CurrentPose -= 1 if gstt.CurrentPose < 2: gstt.CurrentPose = gstt.numfiles -1 #time.sleep(0.033) print "Frame : ",gstt.CurrentPose # increaser current frame if gstt.keystates[pygame.K_x]: # and not gstt.keystates_prev[pygame.K_x]: gstt.CurrentPose += 1 if gstt.CurrentPose > gstt.numfiles -1: gstt.CurrentPose = 1 #time.sleep(0.033) print "Frame : ",gstt.CurrentPose
def xPLS(fwork): global f_sine # point list "PL" 0 generator (assigned to a laser in gstt.lasersPLS) # middle horizontal line PL = 0 dots = [] x = (int(screen_size[1]) / 2) - 50 y = (int(screen_size[0]) / 2) dots.append((int(x), int(y))) dots.append((int((int(screen_size[1]) / 2) + 50), (int(y)))) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) # PL 1 generator (assigned to a laser in gstt.lasersPLS) # middle vertical line PL = 1 dots = [] #pdb.set_trace() x = int(screen_size[1]) / 2 y = (int(screen_size[1]) / 2) - 50 dots.append((int(x), int(y))) dots.append((int(x), (int(screen_size[1]) / 2) + 50)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=1, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) # PL 2 generator (assigned to a laser in gstt.lasersPLS) PL = 2 dots = [] amp = 200 nb_point = 40 for t in range(0, nb_point + 1): y = 0 - amp * math.sin(2 * PI * (float(t) / float(nb_point))) x = 0 - amp * math.cos(2 * PI * f_sine * (float(t) / float(nb_point))) dots.append(proj(int(x), int(y), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=2, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) if f_sine > 24: f_sine = 0 f_sine += 0.01
def Astro(fwork): PlanetsPositions = [] dots = [] amp = 0.8 # get solar planet positions for planet in xrange(9): PlanetsPositions.append(kernel[0, planet + 1].compute(gstt.JulianDate)) # first 5 planets goes to PL 0 PL = 0 for planet in xrange(5): x, y, z = planet2screen(PlanetsPositions[planet][0], PlanetsPositions[planet][1], PlanetsPositions[planet][2]) x, y = proj(int(x), int(y), int(z)) x = x * amp y = y * amp + 60 #dots.append((int(x)-300,int(y)+200)) #dots.append((int(x)-295,int(y)+205)) fwork.Line((x, y), (x + 2, y + 2), c=colorify.rgb2hex(gstt.color), PL=0) gstt.PL[PL] = fwork.LinesPL(PL) # Last planets goes to PL 1 PL = 1 for planet in range(5, 9): #print "1 ", planet x, y, z = planet2screen(PlanetsPositions[planet][0], PlanetsPositions[planet][1], PlanetsPositions[planet][2]) x, y = proj(int(x), int(y), int(z)) x = x * amp y = y * amp + 60 #dots.append((int(x)-300,int(y)+200)) #dots.append((int(x)-295,int(y)+205)) fwork.Line((x, y), (x + 2, y + 2), c=colorify.rgb2hex(gstt.color), PL=1) gstt.PL[PL] = fwork.LinesPL(PL) #time.sleep(0.001) gstt.JulianDate += 1
def Text(fwork): gstt.message = "Hello" message = gstt.message PL = 0 len_message = len(message) i = 0 for char in message: i += 1 # x offset for each letter depends on message length x_offset = 26 * (-(0.9 * len_message) + 3 * i) char_dots = font1.ASCII_GRAPHICS[ord(char) - 47] for dot_pl in char_dots: dots = [] for dot in dot_pl: dots.append((x_offset + dot[0], dot[1])) # Works with letters generated around 0,0 (see font1.py) # Here the dots list will be displayed from 200,200 in pygame coordinates and resized 1 times. fwork.rPolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=1) gstt.PL[PL] = fwork.LinesPL(PL)
def square(fwork): global f_sine dots = [] amp = 200 nb_point = 40 # "frame" components #""" x_max = (800) - 1 y_max = (600) - 1 #x_max = 1 #y_max = 1 x_corner = 20 y_corner = 15 dots = [ (x_corner, y_corner), (-x_corner, y_corner), (-x_corner, -y_corner), (x_corner, -y_corner), (x_corner, y_corner) ] #print dots fwork.rPolyLineOneColor (dots, c = colorify.rgb2hex([255, 0, 0]), PL = 0, closed = False, xpos=x_max>>1 , ypos=y_max>>1, resize=1) #""" # transfer full frame to automatic laser display PL 0 : gstt.PL[0] = fwork.LinesPL(0) if f_sine > 24: f_sine = 0 f_sine += 0.01
def LineX(fwork): joypads() # vertical line dots = [] x = cc2scrX(gstt.cc[1] + 1) y = 0 dots.append((int(x), int(y))) dots.append((int(x), int(screen_size[1]))) #print dots fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color)) # horizontal line dots = [] y = cc2scrY(gstt.cc[2] + 1) x = 0 dots.append((int(x), int(y))) dots.append((int(screen_size[0]), int(y))) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color))
def CC(fwork): dots = [] amp = 200 nb_point = 60 for t in range(0, nb_point+1): y = 1 - amp*math.sin(2*PI*cc2range(gstt.cc[5],0,24)*(float(t)/float(nb_point))) x = 1 - amp*math.cos(2*PI*cc2range(gstt.cc[6],0,24)*(float(t)/float(nb_point))) #bhorosc.send5("/point", [proj(int(x),int(y),0),colorify.rgb2hex(gstt.color)]) dots.append(proj(int(x),int(y),0,0)) fwork.PolyLineOneColor( dots, c=colorify.rgb2hex(gstt.color), PL = 1, closed = False )
def black(): print "black out" for laserid in range(0,4): PL = laserid dots = [] x = xy_center[0] y = xy_center[1] dots.append((x,y)) dots.append((x+5,y+5)) print "black" fwork.PolyLineOneColor(dots, c=colorify.rgb2hex([0,0,0]), PL = 0, closed = False) gstt.PL[PL] = fwork.LinesPL(PL)
def Dancers(fwork): for laseranims in range(3): for anim in gstt.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 #bhorosc.sendresol("/layer1/clip1/connect",1) #bhorosc.sendresol("/layer1/clip1/connect",0) posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json' posefile = open(posename , 'r') posedatas = posefile.read() pose_json = json.loads(posedatas) for people in range(len(pose_json['people'])): fwork.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False,xpos = anim[1], ypos = anim[2], resize = anim[3]) gstt.PL[PL] = fwork.LinesPL(PL) '''
def Dot(fwork): PL = 0 dots = [] x = cc2scrX(gstt.cc[5]) y = cc2scrY(gstt.cc[6]) #x = xy_center[0] + gstt.cc[5]*amp #y = xy_center[1] + gstt.cc[6]*amp #print x,y,proj(int(x),int(y),0) dots.append(proj(int(x), int(y), 0)) dots.append(proj(int(x) + 5, int(y) + 5, 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False) gstt.PL[PL] = fwork.LinesPL(PL)
def NozMode2(fwork): import mikuscope as mk dots = [] nb_point=100 for idx, valx in enumerate(mk.x): if not np.isnan(valx): #print idx,valx,mk.y[idx] xT = valx*20000 x = 3.5 * (extracc2scrX(xT) - 400) yT = mk.y[idx]*15000 y = 3.5 * (extracc2scrY(yT) - 300) dots.append(proj(int(x),int(y),0,0)) else: #dots.append(proj(0,0,0)) fwork.PolyLineOneColor( dots, c=colorify.rgb2hex(gstt.color), PL = 1, closed = False )
def CC(fwork): PL = 0 dots = [] amp = 200 nb_point = 60 for t in range(0, nb_point + 1): y = 1 - amp * math.sin(2 * PI * cc2range(gstt.cc[5], 0, 24) * (float(t) / float(nb_point))) x = 1 - amp * math.cos(2 * PI * cc2range(gstt.cc[6], 0, 24) * (float(t) / float(nb_point))) dots.append(proj(int(x), int(y), 0)) # These points are generated in pygame coordinates space (0,0 is top left) defined by screen_size in globalVars.py fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) gstt.PL[PL] = fwork.LinesPL(PL)
def Sine(fwork): global f_sine dots = [] amp = 200 nb_point = 40 # Laser 0 "frame" components for t in range(0, nb_point+1): y = 0 - amp*math.sin(2 * PI * (float(t)/float(nb_point))) x = 0 - amp*math.cos(2 * PI * f_sine *(float(t)/float(nb_point))) dots.append(proj(int(x),int(y),0)) print dots fwork.PolyLineOneColor ( dots, c = colorify.rgb2hex([255,255,0]), PL = 0, closed = False) # transfer full frame to automatic laser display PL 0 : gstt.PL[0] = fwork.LinesPL(0) if f_sine > 24: f_sine = 0 f_sine += 0.01
def Faces(fwork): for laseranims in range(3): for anim in gstt.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'])): #fwork.rPolyLineOneColor(face(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3]) gstt.PL[PL] = fwork.LinesPL(PL) time.sleep(0.02)
def Shapes(fwork): global mouse_prev, sections, warpd PL = gstt.Laser dots = [] CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow] #switch to SHAPE mode Key E ? if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[ pygame.K_e] and gstt.EditStep == 1: print "SHAPE Mode." gstt.EditStep = 0 gstt.CurrentWindow = 0 gstt.CurrentCorner = 0 # ENTER : Display all shapes if gstt.keystates[pygame.K_RETURN] and gstt.EditStep == 0: print "Display all Mode." gstt.EditStep = 1 gstt.CurrentCorner = 0 # Draw all windows points or "corners" for corner in xrange(len(CurrentWindowPoints)): dots.append( proj(int(CurrentWindowPoints[corner][0]), int(CurrentWindowPoints[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) # Left mouse is clicked, modify current Corner coordinate if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2) CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2) # Change corner if Z key is pressed. if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]: if gstt.CurrentCorner < settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.CurrentCorner += 1 print "Corner : ", gstt.CurrentCorner # Press E inside shape mode : Next window if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[pygame.K_e]: # Save current Window and switch to the next one. if gstt.CurrentWindow < settings.Mapping( sections[gstt.CurrentSection]) - 1: print "saving " settings.MappingWrite(sections, str(gstt.CurrentWindow), CurrentWindowPoints) gstt.CurrentWindow += 1 gstt.CurrentCorner = -1 if gstt.CurrentWindow == settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.EditStep == 0 gstt.CurrentWindow = 0 print "Now Editing window ", gstt.CurrentWindow mouse_prev = gstt.mouse gstt.PL[PL] = fwork.LinesPL(PL) # Press A : Next screen. Press until current section is a screen section with shapes. if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]: if gstt.CurrentSection < len(sections) - 1: gstt.CurrentSection += 1 else: gstt.CurrentSection = 0 print "Section ", sections[gstt.CurrentSection] if sections[gstt.CurrentSection].find("screen") == 0: print "switching to section ", sections[gstt.CurrentSection] print gstt.CurrentSection print sections[gstt.CurrentSection] MappingConf(gstt.CurrentSection) if gstt.EditStep == 1: # Add all windows to PL for display for Window in gstt.Windows: #print Window dots = [] for corner in xrange(len(Window)): #print "Editing : ", WindowPoints[corner] #print Window[corner][0] dots.append( proj(int(Window[corner][0]), int(Window[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) #print dots gstt.PL[PL] = fwork.LinesPL(PL)
def Pose(fwork): global mouse_prev # Left mouse is clicked, modify current corner warp coordinate if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax += gstt.mouse[0][0] * 2 deltay -= gstt.mouse[0][1] * 2 print "Deltas ", deltax, deltay # Next pose if Z key is pressed. if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]: if gstt.CurrentPose < 3: gstt.CurrentPose += 1 # Press A : Next Laser. Press until current section is a screen section with shapes. # Press A : Next Laser. if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]: pass # decrease current frame if gstt.keystates[pygame.K_w]: # and not gstt.keystates_prev[pygame.K_w]: gstt.CurrentPose -= 1 if gstt.CurrentPose < 2: gstt.CurrentPose = gstt.numfiles - 1 time.sleep(0.033) print "Frame : ", gstt.CurrentPose # increase current frame if gstt.keystates[pygame.K_x]: # and not gstt.keystates_prev[pygame.K_x]: gstt.CurrentPose += 1 if gstt.CurrentPose > gstt.numfiles - 1: gstt.CurrentPose = 1 time.sleep(0.033) print "Frame : ", gstt.CurrentPose PL = 0 dots = [] posename = gstt.PoseDir + 'snap_00000000' + str( "%04d" % gstt.CurrentPose) + '_keypoints.json' posefile = open(posename, 'r') posedatas = posefile.read() pose = json.loads(posedatas) print "" print "Frame : ", gstt.CurrentPose print "body :", bodyCOCO(pose) print "arm :", armCOCO(pose) print 'head :', headCOCO(pose) fwork.PolyLineOneColor(bodyCOCO(pose), c=colorify.rgb2hex(gstt.color), PL=0, closed=False) fwork.PolyLineOneColor(armCOCO(pose), c=colorify.rgb2hex(gstt.color), PL=0, closed=False) fwork.PolyLineOneColor(headCOCO(pose), c=colorify.rgb2hex(gstt.color), PL=0, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) mouse_prev = gstt.mouse
def Warp(fwork): global mouse_prev, sections, warpd # Left mouse is clicked, modify current corner warp coordinate if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] warpd[gstt.CurrentCorner][0] -= (deltax * 5) warpd[gstt.CurrentCorner][1] -= (deltay * 5) settings.MappingWriteSection('laser' + str(gstt.Laser), "warpdest", warpd) homography.newEDH(gstt.Laser) print "Laser ", gstt.Laser, " Corner ", gstt.CurrentCorner, warpd # Change corner if Z key is pressed. if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]: if gstt.CurrentCorner < 3: print "saving..." settings.MappingWriteSection('laser' + str(gstt.Laser), "warpdest", warpd) newrenderer.newEDH(gstt.Laser) gstt.CurrentCorner += 1 print "Corner : ", gstt.CurrentCorner else: gstt.CurrentCorner = -1 warpref = ([(300.0, 400.0), (500.0, 400.0), (500.0, 200.0), (300.0, 200.0), (300.0, 400.0)]) # Add all windows to PL for display for Window in gstt.Windows: dots = [] for corner in xrange(len(Window)): dots.append(proj(int(Window[corner][0]), int(Window[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) mouse_prev = gstt.mouse # Press A : Next Laser. Press until current section is a screen section with shapes. # Press A : Next Laser. if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]: if gstt.Laser < gstt.LaserNumber: gstt.Laser += 1 else: gstt.Laser = 0 gstt.CurrentCorner = 0 print "" print "Laser ", gstt.Laser, "Warpd points ", gstt.warpdest[gstt.Laser] warpd = ast.literal_eval(gstt.warpdest[gstt.Laser]) print warpd
def Mapping(fwork): global mouse_prev, sections PL = gstt.Laser dots = [] # switch to windows/shapes edit mode Key E ? if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[ pygame.K_e] and gstt.EditStep == 0: print "Switching to Edit Mode" gstt.EditStep = 1 gstt.CurrentWindow = 0 gstt.CurrentCorner = 0 # Back to Warp edit Mode if ENTER key is pressed ? if gstt.keystates[pygame.K_RETURN] and gstt.EditStep == 1: print "Switching to Warp Mode" gstt.EditStep = 0 gstt.CurrentCorner = 0 # Warp Display and Warp edit Mode # Change current corner position with mouse pointer # Change corner with Z key if gstt.EditStep == 0: # print "Warp mode" # Left mouse is clicked, modify current Corner coordinate # print gstt.mouse if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] gstt.warpdest[gstt.Laser][gstt.CurrentCorner, 0] -= (deltax * 5) gstt.warpdest[gstt.Laser][gstt.CurrentCorner, 1] += (deltay * 5) #print "Laser ", gstt.Laser, " Corner ", gstt.CurrentCorner, "deltax ", deltax, "deltay", deltay #print gstt.warpdest[gstt.Laser] homography.newEDH(gstt.Laser) settings.Write() # Change corner if Z key is pressed. if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]: if gstt.CurrentCorner < 3: gstt.CurrentCorner += 1 else: gstt.CurrentCorner = 0 print "Corner : ", gstt.CurrentCorner # Display all windows to current PL for display for Window in gstt.Windows: dots = [] for corner in xrange(len(Window)): #print "Editing : ", WindowPoints[corner] #print Window[corner][0] dots.append( proj(int(Window[corner][0]), int(Window[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) mouse_prev = gstt.mouse # EDIT WINDOWS MODE : cycle windows for current laser if press e key to adjust corner position # ENTER key to warp/display mode # Mouse to change current corner postion # Z key : next corner # E Key : Next window # A key : Next section if gstt.EditStep > 0: dots = [] CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow] # Draw all windows points or "corners" for corner in xrange(len(CurrentWindowPoints)): dots.append( proj(int(CurrentWindowPoints[corner][0]), int(CurrentWindowPoints[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) # Left mouse is clicked, modify current Corner coordinate if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2) CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2) # Change corner if Z key is pressed. if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]: if gstt.CurrentCorner < settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.CurrentCorner += 1 print "Corner : ", gstt.CurrentCorner # E Key : Next window if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[pygame.K_e]: # Save current Window and switch to the next one. if gstt.CurrentWindow < settings.Mapping( sections[gstt.CurrentSection]) - 1: print "saving " settings.MappingWrite(sections, str(gstt.CurrentWindow), CurrentWindowPoints) gstt.CurrentWindow += 1 gstt.CurrentCorner = -1 if gstt.CurrentWindow == settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.EditStep == 0 gstt.CurrentWindow = 0 print "Now Editing window ", gstt.CurrentWindow mouse_prev = gstt.mouse gstt.PL[PL] = fwork.LinesPL(PL) # A key : Next section ? if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]: print "current section : ", gstt.CurrentSection if gstt.CurrentSection < len(sections) - 1: gstt.CurrentSection += 1 print "Next section name is ", sections[gstt.CurrentSection] if "screen" in sections[gstt.CurrentSection]: print "" print "switching to section ", gstt.CurrentSection, " ", sections[ gstt.CurrentSection] MappingConf(gstt.CurrentSection) else: gstt.CurrentSection = -1
def NozMode(fwork): global f_sine, x # global dotsosc0 # global dotsosc1 global dotsoscT global currentdotsosc # global dotsosc0a # global dotsosc1a # global dotsoscTa # global currentdotsosca amp = 200 nb_point = 40 nbplow = 10 nbphigh = 100 # print "here we are in setllstrp.py" # print "gstt.maxCurvesByLaser", gstt.maxCurvesByLaser # print gstt.osc[4] # There is a sound curve to draw on X axis for curveNumber in range(0, gstt.maxCurvesByLaser): if gstt.X[curveNumber] % 127 != 0: #print "gstt.X != 0 (== %d)" % gstt.X #if (dotsosc.maxlen == nbphigh and gstt.Y != 0): if (dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen == nbphigh and gstt.Y[curveNumber] % 127 != 0): #shrink points list (it's a lissajou curve) print "X changing size of dotsocsT[%d][%d] (%d) to %d" % ( curveNumber, currentdotsosc[curveNumber], dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen, nbplow) dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbplow) xT = gstt.osc[gstt.X[curveNumber]] x = 3.5 * (extracc2scrX(xT) - screenSizeX / 2) #print "xT:%d,x:%d"%(xT,x) else: # Else (i.e. gstt.X == 0) use time for X axis and expand points list #print "gstt.X == 0" if (gstt.Y[curveNumber] % 127 != 0 and dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen == nbplow): print "X changing size of dotsocsT[%d][%d] (%d) to %d" % ( curveNumber, currentdotsosc[curveNumber], dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen, nbphigh) dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) xT = (((time.time() * gstt.XTimeAxe) % 65536) - 32768) x = 3.5 * (extracc2scrX(xT) - screenSizeX / 2) #print "xT:%d,x:%d"%(xT,x) # There is a sound curve to draw on Y axis if gstt.Y[curveNumber] % 127 != 0: #print "gstt.Y != 0 (== %d)" % gstt.Y if (dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen == nbphigh and gstt.X[curveNumber] % 127 != 0): print "Y changing size of dotsocsT[%d][%d] (%d) to %d" % ( curveNumber, currentdotsosc[curveNumber], dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen, nbplow) dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbplow) yT = gstt.osc[gstt.Y[curveNumber]] y = 3.5 * (extracc2scrY(yT) - screenSizeY / 2) #print "yT:%d,x:%d"%(yT,y) else: # Use time for X axis #print "gstt.Y == 0" if (gstt.X[curveNumber] % 127 != 0 and dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen == nbplow): print "Y changing size of dotsocsT[%d][%d] (%d) to %d" % ( curveNumber, currentdotsosc[curveNumber], dotsoscT[currentdotsosc[curveNumber]][curveNumber].maxlen, nbphigh) dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) yT = (((time.time() * gstt.YTimeAxe) % 65536) - 32768) y = 3.5 * (extracc2scrY(yT) - screenSizeY / 2) #print "y:%r,yT:%r" % (y,yT) #print "yT:%d,x:%d"%(yT,y) if gstt.X[curveNumber] % 127 == 0 and gstt.Y[curveNumber] % 127 == 0: x = 0 y = 0 #proj(int(x),int(y),Z,curveNumber)#Z sans perspective #gstt.cc[29]=0 #gstt.cc[30]=0 #gstt.cc[31]=0 #gstt.cc[21]=60 #gstt.cc[22]=60 newx, newy = proj(int(x), int(y), 0, curveNumber) # newx=newx-400 # newy=newy+100 #rPolyLineOneColor if gstt.X[curveNumber] % 127 != 0 and gstt.Y[curveNumber] % 127 == 0: if 1 < len(dotsoscT[currentdotsosc[curveNumber]] [curveNumber]) and newy > dotsoscT[ currentdotsosc[curveNumber]][curveNumber][-1][1]: #switching to the other points list queue in order to not trace the "return" laser line #as we don't know how to trace that particular segment formed by that new "return" point in black #destroy current queue dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) currentdotsosc[curveNumber] = (currentdotsosc[curveNumber] + 1) % 2 #print "Switching dotosc to #%d"%currentdotsosc #creating a new one dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) #we could try to let the previous queue disappear slowly… #instead of destroying it as stated above #if len(dotsoscT[(currentdotsosc+1)%2]): # dotsoscT[(currentdotsosc+1)%2].popleft() dotsoscT[currentdotsosc[curveNumber]][curveNumber].append( (newx, newy)) fwork.PolyLineOneColor(dotsoscT[0][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=0, closed=False) fwork.PolyLineOneColor(dotsoscT[1][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=0, closed=False) fwork.PolyLineOneColor(dotsoscT[0][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=1, closed=False) fwork.PolyLineOneColor(dotsoscT[1][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=1, closed=False) #print "dotsosc:%s,curveNumber:%d,color:%s" % (dotsoscT,curveNumber,colorify.rgb2hex(gstt.curveColor[curveNumber])) if gstt.X[curveNumber] % 127 == 0 and gstt.Y[curveNumber] % 127 != 0: if 1 < len(dotsoscT[currentdotsosc[curveNumber]] [curveNumber]) and newx < dotsoscT[ currentdotsosc[curveNumber]][curveNumber][-1][0]: dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) currentdotsosc[curveNumber] = (currentdotsosc[curveNumber] + 1) % 2 #print "Switching dotosc to #%d"%currentdotsosc dotsoscT[currentdotsosc[curveNumber]][ curveNumber] = collections.deque(maxlen=nbphigh) #if len(dotsoscT[(currentdotsosc+1)%2]): # dotsoscT[(currentdotsosc+1)%2].popleft() dotsoscT[currentdotsosc[curveNumber]][curveNumber].append( (newx, newy)) fwork.PolyLineOneColor(dotsoscT[0][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=0, closed=False) fwork.PolyLineOneColor(dotsoscT[1][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=0, closed=False) fwork.PolyLineOneColor(dotsoscT[0][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=1, closed=False) fwork.PolyLineOneColor(dotsoscT[1][curveNumber], c=colorify.rgb2hex( gstt.curveColor[curveNumber]), PL=1, closed=False) #print "dotsosc:%s,curveNumber:%d,color:%s" % (dotsoscT,curveNumber,colorify.rgb2hex(gstt.curveColor[curveNumber])) #if (gstt.X == 0 and gstt.Y == 0) or (gstt.X != 0 and gstt.Y != 0): if (gstt.X[curveNumber] % 127 != 0 and gstt.Y[curveNumber] % 127 != 0): #dotsosc.append((newx,newy)) dotsoscT[currentdotsosc[curveNumber]][curveNumber].append( (newx, newy)) #dotsoscT[0].append((newx,newy)) #dotsoscT[1].append((newx,newy)) #print "Plotting first lissajou curve" #print "gstt.X[0]=%d" % gstt.X[0] #print "gstt.Y[0]=%d" % gstt.Y[0] fwork.PolyLineOneColor( dotsoscT[currentdotsosc[curveNumber]][curveNumber], c=colorify.rgb2hex(gstt.curveColor[curveNumber]), PL=0, closed=False) fwork.PolyLineOneColor( dotsoscT[currentdotsosc[curveNumber]][curveNumber], c=colorify.rgb2hex(gstt.curveColor[curveNumber]), PL=1, closed=False) #gstt.PL[PL] = fwork.LinesPL(PL) gstt.PL[0] = fwork.LinesPL(0) gstt.PL[1] = fwork.LinesPL(1)
def Mapping(fwork, keystates, keystates_prev): global mouse_prev, sections, warpd PL = gstt.Laser dots = [] #switch to edit mode Key E ? if keystates[pygame.K_e] and not keystates_prev[ pygame.K_e] and gstt.EditStep == 0: print "Switching to Edit Mode" gstt.EditStep = 1 gstt.CurrentWindow = 0 gstt.CurrentCorner = 0 # Back to WARP mode if ENTER key is pressed ? if keystates[pygame.K_RETURN] and gstt.EditStep == 1: print "Switching to Warp Mode" gstt.EditStep = 0 gstt.CurrentCorner = 0 # EDIT MODE : cycle windows if press e key to adjust corner position # Escape edit mode with enter key if gstt.EditStep > 0: dots = [] CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow] # Draw all windows points or "corners" for corner in xrange(len(CurrentWindowPoints)): dots.append( proj(int(CurrentWindowPoints[corner][0]), int(CurrentWindowPoints[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) # Left mouse is clicked, modify current Corner coordinate if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2) CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2) # Change corner if Z key is pressed. if keystates[pygame.K_z] and not keystates_prev[pygame.K_z]: if gstt.CurrentCorner < settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.CurrentCorner += 1 print "Corner : ", gstt.CurrentCorner # Press E inside Edit mode : Next window if keystates[pygame.K_e] and not keystates_prev[pygame.K_e]: # Save current Window and switch to the next one. if gstt.CurrentWindow < settings.Mapping( sections[gstt.CurrentSection]) - 1: print "saving " settings.MappingWrite(sections, str(gstt.CurrentWindow), CurrentWindowPoints) gstt.CurrentWindow += 1 gstt.CurrentCorner = -1 if gstt.CurrentWindow == settings.Mapping( sections[gstt.CurrentSection]) - 1: gstt.EditStep == 0 gstt.CurrentWindow = 0 print "Now Editing window ", gstt.CurrentWindow mouse_prev = gstt.mouse gstt.PL[PL] = fwork.LinesPL(PL) # Press A : Next section ? if keystates[pygame.K_a] and not keystates_prev[pygame.K_a]: print "current section : ", gstt.CurrentSection if gstt.CurrentSection < len(sections) - 1: gstt.CurrentSection += 1 print "Next section name is ", sections[gstt.CurrentSection] if "screen" in sections[gstt.CurrentSection]: print "" print "switching to section ", gstt.CurrentSection, " ", sections[ gstt.CurrentSection] MappingConf(gstt.CurrentSection) else: gstt.CurrentSection = -1 # WARP Mode if gstt.EditStep == 0: #print "Warp mode" # Left mouse is clicked, modify current Corner coordinate #print gstt.mouse if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1: deltax = gstt.mouse[0][0] - mouse_prev[0][0] deltay = gstt.mouse[0][1] - mouse_prev[0][1] print "Laser ", gstt.Laser, " Corner ", gstt.CurrentCorner, "deltax ", deltax, "deltay", deltay #int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][0]) += (deltax *20) #int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][1]) += (deltay * 2) print warpd #print int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][0]) + (deltax * 20) # Change corner if Z key is pressed. if keystates[pygame.K_z] and not keystates_prev[pygame.K_z]: if gstt.CurrentCorner < 4: gstt.CurrentCorner += 1 print "Corner : ", gstt.CurrentCorner # Display all windows to current PL for display for Window in gstt.Windows: dots = [] for corner in xrange(len(Window)): #print "Editing : ", WindowPoints[corner] #print Window[corner][0] dots.append( proj(int(Window[corner][0]), int(Window[corner][1]), 0)) fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=PL, closed=False) gstt.PL[PL] = fwork.LinesPL(PL) mouse_prev = gstt.mouse
def Pose(fwork): PL = 0 dots = [] #posename =gstt.PoseDir+'snap_000000000'+str("%03d"%gstt.CurrentPose)+'_keypoints.json' #pose_dir = 'detroit1' #gstt.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] != '.') #print "Pose : ", pose_dir, gstt.numfiles, "images" posename = 'poses/' + pose_dir + '/' + pose_dir + '-' + str( "%05d" % gstt.CurrentPose) + '.json' # skip empty filed while os.path.getsize(posename) == 159 or os.path.getsize(posename) == 430: posename = 'poses/' + pose_dir + '/' + pose_dir + '-' + str( "%05d" % gstt.CurrentPose) + '.json' if gstt.keystates[pygame.K_w]: gstt.CurrentPose -= 1 if gstt.keystates[pygame.K_x]: gstt.CurrentPose += 1 posefile = open(posename, 'r') posedatas = posefile.read() pose_json = json.loads(posedatas) # Body ''' print "" print "Frame : ",gstt.CurrentPose print "body :", bodyCOCO(pose) print "arm :", armCOCO(pose) print 'head :', headCOCO(pose) print "eyeR :", eyeR(pose) print "eyeL :", eyeL(pose) print "mouth :", mouth(pose) fwork.rPolyLineOneColor(bodyCOCO(pose_json,0), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(armCOCO(pose_json,0), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) #fwork.rPolyLineOneColor(headCOCO(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) # Face #fwork.rPolyLineOneColor(face(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(browL(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(browR(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(eyeR(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(eyeL(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(nose(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(mouth(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) if len(pose_json['people']) != 1: print "people 1 pose ", pose_json['people'][1]['pose_keypoints_2d'] print len(pose_json['people']) fwork.rPolyLineOneColor(bodyCOCO(pose_json,1), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) fwork.rPolyLineOneColor(armCOCO(pose_json,1), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = 200, ypos = 200, resize = 200) ''' for people in range(len(pose_json['people'])): fwork.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=300) gstt.PL[PL] = fwork.LinesPL(PL) # decrease current frame if gstt.keystates[pygame.K_w]: # and not gstt.keystates_prev[pygame.K_w]: gstt.CurrentPose -= 1 if gstt.CurrentPose < 2: gstt.CurrentPose = gstt.numfiles - 1 #time.sleep(0.033) print "Frame : ", gstt.CurrentPose # increaser current frame if gstt.keystates[pygame.K_x]: # and not gstt.keystates_prev[pygame.K_x]: gstt.CurrentPose += 1 if gstt.CurrentPose > gstt.numfiles - 1: gstt.CurrentPose = 1 #time.sleep(0.033) print "Frame : ", gstt.CurrentPose
def LaserID(fwork): # "0" on laser 0 message = "0" len_message = len(message) i = 0 for char in message: i += 1 # x offset for each letter depends on message length x_offset = 26 * (-(0.9 * len_message) + 3 * i) char_dots = font1.ASCII_GRAPHICS[ord(char) - 47] for dot_pl in char_dots: dots = [] for dot in dot_pl: dots.append((x_offset + dot[0], dot[1])) fwork.rPolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False, xpos=200, ypos=200, resize=1) gstt.PL[0] = fwork.LinesPL(0) # "1" on laser 1 message = "1" len_message = len(message) i = 0 for char in message: i += 1 # x offset for each letter depends on message length x_offset = 26 * (-(0.9 * len_message) + 3 * i) char_dots = font1.ASCII_GRAPHICS[ord(char) - 47] for dot_pl in char_dots: dots = [] for dot in dot_pl: dots.append((x_offset + dot[0], dot[1])) fwork.rPolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=1, closed=False, xpos=200, ypos=200, resize=1) gstt.PL[1] = fwork.LinesPL(1) # "2" on laser 2 message = "2" len_message = len(message) i = 0 for char in message: i += 1 # x offset for each letter depends on message length x_offset = 26 * (-(0.9 * len_message) + 3 * i) char_dots = font1.ASCII_GRAPHICS[ord(char) - 47] for dot_pl in char_dots: dots = [] for dot in dot_pl: dots.append((x_offset + dot[0], dot[1])) fwork.rPolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=2, closed=False, xpos=200, ypos=200, resize=1) gstt.PL[2] = fwork.LinesPL(2)
def xPLS(fwork): global f_sine # middle horizontal line # point list "PL" 0 generator (assigned to laser 0 in setexample.conf) dots = [] x = (int(screen_size[1]) / 2) - 50 y = (int(screen_size[0]) / 2) dots.append((int(x), int(y))) dots.append((int((int(screen_size[1]) / 2) + 50), (int(y)))) # add the line to the current "frame" of PL 0 fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=0, closed=False) # transfer full frame to automatic laser display PL 0 : gstt.PL[0] = fwork.LinesPL(0) # middle vertical line # PL 1 generator (assigned to laser 1 in setexample.conf) dots = [] #pdb.set_trace() x = int(screen_size[1]) / 2 y = (int(screen_size[1]) / 2) - 50 dots.append((int(x), int(y))) dots.append((int(x), (int(screen_size[1]) / 2) + 50)) # add the line to the current "frame" of PL 1 fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=1, closed=False) # transfer full frame to automatic laser display PL 1 : gstt.PL[1] = fwork.LinesPL(1) # Some Lissajoux function. # PL 2 generator (assigned to laser 2 in setexample.conf PL = 2 dots = [] amp = 200 nb_point = 40 for t in range(0, nb_point + 1): y = 0 - amp * math.sin(2 * PI * (float(t) / float(nb_point))) x = 0 - amp * math.cos(2 * PI * f_sine * (float(t) / float(nb_point))) dots.append(proj(int(x), int(y), 0)) # add the polyline to the current "frame" of PL 2 fwork.PolyLineOneColor(dots, c=colorify.rgb2hex(gstt.color), PL=2, closed=False) # transfer full frame to automatic laser display PL 2 : gstt.PL[2] = fwork.LinesPL(2) if f_sine > 24: f_sine = 0 f_sine += 0.01
def Starfield(fwork,hori=0,verti=0): gstt.starfieldcount += 1 #print gstt.starfieldcount starpoints = [] # Move starfield according to joypads. Not used in the demo ''' # Tflight joystick : # y axis 1 top -1 bottom 1 # x axis 0 left -1 right 1 # Main fire button 5 # hat (x,y) x -1 left x 1 right y -1 bottom y 1 top # speed axis 3 backward 1 forward -1 if gstt.Nbpads > 0: # Move center on X axis according to pad if gstt.pad1.get_axis(0)<-0.1 or gstt.pad1.get_axis(0)>0.1: hori = gstt.pad1.get_axis(0) #print hori # Move center on Y axis according to pad if gstt.pad1.get_axis(1)<-0.1 or gstt.pad1.get_axis(1)>0.1: verti= gstt.pad1.get_axis(1) #print verti ''' #print gstt.displayedstars, 'stars displayed' # Increase number of if gstt.displayedstars < gstt.num_stars and gstt.starfieldcount % 15 == 0: gstt.displayedstars += 1 if gstt.displayedstars == gstt.num_stars and gstt.starfieldcount % 10 == 0: gstt.starspeed += 0.005 if gstt.Nbpads > 0: gstt.starspeed = (1-gstt.pad1.get_axis(3)) #print gstt.starspeed for starnumber in range(0,gstt.displayedstars): # The Z component is decreased on each frame. gstt.stars0[starnumber][2] -= gstt.starspeed * 3 gstt.stars1[starnumber][2] -= gstt.starspeed * 3 gstt.stars2[starnumber][2] -= gstt.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 gstt.stars0[starnumber][2] <= 0: gstt.stars0[starnumber][0] = randrange(-25,25) gstt.stars0[starnumber][1] = randrange(-25,25) gstt.stars0[starnumber][2] = gstt.max_depth if gstt.stars1[starnumber][2] <= 0: gstt.stars1[starnumber][0] = randrange(-25,25) gstt.stars1[starnumber][1] = randrange(-25,25) gstt.stars1[starnumber][2] = gstt.max_depth if gstt.stars2[starnumber][2] <= 0: gstt.stars2[starnumber][0] = randrange(-25,25) gstt.stars2[starnumber][1] = randrange(-25,25) gstt.stars2[starnumber][2] = gstt.max_depth # Convert the 3D coordinates to 2D using perspective projection. k0 = 128.0 / gstt.stars0[starnumber][2] k1 = 128.0 / gstt.stars1[starnumber][2] k2 = 128.0 / gstt.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(gstt.stars0[starnumber][0]) == np.sign(hori): x0 = int(gstt.stars0[starnumber][0] * k0 + xy_center[0] + (hori*600)) else: x0 = int(gstt.stars0[starnumber][0] * k0 + xy_center[0] + (hori*300)) if np.sign(gstt.stars0[starnumber][1]) == np.sign(verti): y0 = int(gstt.stars0[starnumber][1] * k0 + xy_center[1] + (verti*600)) else: y0 = int(gstt.stars0[starnumber][1] * k0 + xy_center[1] + (verti*300)) if np.sign(gstt.stars1[starnumber][0]) == np.sign(hori): x1 = int(gstt.stars1[starnumber][0] * k1 + xy_center[0] + (hori*600)) else: x1 = int(gstt.stars1[starnumber][0] * k1 + xy_center[0] + (hori*300)) if np.sign(gstt.stars1[starnumber][1]) == np.sign(verti): y1 = int(gstt.stars1[starnumber][1] * k1 + xy_center[1] + (verti*600)) else: y1 = int(gstt.stars1[starnumber][1] * k1 + xy_center[1] + (verti*300)) if np.sign(gstt.stars2[starnumber][0]) == np.sign(hori): x2 = int(gstt.stars2[starnumber][0] * k2 + xy_center[0] + (hori*600)) else: x2 = int(gstt.stars2[starnumber][0] * k2 + xy_center[0] + (hori*300)) if np.sign(gstt.stars2[starnumber][1]) == np.sign(verti): y2 = int(gstt.stars2[starnumber][1] * k2 + xy_center[1] + (verti*600)) else: y2 = int(gstt.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: #f.LineTo((x,y), 0x80000000) fwork.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c=colorify.rgb2hex([255,255,255]), PL = 0, closed = False) # Add star to pointlist PL 1 if 0 <= x1 < screen_size[0] - 2 and 0 <= y1 < screen_size[1] - 2: fwork.PolyLineOneColor([(x1,y1),((x1+1),(y1+1))], c=colorify.rgb2hex([255,255,255]), PL = 1, closed = False) # Add star to pointlist PL 2 #if 0 <= x2 < screen_size[0] - 2 and 0 <= y2 < screen_size[1] - 2: # fwork.PolyLineOneColor([(x2,y2),((x2+1),(y2+1))], c=colorify.rgb2hex([255,255,255]), PL = 2, closed = False) # #f.PolyLineOneColor([(x,y),((x+2),(y+2))], COLOR_WHITE) ''' if gstt.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) ''' # Point list 4 is a text. Text(fwork,3,250,300,1) gstt.PL[0] = fwork.LinesPL(0) gstt.PL[1] = fwork.LinesPL(1) gstt.PL[2] = fwork.LinesPL(2)
def Draw(self, f): #f.LineTo((self.centerX,self.centerY), 0x000000) ''' self.angleX += 0.0 self.angleY += 0.0 self.angleZ += 0.0 ''' PL = 0 self.joypads() gstt.angleX += self.cc2range(gstt.cc[29], 0, 0.1) gstt.angleY += self.cc2range(gstt.cc[30], 0, 0.1) gstt.angleZ += self.cc2range(gstt.cc[31], 0, 0.1) for number in range(int(self.cc2range(gstt.cc[6], 1, 10))): planet = self.planets[number] planet[0] += self.cc2range(gstt.cc[5], 0, 25) rad = planet[0] * PI / 180 r = (planet[1] * (1 - planet[2]**2)) / (1 + (planet[2] * math.cos(rad))) #* gstt. x = r * math.cos(rad) y = r * math.sin(rad) z = 0 # print x,y,z # 3D rotation along self.angleX, self.angleX, self.angleX rad = gstt.angleX * PI / 180 cosa = math.cos(rad) sina = math.sin(rad) y2 = y y = y2 * cosa - z * sina z = y2 * sina + z * cosa rad = gstt.angleY * PI / 180 cosa = math.cos(rad) sina = math.sin(rad) z2 = z z = z2 * cosa - x * sina x = z2 * sina + x * cosa rad = gstt.angleZ * PI / 180 cosa = math.cos(rad) sina = math.sin(rad) x2 = x x = x2 * cosa - y * sina y = x2 * sina + y * cosa #print x,y # 3D to 2D projection factor = 4 * gstt.cc[22] / ((gstt.cc[21] * 8) + z) x = x * factor + self.centerX + gstt.cc[1] - 100 y = -y * factor + self.centerY - gstt.cc[2] ''' angle = 90 angle = angle * PI / 180 x2 = x* math.cos(angle) - y*math.sin(angle) y2 = x* math.sin(angle) + y*math.cos(angle) x2 = x2 * factor + self.centerX y2 = - y2 * factor + self.centerY angle = 270 angle = angle * PI / 180 x3 = x* math.cos(angle) - y*math.sin(angle) y3 = x* math.sin(angle) + y*math.cos(angle) x3 = x2 * factor + self.centerX y3 = - y3 * factor + self.centerY ''' #print x,y f.Line((x, y), (x + 5, y + 5), c=colorify.rgb2hex(gstt.color), PL=PL) #f.Line((x2,y2),(x2+5,y2+5), c=colorify.rgb2hex(gstt.color)) #f.Line((x3,y3),(x3+5,y3+5), c=colorify.rgb2hex(gstt.color)) gstt.PL[PL] = f.LinesPL(PL)