def __init__(self, windowX: int, windowY: int, width=120, height=30, isNew=False, isMoving=False, imagePath='images/floor.png'): super().__init__(imagePath, windowX, windowY, width, height) self.__isMoving = isMoving # 地板是否左右移动 currHeight = Floor.lastHeight + randint(70, 90) self._rect.x = randint(0, windowX - width) self._rect.y = 50 if isNew else windowY - currHeight Floor.lastHeight = currHeight # 板子上面的东西:火箭 弹簧 怪物 等... self.__itemOn = None if randint(0, 100) < 20: self.__itemOn = Spring(windowX, windowY) self.__itemOn.attachTo(self) if randint(0, 100) < 20: self.__itemOn = Rocket(windowX, windowY, self.getLeft(), self.getTop()) self.__itemOn.attachTo(self)
def init_window(self): self.parent.title("SupMold: SpringCalc") self.grid(column=0, row=0, sticky="nwse") mainFrame = Frame(self, relief='raised', borderwidth=1) mainFrame.grid(column=0, row=0, sticky='nsew') closeButton = Button(mainFrame, text='Cerrar', command=self.appQuit) closeButton.grid(column=0, row=3, padx=5, pady=5) nb = Notebook(mainFrame) tab1 = Frame(nb) tab2 = Frame(nb) tab3 = Frame(nb) nb.add(tab1, text="Compresión") nb.add(tab2, text="Extensión") nb.add(tab3, text="Torsión") nb.grid(column=0, row=1, sticky='nsew', padx=5, pady=5) msg = consoleFrame(mainFrame, 'Mensages') dataB = resource_path('wires.db') if not os.path.isfile(dataB): self.centerWindow() messagebox.showerror( "ERROR", "Base de datos {} inaccesible. " "Favor verificar permisos de lectura o " "ubicación de la misma".format(dataB)) return self.sub1 = subWindow(tab1, Spring(database=dataB)) self.sub1.init_widgets() self.sub2 = subWindow2(tab2, eSpring(database=dataB)) self.sub2.init_widgets() self.sub3 = subWindow3(tab3, tSpring(database=dataB)) self.sub3.init_widgets() self.centerWindow() nb.bind("<<NotebookTabChanged>>", self.tabChangedEvent)
def _ChooseNextNodeLocation(self): node_list = self.FindAttachmentNodes() for node in node_list: self.AddObject(Spring(node, self.next_node)) self.AddObject(self.next_node) self.GenerateNextNode() sound = random.choice(self.placement_sound_list) sound.play()
def __init__(self, start, board): width = 26 obstacles = [] obstacles.append(Spring(start + 3, 6, board)) coin_row(Point(8, start + 6), Dimension(10, 1), board) enemy = [] enemy.append(SlaveEnemy(FLOOR - 2, start, board)) enemy.append(SlaveEnemy(FLOOR - 2, start + 13, board)) Hurdle.__init__(self, start, width, obstacles, enemy, board) self.load()
def spring_start(self): self.spring = Spring(self.time_counter, self.sound_stopper) Pin_height = int(self.currentTrial[3]) if 1 <= Pin_height and Pin_height <= 3: self.spring.set_profile(self.currentTrial[2], 'long') elif 4 <= Pin_height and Pin_height <= 6: self.spring.set_profile(self.currentTrial[2], 'middle') elif 7 <= Pin_height and Pin_height <= 9: self.spring.set_profile(self.currentTrial[2], 'short') self.spring.start()
def __init__(self, x, y, length, sections, s_const): sec_length = length / sections self.masses = [PointMass(x, y, 1, True)] self.springs = [] cur_y = y for mass in range(sections): cur_y += sec_length self.masses.append(PointMass(x, cur_y, 1)) for spring in range(sections): self.springs.append( Spring(self.masses[spring], self.masses[spring + 1], s_const, sec_length))
def get_func_deriv(k): """ Get the energy value and its derivative for given k value """ f = np.pi spr = Spring(k) u = spr.solve(0, f) E = spr.F(u) dRdk = spr.dRdk(u) dFdk = spr.dFdk(u) dRdq = spr.dRdq(u) dFdq = spr.dFdq(u) lam = spr.adjoint_solve(u) DFDx = dFdk + lam * dRdk return E, DFDx
def __init__(self): '''Initialization''' self.over = False self.height = 30 self.width = 90 self.score = 0 self.coins = 0 self.layout = [] self.enemyarr = [] self.pipearr = [ Pipe(18, 315), Pipe(18, 60), Pipe(18, 120), Pipe(18, 165) ] self.springarr = [ Spring(19, 337), Spring(19, 390) ] self.brickarr = [ Brick("unbreakable", 18, 37), Brick( "breakable", 18, 40), Brick("unbreakable", 18, 43), Brick( "breakable", 14, 40), Brick("breakable", 18, 113), Brick( "unbreakable", 14, 121), Brick("unbreakable", 10, 129), Brick( "unbreakable", 18, 235), Brick("unbreakable", 18, 225), Brick( "unbreakable", 18, 245), Brick("unbreakable", 14, 230), Brick( "unbreakable", 14, 240), Brick("breakable", 10, 235), Brick( "breakable", 10, 135), Brick("unbreakable", 14, 143), Brick( "unbreakable", 18, 151), Brick("unbreakable", 21, 340), Brick( "unbreakable", 13, 340), Brick("unbreakable", 20, 340), Brick( "unbreakable", 19, 340), Brick("unbreakable", 18, 340), Brick( "unbreakable", 17, 340), Brick("unbreakable", 16, 340), Brick( "unbreakable", 15, 340), Brick("unbreakable", 14, 340) ] self.coinarr = [ Coin(21, 39), Coin(21, 41), Coin(21, 43), Coin(13, 40), Coin(9, 129), Coin(9, 235), Coin(13, 230), Coin(13, 240), Coin(17, 235) ] for _ in range(self.height): self.layout.append([]) for i in range(self.height): for _ in range(self.width): self.layout[i].append(' ') # Fixed Score, lives and coins in the 1st row self.layout[0][0:6] = 'Score:' self.layout[0][40:46] = 'Lives:' self.layout[0][60:66] = 'Coins:'
def createBackground(self): '''generate ground''' self.createBase() '''generate clouds''' x = 60 y = 6 while x < self.width: self.createCloud(4 + y, x) x = x + 50 y = y + 3 y = y % 6 '''generate mountains''' self.createMountain(28, 6, 30, 1) self.createMountain(28, 6, 405, 1) self.createMountain(28, 6, 490, 1) self.createMountain(28, 6, 550, 1) self.createMountain(28, 6, 650, 1) self.createMountain(28, 6, 960, 1) self.createMountain(28, 6, 1055, 1) '''generate bricks''' c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 130, 25) self.bricks.append([c, 130, 25]) self.createBricks(self.green + '#' + self.reset, 150, 25) self.bricks.append([self.green + '#' + self.reset, 150, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 155, 25) self.bricks.append([c, 155, 25]) self.createBricks(self.green + '#' + self.reset, 160, 25) self.bricks.append([self.green + '#' + self.reset, 160, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 165, 25) self.bricks.append([c, 165, 25]) self.createBricks(self.green + '#' + self.reset, 170, 25) self.bricks.append([self.green + '#' + self.reset, 170, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 160, 10) self.bricks.append([c, 160, 10]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 520, 24) self.bricks.append([c, 520, 24]) self.createBricks(self.green + '#' + self.reset, 525, 24) self.bricks.append([self.green + '#' + self.reset, 525, 24]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 530, 24) self.bricks.append([c, 530, 24]) for i in range(500, 560, 5): self.createBricks(self.green + '#' + self.reset, i, 10) self.bricks.append([self.green + '#' + self.reset, i, 10]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 660, 25) self.bricks.append([c, 660, 25]) self.createBricks(self.green + '#' + self.reset, 705, 25) self.bricks.append([self.green + '#' + self.reset, 705, 25]) self.createBricks(self.green + '#' + self.reset, 710, 25) self.bricks.append([self.green + '#' + self.reset, 710, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 760, 25) self.bricks.append([c, 760, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 770, 25) self.bricks.append([c, 770, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 780, 25) self.bricks.append([c, 780, 25]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 770, 10) self.bricks.append([c, 770, 10]) self.createBricks(self.green + '#' + self.reset, 810, 25) self.bricks.append([self.green + '#' + self.reset, 810, 25]) self.createBricks(self.green + '#' + self.reset, 825, 10) self.bricks.append([self.green + '#' + self.reset, 825, 10]) self.createBricks(self.green + '#' + self.reset, 830, 10) self.bricks.append([self.green + '#' + self.reset, 830, 10]) self.createBricks(self.green + '#' + self.reset, 835, 10) self.bricks.append([self.green + '#' + self.reset, 835, 10]) self.createBricks(self.green + '#' + self.reset, 855, 10) self.bricks.append([self.green + '#' + self.reset, 855, 10]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 860, 10) self.bricks.append([c, 860, 10]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 865, 10) self.bricks.append([c, 865, 10]) self.createBricks(self.green + '#' + self.reset, 870, 10) self.bricks.append([self.green + '#' + self.reset, 870, 10]) self.createBricks(self.green + '#' + self.reset, 860, 24) self.bricks.append([self.green + '#' + self.reset, 860, 24]) self.createBricks(self.green + '#' + self.reset, 865, 24) self.bricks.append([self.green + '#' + self.reset, 865, 24]) self.createBricks(self.green + '#' + self.reset, 1100, 24) self.bricks.append([self.green + '#' + self.reset, 1100, 24]) self.createBricks(self.green + '#' + self.reset, 1105, 24) self.bricks.append([self.green + '#' + self.reset, 1105, 24]) self.createBricks(self.green + '#' + self.reset, 1110, 24) self.bricks.append([self.green + '#' + self.reset, 1110, 24]) c = random.choice([ self.red + '1' + self.reset, self.red + '2' + self.reset, self.red + '3' + self.reset ]) self.createBricks(c, 1115, 24) self.bricks.append([c, 1115, 24]) self.createBricks(self.green + '#' + self.reset, 1120, 24) self.bricks.append([self.green + '#' + self.reset, 1120, 24]) '''generate pipes''' self.createPipes(185, 13, 6) self.createPipes(250, 13, 8) self.createPipes(310, 13, 12) self.createPipes(370, 13, 12) self.createPipes(1070, 13, 6) self.createPipes(1200, 13, 6) '''generate pits''' self.createPit(440, 40) self.createPit(580, 30) self.createPit(1005, 18) '''generate stairs''' self.createStairs(890, 33, 4, 4, 1) self.createStairs(920, 33, 4, 4, 0) self.createStairs(980, 33, 5, 5, 1) self.createStairs(1023, 33, 4, 4, 0) self.createStairs(1230, 33, 7, 7, 1) '''generate enemies''' self.enemies.append(Enemy('(E)', 180, 30, time.time())) self.enemies.append(Enemy('(E)', 263, 25, time.time())) self.enemies.append(Enemy('(E)', 330, 26, time.time())) self.enemies.append(Enemy('(E)', 365, 23, time.time())) self.enemies.append(Enemy('(E)', 530, 33, time.time())) self.smartEnemies.append(SmartEnemy('(E)', 694, 33, time.time())) self.smartEnemies.append(SmartEnemy('(E)', 780, 30, time.time())) self.enemies.append(Enemy('(E)', 850, 30, time.time())) self.enemies.append(Enemy('(E)', 975, 30, time.time())) self.enemies.append(Enemy('(E)', 950, 33, time.time())) self.enemies.append(Enemy('(E)', 1096, 33, time.time())) self.smartEnemies.append(SmartEnemy('(E)', 100, 20, time.time())) '''generate coins''' self.createCoins(90, 33) self.coins.append([90, 33]) self.createCoins(190, 27) self.coins.append([190, 27]) for i in range(280, 300, 5): self.createCoins(i, 33) self.coins.append([i, 33]) self.createCoins(420, 33) self.coins.append([420, 33]) self.createCoins(525, 20) self.coins.append([525, 20]) self.createCoins(570, 20) self.coins.append([570, 20]) for i in range(730, 750, 5): self.createCoins(i, 20) self.coins.append([i, 20]) for i in range(1160, 1180, 5): self.createCoins(i, 25) self.coins.append([i, 25]) '''generate bridge''' self.createBridge() '''generate boundary''' for i in range(self.height): self.grid[i][self.width - 1] = '#' ''' generate spring ''' self.springs.append(Spring(5, 430, 31)) for i in self.springs: self.createSpring(i) ''' draw castle ''' self.createCastle()
DFDx = dFdk + lam * dRdk return E, DFDx # Create random parameters pfactory = ParameterFactory() K = pfactory.createNormalParameter( 'K', dict(mu=np.pi / 2., sigma=0.1 * (np.pi / 2.)), 7) # Add random parameters into a container and initialize pc = ParameterContainer() pc.addParameter(K) pc.initialize() # Create deterministic and stochastic spring elements dspr = Spring(k=np.pi / 2.) sspr = StochasticSpring(dspr, pc) ####################################################################### # Test the system ####################################################################### # Assemble stochastic force vector from deterministic vector f = np.pi U = sspr.solve(0, f) # E = dspr.F(uhat) # print("force :", f) # print("disp :", U) # Decompose f(y) and dfdx(y) in stochastic basis E = np.zeros((sspr.nsdof))
def object_generator(): return Spring(1, 1)
def retry(self): # Recognition Load question answer if self.currentTrial[1] == '1': if len(self.entry_Answer.get()) == 0: tkMessageBox.showinfo( 'Warning', message='Select the Electronic Element before retry') return else: if self.entry_Answer.get().strip().isdigit() and 0 < int( self.entry_Answer.get().strip()) < 10: self.user_choice = int(self.entry_Answer.get()) else: tkMessageBox.showinfo( title='Notice', message='Your Choice MUST BE Integer in [1-9]') return result = tkMessageBox.askyesno( 'Notice', message='Your Recognition Load Choice: ' + str(self.user_choice) + '\nCan you confirm ?') if result is True: pass else: return else: self.user_choice = -1 self.Question_text.set("") self.Question_choice_row_1.set("") self.Question_choice_row_2.set("") self.Question_choice_row_3.set("") self.Answer.set("") self.write_info += str(self.deltatime) + "," if self.User_feel_FP != 'None': self.write_info += str( self.cmd.Force_Profile.index(self.User_feel_FP)) + "," if self.User_feel_FP == self.currentTrial[3]: self.write_info += str(1) + "," self.correct_times += 1 print str(self.correct_times) + "/" + str( self.global_times_counter) else: self.write_info += str(0) + "," else: self.write_info += str(8) + ',' self.write_info += str(self.ask_last_num) + "," if self.currentTrial[1] == '1': self.write_info += str( self.play_electronic_element.last_i_th( self.ask_last_num)) + "," self.write_info += str(self.user_choice) + "," if int(self.user_choice) == int( self.play_electronic_element.last_i_th(self.ask_last_num)): self.write_info += str(1) + "\n" else: self.write_info += str(0) + "\n" else: self.write_info += str(-1) + "," self.write_info += str(self.user_choice) + "," self.write_info += str(-1) + "\n" self.outputfile.write(self.write_info) self.outputfile.flush() self.write_info = "" # Begin the next trial print self.currentTrial self.global_times_counter -= 1 # Current/Total times self.write_info += str( self.user_num) + "," + self.user_name + "," + str( self.user_age) + "," + self.user_gender + "," if self.startTrialNum == 0: current_time = self.global_times_counter + 1 else: current_time = self.global_times_counter + self.startTrialNum self.show_info += str(current_time) + "\t\t" self.write_info += str(current_time) + "," for i in range(len(self.currentTrial)): if i == 0: self.pin_height = self.currentTrial[i] self.write_info += str( self.cmd.condition_lookup_table.index( self.pin_height)) + "," if i == 1: if self.currentTrial[i] == '1': self.show_info += "True\t\t" self.write_info += "1," else: self.show_info += "False\t\t" self.write_info += "0," if i == 2: if self.currentTrial[i] == '1': self.show_info += "Dominant\t " self.write_info += "1," else: self.show_info += "Non-Dominant\t " self.write_info += "0," if i == 3: self.Debug_Info.set("FP: " + self.currentTrial[i]) self.write_info += str( self.cmd.Force_Profile.index(self.currentTrial[i])) + "," if i == 4: self.show_info += self.cmd.Electronic_Element_Component_lookup[ self.currentTrial[i]] self.write_info += self.currentTrial[i] + "," self.PressSpaceTwice = False self.TrialInfo.set(self.show_info) self.Position_Info.set( str(self.correct_RL_times) + "/" + str(self.RL_total)) self.show_info = "" self.global_times_counter += 1 self.EnterPressTime += 1 # Create thread for handling haptic Spring #self.spring = Spring(self.Position_Info.set) self.spring = Spring() Pin_height = int(self.currentTrial[4]) if 1 <= Pin_height and Pin_height <= 3: self.spring.set_profile(self.currentTrial[3], 'long') elif 4 <= Pin_height and Pin_height <= 6: self.spring.set_profile(self.currentTrial[3], 'middle') elif 7 <= Pin_height and Pin_height <= 9: self.spring.set_profile(self.currentTrial[3], 'short') self.spring.start()
def EnterPress(self, event): # Incomplete Personal Information if self.EnterPressTime == 0: if self.user_num == -1 or self.user_name == "" or self.user_gender == "" or self.user_age == "": tkMessageBox.showinfo( 'Warning', message='Complete Personal Info before proceed') return # the first time press [Enter]: show a Trial Information if self.EnterPressTime == 0: start_num = self.startTrialNum if start_num == 0: self.currentTrial = self.cmd.read_command_by_line() while start_num != 0: self.currentTrial = self.cmd.read_command_by_line() start_num -= 1 print self.currentTrial # Current/Total times self.write_info += str( self.user_num) + "," + self.user_name + "," + str( self.user_age) + "," + self.user_gender + "," if self.startTrialNum == 0: current_time = self.global_times_counter + 1 else: current_time = self.global_times_counter + self.startTrialNum self.show_info += " " + str(current_time) + "\t " self.write_info += str(current_time) + "," for i in range(len(self.currentTrial)): if i == 0: self.pin_height = self.currentTrial[i] self.write_info += str( self.cmd.condition_lookup_table.index( self.pin_height)) + "," if i == 1: if self.currentTrial[i] == '1': self.show_info += " True\t\t" self.write_info += "1," else: self.show_info += " False\t\t" self.write_info += "0," if i == 2: if self.currentTrial[i] == '1': self.show_info += "Dominant\t " self.write_info += "1," else: self.show_info += "Non-Dominant\t " self.write_info += "0," if i == 3: self.write_info += str( self.cmd.Force_Profile.index( self.currentTrial[i])) + "," self.Debug_Info.set("FP: " + self.currentTrial[i]) if i == 4: self.show_info += self.cmd.Electronic_Element_Component_lookup[ self.currentTrial[i]] self.write_info += self.currentTrial[i] + "," self.TrialInfo.set(self.show_info) self.global_times_counter += 1 self.show_info = "" # Create thread for handling haptic Spring #self.spring = Spring(self.Position_Info.set) self.spring = Spring() Pin_height = int(self.currentTrial[4]) if 1 <= Pin_height and Pin_height <= 3: self.spring.set_profile(self.currentTrial[3], 'long') elif 4 <= Pin_height and Pin_height <= 6: self.spring.set_profile(self.currentTrial[3], 'middle') elif 7 <= Pin_height and Pin_height <= 9: self.spring.set_profile(self.currentTrial[3], 'short') self.spring.start() elif self.EnterPressTime % 2 == 1: # Incomplete Haptic Test Start--End if self.PressSpaceTwice is False: tkMessageBox.showinfo( 'Warning', message='Finish Haptic Test before proceed Press [Space]') return if len(self.entry_Answer.get()) == 0: tkMessageBox.showinfo( 'Warning', message='Enter your haptic feel before proceed') return else: if self.entry_Answer.get().strip().isdigit() and 0 < int( self.entry_Answer.get().strip()) < 10: self.User_feel_FP = self.haptic_feel_lookup[int( self.entry_Answer.get())] result = tkMessageBox.askyesno( title='Notice', message='Your Haptic Choice: ' + self.User_feel_FP + '\nCan you confirm ?') if result is True: pass else: return else: tkMessageBox.showinfo( title='Warning', message='Your Choice MUST BE Integer in [1-9]') return self.Answer.set("") # Show the recognition load question if self.currentTrial[1] == '1': self.ask_last_num = random.randrange( 1, 4) # random number for quiz of last element if self.ask_last_num > self.trackLength: self.ask_last_num = self.trackLength self.Question_text.set("Select the Last " + str(self.ask_last_num) + " Electronic Element\n") self.Question_choice_row_1.set("1. 光敏电阻\t2. 发光二极管\t3. 电阻") self.Question_choice_row_2.set("4. 场效应管\t5. 三极管\t6. 电容") self.Question_choice_row_3.set("7. 芯片\t\t8. 电位器\t9. 跳线") base_question_x = 19 * self.width / 64 base_question_y = 11 * self.height / 16 base_question_y_row_1 = base_question_y + 30 base_question_y_row_2 = base_question_y_row_1 + 30 base_question_y_row_3 = base_question_y_row_2 + 30 self.Question.place(x=base_question_x, y=base_question_y, anchor=W) self.Choice_row_1.place(x=base_question_x, y=base_question_y_row_1, anchor=W) self.Choice_row_2.place(x=base_question_x, y=base_question_y_row_2, anchor=W) self.Choice_row_3.place(x=base_question_x, y=base_question_y_row_3, anchor=W) self.Question.config(font=("Courier", 20, "bold"), fg="red") self.Choice_row_1.config(font=("Courier", 20, "bold"), fg="black") self.Choice_row_2.config(font=("Courier", 20, "bold"), fg="black") self.Choice_row_3.config(font=("Courier", 20, "bold"), fg="black") else: self.ask_last_num = -1 self.Question_text.set( "No Question just Press [Enter] to Proceed") # Write the current user trial data information to output file # and choice and show a trial Information elif self.EnterPressTime % 2 == 0: # Recognition Load question answer if self.currentTrial[1] == '1': if len(self.entry_Answer.get()) == 0: tkMessageBox.showinfo( 'Warning', message='Select the Electronic Element before proceed') return else: if self.entry_Answer.get().strip().isdigit() and 0 < int( self.entry_Answer.get().strip()) < 10: self.user_choice = int(self.entry_Answer.get()) else: tkMessageBox.showinfo( title='Notice', message='Your Choice MUST BE Integer in [1-9]') return result = tkMessageBox.askyesno( 'Notice', message='Your Recognition Load Choice: ' + str(self.user_choice) + '\nCan you confirm ?') if result is True: pass else: return else: self.user_choice = -1 self.Question_text.set("") self.Question_choice_row_1.set("") self.Question_choice_row_2.set("") self.Question_choice_row_3.set("") self.Answer.set("") self.write_info += str(self.deltatime) + "," if self.User_feel_FP != 'None': self.write_info += str( self.cmd.Force_Profile.index(self.User_feel_FP)) + "," if self.User_feel_FP == self.currentTrial[3]: self.write_info += str(1) + "," self.correct_times += 1 else: self.write_info += str(0) + "," else: self.write_info += str(8) + ',' print "Actual FP: " + self.currentTrial[ 3] + " User FP: " + self.User_feel_FP print "***" + str(self.correct_times) + "/" + str( self.global_times_counter) self.write_info += str(self.ask_last_num) + "," if self.currentTrial[1] == '1': self.write_info += str( self.play_electronic_element.last_i_th( self.ask_last_num)) + "," self.write_info += str(self.user_choice) + "," if int(self.user_choice) == int( self.play_electronic_element.last_i_th( self.ask_last_num)): self.write_info += str(1) + "\n" self.correct_RL_times += 1 else: self.write_info += str(0) + "\n" self.RL_total += 1 else: self.write_info += str(-1) + "," self.write_info += str(self.user_choice) + "," self.write_info += str(-1) + "\n" self.outputfile.write(self.write_info) self.outputfile.flush() self.write_info = "" # When the trial times reach the end if self.global_times_counter == len(self.cmd.Commands): tkMessageBox.showinfo('Notice', message='Haptic Test End, Thank you!!') return # Begin the next trial self.currentTrial = self.cmd.read_command_by_line() print self.currentTrial # Current/Total times self.write_info += str( self.user_num) + "," + self.user_name + "," + str( self.user_age) + "," + self.user_gender + "," if self.startTrialNum == 0: current_time = self.global_times_counter + 1 else: current_time = self.global_times_counter + self.startTrialNum self.show_info += str(current_time) + "\t\t" self.write_info += str(current_time) + "," for i in range(len(self.currentTrial)): if i == 0: self.pin_height = self.currentTrial[i] self.write_info += str( self.cmd.condition_lookup_table.index( self.pin_height)) + "," if i == 1: if self.currentTrial[i] == '1': self.show_info += "True\t\t" self.write_info += "1," else: self.show_info += "False\t\t" self.write_info += "0," if i == 2: if self.currentTrial[i] == '1': self.show_info += "Dominant\t " self.write_info += "1," else: self.show_info += "Non-Dominant\t " self.write_info += "0," if i == 3: # self.show_info += self.currentTrial[i] + "\t\t" self.Debug_Info.set("FP: " + self.currentTrial[i]) self.write_info += str( self.cmd.Force_Profile.index( self.currentTrial[i])) + "," if i == 4: self.show_info += self.cmd.Electronic_Element_Component_lookup[ self.currentTrial[i]] self.write_info += self.currentTrial[i] + "," self.PressSpaceTwice = False self.TrialInfo.set(self.show_info) self.Position_Info.set( str(self.correct_RL_times) + "/" + str(self.RL_total)) self.global_times_counter += 1 self.show_info = "" # Create thread for handling haptic Spring #self.spring = Spring(self.Position_Info.set) self.spring = Spring() Pin_height = int(self.currentTrial[4]) if 1 <= Pin_height and Pin_height <= 3: self.spring.set_profile(self.currentTrial[3], 'long') elif 4 <= Pin_height and Pin_height <= 6: self.spring.set_profile(self.currentTrial[3], 'middle') elif 7 <= Pin_height and Pin_height <= 9: self.spring.set_profile(self.currentTrial[3], 'short') self.spring.start() self.EnterPressTime += 1
def __init__(self): # Set the basic params of windows self.root = Tkinter.Tk() self.root.title("Haptic Experiment") w = 1920 #self.root.winfo_screenwidth() h = 1080 #self.root.winfo_screenheight() self.width = w self.height = h self.root.geometry("%dx%d" % (w, h)) self.root.minsize(300, 240) self.user_num = -1 self.user_name = "" self.user_gender = "" self.user_age = 0 self.haptic_feel_lookup = { 1: 'empty', 2: 'low', 3: 'high', 4: 'medium', 5: 'increasing', 6: 'decreasing', 7: 'click', 8: 'drop', 9: 'None', } self.cmd = Produce_Read_Order_List.Produce_Read_Order_List( ) # Initiate list of command self.User_feel_FP = "" # record the user's actual choice of haptic feeling self.global_times_counter = 0 # record the user's repeated times self.correct_times = 0 self.correct_RL_times = 0 self.RL_total = 0 self.start = 0 # Start timestamp for haptic sensing self.end = 0 # End timestamp for haptic sensing self.deltatime = 0 # The time duration for haptic sensing self.startTrialNum = 0 # Start number specified for program crash self.outputfile = None # Output file for trial recording self.currentTrial = None # Current trial information self.play_electronic_element = None # Define the instance of electronic element sound play self.SpacePressTime = 0 # Times of press [Space] self.EnterPressTime = 0 # Times of press [Enter] self.PressSpaceTwice = False # Space pressed for more than twice without [Enter] self.user_choice = -1 # User choice of last i'th electronic element self.ask_last_num = -1 # the last i'th elements hear of under the Recongnition load self.trackLength = 0 # track the length of the sound playlist self.write_info = "" # Information written to output file self.show_info = "" # Information showed on the panel self.pin_height = "" # Information of the pin height # Switch between show debug and not show self.show_debug = False self.TrialInfo = Tkinter.StringVar(value='') # Trial information self.Answer = Tkinter.StringVar(value='') # User answer self.Question_text = Tkinter.StringVar(value='') # Text of Question self.Question_choice_row_1 = Tkinter.StringVar( value='') # First row of choice of question self.Question_choice_row_2 = Tkinter.StringVar( value='') # Second row of choice of question self.Question_choice_row_3 = Tkinter.StringVar( value='') # Third row of choice of question self.Position_Info = Tkinter.StringVar( value='') # Position Information about the Spring self.Debug_Info = Tkinter.StringVar( value='') # Debug Information about the Spring # Bind the Space Key press to continue self.root.bind( "<KeyPress>", self.SpaceContinue) # Bind the [Space] press and its function self.root.focus_set() self.root.bind('<Return>', self.EnterPress) # Bind the [Enter] Key press self.spring = Spring() self.varNum = Tkinter.StringVar(value='') self.varName = Tkinter.StringVar(value='') self.varGender = Tkinter.StringVar(value='') self.varAge = Tkinter.StringVar(value='') # Top level Panel for user information enter, show at program boot, hide when information entered and confirmed top_entry_y = h / 80 top_col_1 = w / 15 top_col_2 = top_col_1 + w / 12 + w / 18 top_col_3 = top_col_2 + w / 12 + w / 18 top_col_4 = top_col_3 + w / 12 + w / 18 top_col_5 = top_col_4 + w / 12 + w / 15 top_col_6 = top_col_5 + w / 12 + w / 12 self.labelNum = Tkinter.Label(self.root, text='User Num:') self.labelNum.place(x=top_col_1, y=top_entry_y, width=w / 12, height=h / 20) self.labelNum.config(font=("Courier", 15, "bold")) self.entryNum = Tkinter.Entry(self.root, textvariable=self.varNum) self.entryNum.place(x=top_col_1 + w / 12, y=top_entry_y, width=w / 18, height=h / 20) self.LabelName = Tkinter.Label(self.root, text='Name:') self.LabelName.place(x=top_col_2, y=top_entry_y, width=w / 12, height=h / 20) self.LabelName.config(font=("Courier", 15, "bold")) self.entryName = Tkinter.Entry(self.root, textvariable=self.varName) self.entryName.place(x=top_col_2 + w / 12, y=top_entry_y, width=w / 20, height=h / 20) self.LabelGender = Tkinter.Label(self.root, text='Gender:') self.LabelGender.place(x=top_col_3, y=top_entry_y, width=w / 12, height=h / 20) self.LabelGender.config(font=("Courier", 15, "bold")) self.entryGender = Tkinter.Entry(self.root, width=80, textvariable=self.varGender) self.entryGender.place(x=top_col_3 + w / 12, y=top_entry_y, width=w / 20, height=h / 20) self.LabelAge = Tkinter.Label(self.root, text='Age:') self.LabelAge.place(x=top_col_4, y=top_entry_y, width=w / 12, height=h / 20) self.LabelAge.config(font=("Courier", 15, "bold")) self.entryAge = Tkinter.Entry(self.root, width=80, textvariable=self.varAge) self.entryAge.place(x=top_col_4 + w / 12, y=top_entry_y, width=w / 20, height=h / 20) self.LabelStartFromTrial = Tkinter.Label(self.root, text='Start Num:') self.LabelStartFromTrial.place(x=top_col_5, y=top_entry_y, width=w / 12, height=h / 20) self.LabelStartFromTrial.config(font=("Courier", 15, "bold")) self.entryStartFromTrial = Tkinter.Entry( self.root, width=80, textvariable=self.startTrialNum) self.entryStartFromTrial.place(x=top_col_5 + w / 12, y=top_entry_y, width=w / 20, height=h / 20) self.buttonOk = Tkinter.Button(self.root, text='Confirm', command=self.login) self.buttonOk.place(x=top_col_6, y=top_entry_y, width=w / 20, height=h / 20) self.buttonOk.config(font=("Courier", 12, "bold")) self.buttonCancel = Tkinter.Button(self.root, text='Cancel', command=self.cancel) self.buttonCancel.place(x=top_col_6 + w / 18, y=top_entry_y, width=w / 20, height=h / 20) self.buttonCancel.config(font=("Courier", 12, "bold")) self.buttonRetry = Tkinter.Button(self.root, text='Retry', command=self.retry) self.buttonRetry.place(x=top_col_6 + 2 * w / 18, y=top_entry_y, width=w / 20, height=h / 20) self.buttonRetry.config(font=("Courier", 12, "bold")) self.Info_Header = Label( self.root, text="Trial\tRecongition Load\tHandness\tComponent", anchor=W) self.Info_Header.config(font=("Courier", 12, "bold")) self.Info = Label(self.root, textvariable=self.TrialInfo, anchor=W) self.Info.config(font=("Courier", 12, "bold")) # Set up and place the images at the second level img_1 = Image.open('img/F01.jpg') img_1 = img_1.resize((w / 6, h / 6), Image.ANTIALIAS) img_1 = ImageTk.PhotoImage(img_1) img_2 = Image.open('img/F02.jpg') img_2 = img_2.resize((w / 6, h / 6), Image.ANTIALIAS) img_2 = ImageTk.PhotoImage(img_2) img_3 = Image.open('img/F03.jpg') img_3 = img_3.resize((w / 6, h / 6), Image.ANTIALIAS) img_3 = ImageTk.PhotoImage(img_3) img_4 = Image.open('img/F04.jpg') img_4 = img_4.resize((w / 6, h / 6), Image.ANTIALIAS) img_4 = ImageTk.PhotoImage(img_4) img_5 = Image.open('img/F05.jpg') img_5 = img_5.resize((w / 6, h / 6), Image.ANTIALIAS) img_5 = ImageTk.PhotoImage(img_5) img_6 = Image.open('img/F06.jpg') img_6 = img_6.resize((w / 6, h / 6), Image.ANTIALIAS) img_6 = ImageTk.PhotoImage(img_6) img_7 = Image.open('img/F07.jpg') img_7 = img_7.resize((w / 6, h / 6), Image.ANTIALIAS) img_7 = ImageTk.PhotoImage(img_7) img_8 = Image.open('img/F08.jpg') img_8 = img_8.resize((w / 6, h / 6), Image.ANTIALIAS) img_8 = ImageTk.PhotoImage(img_8) col_x_1 = w / 15 col_x_2 = 2 * w / 15 + w / 6 col_x_3 = 3 * w / 15 + 2 * w / 6 col_x_4 = 4 * w / 15 + 3 * w / 6 label_level_1_y = top_entry_y + 2 * h / 20 label_level_2_y = top_entry_y + 4 * h / 20 + h / 6 img_level_1_y = top_entry_y + 3 * h / 20 img_level_2_y = top_entry_y + 5 * h / 20 + h / 6 self.FP1 = Label(self.root, text="1. empty", fg='blue') self.FP1.place(x=col_x_1, y=label_level_1_y) self.FP1.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_1).place(x=col_x_1, y=img_level_1_y) self.FP2 = Label(self.root, text="2. low", fg='blue') self.FP2.place(x=col_x_2, y=label_level_1_y) self.FP2.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_2).place(x=col_x_2, y=img_level_1_y) self.FP3 = Label(self.root, text="3. high", fg='blue') self.FP3.place(x=col_x_3, y=label_level_1_y) self.FP3.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_3).place(x=col_x_3, y=img_level_1_y) self.FP4 = Label(self.root, text="4. medium", fg='blue') self.FP4.place(x=col_x_4, y=label_level_1_y) self.FP4.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_4).place(x=col_x_4, y=img_level_1_y) self.FP5 = Label(self.root, text="5. increasing", fg='blue') self.FP5.place(x=col_x_1, y=label_level_2_y) self.FP5.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_5).place(x=col_x_1, y=img_level_2_y) self.FP6 = Label(self.root, text="6. decreasing", fg='blue') self.FP6.place(x=col_x_2, y=label_level_2_y) self.FP6.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_6).place(x=col_x_2, y=img_level_2_y) self.FP7 = Label(self.root, text="7. click", fg='blue') self.FP7.place(x=col_x_3, y=label_level_2_y) self.FP7.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_7).place(x=col_x_3, y=img_level_2_y) self.FP8 = Label(self.root, text="8. drop", fg='blue') self.FP8.place(x=col_x_4, y=label_level_2_y) self.FP8.config(font=("Courier", 15, "bold")) Label(self.root, text="abc", image=img_8).place(x=col_x_4, y=img_level_2_y) # User haptic feel part and Quize part self.Question = Label(self.root, textvariable=self.Question_text) # Show the current position information on right side self.CurrPosition = Label(self.root, text="Position Info", textvariable=self.Position_Info) self.CurrPosition.place(x=12 * self.width / 16, y=7 * self.height / 8) self.CurrPosition.config(font=("Courier", 15, "bold"), fg="red") # Show the Force Profile on left side self.CurrDebug = Label(self.root, text="Debug Info", textvariable=self.Debug_Info) if self.show_debug: self.CurrDebug.place(x=2 * self.width / 16, y=3 * self.height / 4) self.CurrDebug.config(font=("Courier", 20, "bold"), fg="red") self.Choice_row_1 = Label(self.root, textvariable=self.Question_choice_row_1) self.Choice_row_2 = Label(self.root, textvariable=self.Question_choice_row_2) self.Choice_row_3 = Label(self.root, textvariable=self.Question_choice_row_3) self.User_Answer = Tkinter.Label(self.root, text='Answer: ', fg="blue") self.User_Answer.place(x=w / 2 - w / 8, y=7 * h / 8) self.User_Answer.config(font=("Courier", 20, "bold")) self.entry_Answer = Tkinter.Entry(self.root, width=80, textvariable=self.Answer) self.entry_Answer.place(x=w / 2 - w / 25, y=7 * h / 8, width=w / 12, height=h / 25) self.root.mainloop()
def __init__( self, roomnumber, floorNumber ): #FIXME: les couleurs dans design niveaux ne sont pas homogenes. self.floorNumber = floorNumber if floorNumber == 1: #python doesn't have switch statements smh floordesignPath = 'design niveaux/lvl1.png' elif floorNumber == 2: floordesignPath = 'design niveaux/lvl2.png' elif floorNumber == 3: floordesignPath = 'design niveaux/lvl3.png' elif floorNumber == 4: floordesignPath = 'design niveaux/lvl4.png' elif floorNumber == 5: floordesignPath = 'design niveaux/lvl5.png' elif floorNumber == 6: floordesignPath = 'design niveaux/salle du boss.png' floordesign = pygame.image.load(floordesignPath) self.roomnumber = roomnumber self.roomBlocks = [] for y in range(9): for x in range(16): color = floordesign.get_at((x + (roomnumber * 16), y)) # print("x = " + str(x+ (roomnumber*16)) + "; y = " + str(y) + "; color = " + str(color)) if color == (0, 0, 0, 255): # wall self.roomBlocks.append(Wall((x, y))) elif color == (88, 88, 88, 255): # spike if floordesign.get_at( (x + (roomnumber * 16), y + 1)) == (0, 0, 0, 255): self.roomBlocks.append(Spike((x, y))) elif floordesign.get_at( (x + (roomnumber * 16) + 1, y)) == (0, 0, 0, 255): self.roomBlocks.append(Spike((x, y), 1)) elif floordesign.get_at( (x + (roomnumber * 16) - 1, y)) == (0, 0, 0, 255): self.roomBlocks.append(Spike((x, y), 3)) elif floordesign.get_at( (x + (roomnumber * 16), y - 1)) == (0, 0, 0, 255): self.roomBlocks.append(Spike((x, y), 2)) else: self.roomBlocks.append(Spike((x, y))) elif color == (18, 189, 99, 255): self.roomBlocks.append(Coin((x, y))) elif color == (189, 18, 18, 255): #enemy if floordesign.get_at( (x + (roomnumber * 16), y + 1)) == (0, 0, 0, 255): if floorNumber == 1: self.roomBlocks.append(Slime((x, y))) elif floorNumber == 2: self.roomBlocks.append(Slime2((x, y))) elif floorNumber == 3: self.roomBlocks.append(Slime3((x, y))) elif floorNumber == 4: self.roomBlocks.append(Slime4((x, y))) elif floorNumber == 5: self.roomBlocks.append(Slime5((x, y))) else: # bat if floorNumber == 1: self.roomBlocks.append(Bat((x, y))) elif floorNumber == 2: self.roomBlocks.append(Bat2((x, y))) elif floorNumber == 3: self.roomBlocks.append(Bat3((x, y))) elif floorNumber == 4: self.roomBlocks.append(Bat4((x, y))) elif floorNumber == 5: self.roomBlocks.append(Bat5((x, y))) elif color == (23, 18, 189, 255): #spring self.roomBlocks.append(Spring((x, y))) elif color == (215, 223, 1, 255): self.roomBlocks.append(SpawnPoint((x, y))) elif color == (230, 89, 1, 255): self.roomBlocks.append(Button((x, y))) elif color == (168, 7, 125, 255): self.roomBlocks.append(PNJ((x, y))) elif color == (9, 199, 254): self.roomBlocks.append(Table((x, y))) elif color == (124, 48, 201): self.roomBlocks.append(Boss((x, y)))