def run_game(): app_settings = Settings() pygame.init() screen = pygame.display.set_mode( (app_settings.screen_width, app_settings.screen_height)) pygame.display.set_caption("Visualization") # pygame.event.set_blocked(None) data = f.init_data(app_settings.num_of_objects, app_settings.screen_width, app_settings.screen_height) for i in range(len(data)): for j in range(len(data)): # Чтобы игра не зависла for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if data[i] < data[j]: t = data[i] data[i] = data[j] data[j] = t screen.fill(app_settings.bg_color) f.draw(screen, data, app_settings.screen_width, app_settings.screen_height) pygame.display.flip() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit()
def updateScreen(background_color, screen, arrow, board): """更新屏幕上的新图像""" # 每个循环重新绘制弹出屏幕 screen.fill(background_color) arrow.build() func.draw(board, screen) # 弹出新绘制的屏幕 pygame.display.flip()
def run_game(): pygame.init() settings = Settings() # 创建存储棋子的编组 pieces = Group() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height), 4, 0) chequer = Chequer(settings, screen, pieces) pygame.display.set_caption("五子棋") background = pygame.image.load("background3.jpg").convert() #按钮 button_d = Button(screen, "悔棋", 30, (65, 49), (20, 20, 90, 55)) button_d2 = Button(screen, "悔棋", 35, (65, 49), (18, 18, 95, 63)) button_r = Button(screen, "重新開始", 30, (200, 49), (130, 20, 140, 58)) button_r2 = Button(screen, "重新開始", 33, (200, 49), (128, 18, 145, 62)) button_s = Button(screen, "設置", 30, (525, 49), (480, 20, 90, 55)) button_s2 = Button(screen, "設置", 35, (525, 49), (478, 18, 95, 63)) #弹框 msg_box_reset = Msg_box(screen, "確定重新開始?", "確定", "取消") box_black_win = Msg_box(screen, "黑棋獲勝!", "重置", "退出游戲") box_white_win = Msg_box(screen, "白棋獲勝!", "重置", "退出游戲") box_get_draw = Msg_box(screen, '棋盤下滿了,平局!', "重置", "退出游戲") box_get_draw2 = Msg_box(screen, '時間到,此局平局!', "重置", "退出游戲") box_open_jinshou = Msg_box(screen, "開啓黑棋禁手?", "開啓", "禁手規則") box_close_jinshou = Msg_box(screen, "關閉黑棋禁手?", "關閉", "禁手規則") box_jinshou = Msg_box(screen, "黑棋禁手,不能落子", "確定", "禁手規則") #倒计时 count_down = Count_down(screen) while True: f.check_events(settings, chequer, pieces, button_d2, button_r2, button_s2, msg_box_reset, count_down) #screen.fill((settings.bg_color)) screen.blit(background, (0, 0)) chequer.lines() chequer.cirs() chequer.get_mouse_pos(pieces) for pos in settings.poslist_b: chequer.set_piece(pos, chequer.black) for pos in settings.poslist_w: chequer.set_piece(pos, chequer.white) ##绘制各种按钮————悔棋,重新开始,设置 f.draw_button(button_d, button_d2) f.draw_button(button_r, button_r2) f.draw_button(button_s, button_s2) f.draw(settings, msg_box_reset, box_black_win, box_white_win, box_get_draw, box_get_draw2, box_open_jinshou, box_close_jinshou, box_jinshou) #f.tine_down(settings) f.prep_time(settings, count_down) count_down.draw() pygame.display.flip()
def run_game(): app_settings = Settings() pygame.init() screen = pygame.display.set_mode( (app_settings.screen_width, app_settings.screen_height)) pygame.display.set_caption("Visualization") data = f.init_data(app_settings.num_of_objects, app_settings.screen_width, app_settings.screen_height) f.bubbleSort(data) while True: screen.fill(app_settings.bg_color) f.draw(screen, data, app_settings.screen_width, app_settings.screen_height) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() pygame.display.flip()
proxy = ["_"] * len(word) # clear the console f.clear() # play the intro text f.intro() # prompt the player to start the game raw_input("\n\nPress ENTER when you are ready!") # clear the console f.clear() # first drawing of the gallows!! f.draw(guesses) #print a playful message to the player f.message(guesses, random.choice(m[guesses])) # print out the hidden word proxy # the proxy starts out as a string of underscores # which are replaced with letters when the player # guesses correctly f.printProxy(proxy) # START THE GAME LOOP # The game loop continues to run until the # player has won or until our friend is hanged while True: # deconstructing the tuple into
# play the intro text f.intro() # prompt the player to start the game raw_input("\n\nPress ENTER when you are ready!") # clear the console f.clear() # first drawing of the gallows!! f.draw(guesses) #print a playful message to the player f.message(guesses, random.choice(m[guesses])) # print out the hidden word proxy # the proxy starts out as a string of underscores # which are replaced with letters when the player # guesses correctly f.printProxy(proxy) # START THE GAME LOOP # The game loop continues to run until the
playerXpos = 5 PLAYER_Y_POS = 200 compXpos = 5 COMP_Y_POS = 25 PLAYER_TOTAL_Y = 185 COMP_TOTAL_Y = 13 # reset window graphics.window(WINDOWWIDTH, WINDOWHEIGHT) # indicate where each players hand is graphics.displayText("Player:", 5, PLAYER_Y_POS - 15) graphics.displayText("Computer:", 5, COMP_Y_POS - 15) # picks two cards for each hand for card in range(2): functions.deal_Card(playerHand) playerXpos = functions.draw(playerXpos, PLAYER_Y_POS, playerHand) functions.deal_Card(compHand) compXpos = functions.draw(compXpos, COMP_Y_POS, compHand) #gets and displays the total of player hand and comphand compTotal = str(functions.get_total(compHand)) playerTotal = str(functions.get_total(playerHand)) player2Total = str(functions.get_total(player2hand)) graphics.displayText(playerTotal, playerXpos, PLAYER_TOTAL_Y) graphics.displayText(compTotal, compXpos, COMP_TOTAL_Y) pygame.display.update() #Players turn is first turn = "player"
import functions import classes pic_file = "../data/monalisa.jpg" s_o_m = functions.initialize_som() image = classes.Dataset(pic_file) functions.train(image,s_o_m) functions.save_som(s_o_m,pic_file) functions.draw(s_o_m) functions.reproduce(image,s_o_m,image.size[0],image.size[1]) # import after database updated with new SOM import db_check db_check.similar_som()
# and print each one. elif commands[0].lower() == "help" or commands[0].lower() == "?": fn.help_command() # if the command is 'exit' print a goodbye message and set # is_running to False, ending the while loop and ending the prog. elif commands[0].lower() == "exit" or commands[0].lower() == "x!": txt.print_blue("Bye!") is_running = False # if the command is 'draw' try to figure out which shape was # provided and if it's an invalid shape, print error msg, # if no shape is provided, also print an error message, # otherwise draw the shape. elif commands[0].lower() == "draw" or commands[0].lower() == "dr": try: if len(commands) >= 2: fn.draw(commands) else: raise err.FieldNotProvidedError except err.FieldNotProvidedError: txt.print_red( "FieldNotProvidedError: Cannot execute: not enough arguments!" ) except err.InvalidShapeError: txt.print_red("InvalidShapeError: Invalid shape!") # if the command is 'to-base-10', try to figure out which int # was provided using startswith and converting it based upon this. # If the base does not match, provide an error message. If the # user doesn't provide some fields, write an error, and if the # user writes the wrong integer, write an error as well. elif commands[0].lower() == "to-base-10" or commands[0].lower( ) == "tbt":
# # print(lap) # Avg_mtx = np.diag(np.ones(num_grid - 1)/2, 1) + np.diag(np.ones(num_grid - 1)/2, -1) # Avg_mtx[[0, num_grid - 1], [0, num_grid - 1]] = 1 # Avg_mtx[[0, num_grid - 1], [1, num_grid - 2]] = 0 # print(Avg_mtx) # err = 1e2 v_old = v # while err > tol: for i in tqdm(range(num_iter)): v_new = v_old for i in range(1, num_grid - 1): for j in range(1, num_grid - 1): # if i in range(45, 55) and j in range(49, 52): # continue v_new[i, j] = np.sum(v_old[[i - 1, i + 1, i, i], [j, j, j - 1, j + 1]]) / 4 # for pos, val in fixed_points: # v_new[pos] = val # err = np.sum((v_new - v_old)**2) v_old = v_new print(v_old) # print("Error:", err) draw(X, Y, v_old, type='3d') E = np.gradient(-v_old) print(E) draw(X, Y, E, type='quiver')
if tried != -1: tried, last = functions.test(im, p_bot, game, last, mode, change, tried, random) random = False if tried >= 15: change = False if mode == "tree": print("> I'M SORRY, BACK TO CHOPPING") else: print("> I'M SORRY, BACK TO MINING") tried = 0 functions.draw(im) functions.grid(im) cv2.imshow("frame1", im) delta = time.time() - start if delta < SLEEP_TIME: time.sleep(SLEEP_TIME - delta) key = cv2.waitKey(1) & 0xFF if key == ESC_KEY: break else: time.sleep(1)
def updateScreen(background, screen, board): """更新屏幕上的新图像""" # 每个循环重新绘制弹出屏幕 screen.fill(background) func.draw(board, screen) pygame.display.flip()
for i in range(all_length): x_forecast.append(i) min_trend = numpy.polyfit(x, min_years, 2) max_trend = numpy.polyfit(x, max_years, 2) min_trendline = [] max_trendline = [] x0_min_years = min_years[0] x0_max_years = max_years[0] for i in range(yearly_range): min_years[i] = min_years[i] / x0_min_years max_years[i] = max_years[i] / x0_max_years x0_min_trend = x_forecast[0] * x_forecast[0] * min_trend[0] + x_forecast[ 0] * min_trend[1] + min_trend[2] x0_max_trend = x_forecast[0] * x_forecast[0] * max_trend[0] + x_forecast[ 0] * max_trend[1] + max_trend[2] for i in range(all_length): min_trendline.append( (x_forecast[i] * x_forecast[i] * min_trend[0] + x_forecast[i] * min_trend[1] + min_trend[2]) / x0_min_trend) max_trendline.append( (x_forecast[i] * x_forecast[i] * max_trend[0] + x_forecast[i] * max_trend[1] + max_trend[2]) / x0_max_trend) print min_trendline draw(ice_extent, min_years, max_years, min_trendline, max_trendline, dates_month, dates_year, dates_forecast)
import numpy as np import functions as fn img1 =cv2.imread('normal.jpg',0) #test #roi img1_process=img1[0:np.shape(img1)[0],11:109] img1_show = cv2.cvtColor(img1_process, cv2.COLOR_GRAY2BGR) thresh=fn.Inhence_and_threshod(img1_process,111) image1, contours1, hierarchy = cv2.findContours( #找最外層的輪廓 fn.inner_fill(thresh), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) mor1_color = cv2.cvtColor(fn.inner_fill(thresh), cv2.COLOR_GRAY2BGR) img1_color = cv2.cvtColor(img1, cv2.COLOR_GRAY2BGR) fn.draw(contours1,img1_color) fn.find_roi_coordinate(contours1,img1_color) tmp1 = np.hstack((img1_show,mor1_color,img1_color)) cv2.imshow("normal",tmp1) k = cv2.waitKey(0) if k==ord('q'): cv2.destroyAllWindows()