How to use window_width method in Selene

Best Python code snippet using selene_python

layouts.py

Source:layouts.py Github

copy

Full Screen

1import json2import os3import random4import pygame5from pygame.locals import *6from time import sleep7from . import interface8"""9Здесь рисую маленькие всплывающие окна10Сначала отрисовывается рамка, потом окно, потом кнопки11И прочее содержимое12"""13# colors14COLOR_WHITE = (255, 255, 255)15COLOR_BLACK = (0, 0, 0)16COLOR_BRIGHT_GREY = (200, 200, 200)17COLOR_RED = (255, 0, 0)18COLOR_BLUE = (0, 0, 255)19# return true if quit20def interruption_menu(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT):21 pygame.mouse.set_visible(True)22 button_continue = interface.Button(WINDOW_WIDTH / 2 + 100, WINDOW_HEIGHT / 4,23 WINDOW_WIDTH / 3, WINDOW_HEIGHT / 8, "Continue")24 button_quit = interface.Button(WINDOW_WIDTH / 2 + 100, WINDOW_HEIGHT / 2,25 WINDOW_WIDTH / 3, WINDOW_HEIGHT / 8, "Quit")26 while True:27 for event in pygame.event.get():28 mouse_pos = pygame.mouse.get_pos()29 if event.type == KEYUP:30 if event.key == K_ESCAPE:31 pygame.mouse.set_visible(False)32 return False33 if button_continue.is_over(mouse_pos):34 if event.type == pygame.MOUSEBUTTONDOWN:35 pygame.mouse.set_visible(False)36 return False37 if button_quit.is_over(mouse_pos):38 if event.type == pygame.MOUSEBUTTONDOWN:39 return True40 pygame.draw.rect(window_surface, COLOR_BLACK,41 (WINDOW_WIDTH / 2 + 100 - 5, WINDOW_HEIGHT / 5 - 5,42 WINDOW_WIDTH / 3 + 10, WINDOW_HEIGHT / 2 + 10))43 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY,44 (WINDOW_WIDTH/2 + 100, WINDOW_HEIGHT/5, WINDOW_WIDTH / 3, WINDOW_HEIGHT / 2))45 button_continue.draw(window_surface)46 button_quit.draw(window_surface)47 pygame.display.update()48def stats_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT):49 font = pygame.font.SysFont(None, 46)50 drawable = list()51 handler = open("../stats/high_score.json", 'r')52 data = json.load(handler)53 handler.close()54 for i in range(len(data)):55 text_view = interface.TextView(font, COLOR_BLACK, WINDOW_WIDTH / 2 - 200, WINDOW_HEIGHT / 5 + i*48,56 data[str(i+1)][0] + " " + str(data[str(i+1)][1]))57 drawable.append(text_view)58 button_close = interface.Button(WINDOW_WIDTH / 2 - 260 + WINDOW_WIDTH / 3 - WINDOW_WIDTH / 20, WINDOW_HEIGHT / 5 - 50,59 WINDOW_WIDTH / 20, WINDOW_HEIGHT / 20, "x")60 while True:61 for event in pygame.event.get():62 mouse_pos = pygame.mouse.get_pos()63 if event.type == KEYUP:64 if event.key == K_ESCAPE:65 return66 if button_close.is_over(mouse_pos):67 if event.type == pygame.MOUSEBUTTONDOWN:68 return69 pygame.draw.rect(window_surface, COLOR_BLACK,70 (WINDOW_WIDTH / 2 - 268, WINDOW_HEIGHT / 5 - 58, WINDOW_WIDTH / 3+16, 3 * WINDOW_HEIGHT / 4+16))71 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY,72 (WINDOW_WIDTH / 2 - 260, WINDOW_HEIGHT / 5 - 50, WINDOW_WIDTH / 3, 3*WINDOW_HEIGHT / 4))73 for elem in drawable:74 elem.draw(window_surface)75 button_close.draw(window_surface)76 pygame.display.update()77def victory_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT, boss, score, new_record, new_skin):78 rect = pygame.Rect((0, 0), (2*WINDOW_WIDTH/3, 2*WINDOW_HEIGHT/3))79 rect_border = pygame.Rect((0, 0), (2*WINDOW_WIDTH/3+10, 2*WINDOW_HEIGHT/3+10))80 rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)81 rect_border.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)82 font0 = pygame.font.SysFont(None, 140)83 font1 = pygame.font.SysFont(None, 80)84 font2 = pygame.font.SysFont(None, 60)85 text_victory = interface.TextView(font0, COLOR_BLACK, 150, 2*WINDOW_HEIGHT / 6, "Level complete!")86 text_victory.rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/4)87 if boss:88 text_formula = interface.TextView(font1, COLOR_BLACK, 150, 2*WINDOW_HEIGHT / 6, "Score = (score+life*1000)*100/time")89 else:90 text_formula = interface.TextView(font1, COLOR_BLACK, 150, 2*WINDOW_HEIGHT / 6, "Score = score + life*1000")91 text_formula.rect.topleft = (WINDOW_WIDTH/4 - 70, WINDOW_HEIGHT/3 + 60)92 text_press_esc = interface.TextView(font2, COLOR_WHITE, 150, 2 * WINDOW_HEIGHT / 6, "Press ESC to continue")93 text_press_esc.rect.center = (4*WINDOW_WIDTH / 5, 8*WINDOW_HEIGHT / 9)94 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)95 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)96 text_victory.draw(window_surface)97 text_formula.draw(window_surface)98 text_formula.next_line(90)99 text_formula.draw_this(window_surface, "Your score is " + str(score))100 if new_record:101 sleep(0.5)102 new_top_sound = pygame.mixer.Sound('../sound/short_tracks/health.wav')103 new_top_sound.play()104 text_formula.color = COLOR_RED105 text_formula.next_line(100)106 text_formula.draw_this(window_surface, "New level record!")107 if new_skin:108 sleep(0.5)109 text_formula.color = COLOR_BLUE110 text_formula.next_line(100)111 text_formula.draw_this(window_surface, "New skin available!")112 text_press_esc.draw(window_surface)113 pygame.display.update()114 while True:115 for event in pygame.event.get():116 if event.type == KEYUP:117 if event.key == K_ESCAPE:118 return119def defeat_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT):120 font0 = pygame.font.SysFont(None, 200)121 font1 = pygame.font.SysFont(None, 80)122 text_view_message = interface.TextView(font0, COLOR_WHITE, 150, 2*WINDOW_HEIGHT / 6,123 "Game over, bro =(")124 text_view_message.draw(window_surface)125 text_view_press_esc = interface.TextView(font1, COLOR_WHITE, WINDOW_WIDTH / 2 - 200, 3*WINDOW_HEIGHT / 5,126 "Press ESC to exit...")127 text_view_press_esc.draw(window_surface)128 pygame.display.update()129 while True:130 for event in pygame.event.get():131 if event.type == KEYUP:132 if event.key == K_ESCAPE:133 return134# returning player135def create_profile_layout(window_surface, player, WINDOW_WIDTH, WINDOW_HEIGHT):136 player.save_current_state()137 clock = pygame.time.Clock()138 rect = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3, WINDOW_HEIGHT / 3))139 rect_border = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3 + 10, WINDOW_HEIGHT / 3 + 10))140 rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)141 rect_border.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)142 input_box = interface.InputBox(WINDOW_WIDTH/4, 4*WINDOW_HEIGHT/8, 220, 80)143 font0 = pygame.font.SysFont(None, 100)144 font1 = pygame.font.SysFont(None, 78)145 input_box.font = font1146 text_write_name = interface.TextView(font0, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6, "Write your name here")147 text_write_name.rect.center = (WINDOW_WIDTH / 2, 2*WINDOW_HEIGHT / 5)148 button_done = interface.Button(2*WINDOW_WIDTH / 3, 4*WINDOW_HEIGHT / 8,149 WINDOW_WIDTH / 15, WINDOW_HEIGHT / 10, "Done")150 done = False151 while not done:152 for event in pygame.event.get():153 mouse_pos = pygame.mouse.get_pos()154 if event.type == pygame.QUIT:155 done = True156 if button_done.is_over(mouse_pos):157 if event.type == pygame.MOUSEBUTTONDOWN:158 print(input_box.text)159 name = input_box.text.strip()160 if not name:161 done = True162 continue163 path = '../stats/players/' + name + '.json'164 if os.path.isfile(path):165 print("Exist")166 player = interface.load_player_by_path(path)167 else:168 print("Not exist")169 interface.create_empty_profile(name)170 player = interface.load_player_by_path(path)171 input_box.text = ''172 done = True173 if event.type == KEYUP:174 if event.key == K_ESCAPE:175 done = True176 elif event.key == pygame.K_RETURN: # if enter177 print(input_box.text)178 name = input_box.text.strip()179 if not name:180 done = True181 continue182 path = '../stats/players/' + name + '.json'183 if os.path.isfile(path):184 print("Exist")185 player = interface.load_player_by_path(path)186 else:187 print("Not exist")188 interface.create_empty_profile(name)189 player = interface.load_player_by_path(path)190 input_box.text = ''191 done = True192 input_box.handle_event(event)193 input_box.update()194 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)195 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)196 text_write_name.draw(window_surface)197 input_box.draw(window_surface)198 button_done.draw(window_surface)199 pygame.display.update()200 clock.tick(30)201 return player202# returning player203def change_skin_layout(window_surface, player, WINDOW_WIDTH, WINDOW_HEIGHT):204 rect = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3, 2 * WINDOW_HEIGHT / 3))205 rect_border = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3 + 10, 2 * WINDOW_HEIGHT / 3 + 10))206 rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)207 rect_border.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)208 font0 = pygame.font.SysFont(None, 120)209 text_title = interface.TextView(font0, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6, "Select skin")210 text_title.rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 4)211 skin_levels = [1, 6, 8, 9, 10, 12]212 buttons = list()213 for i, skin in enumerate(skin_levels):214 if skin in player.skins:215 button = interface.Button(WINDOW_WIDTH / 5 + (i % 3) * (WINDOW_WIDTH / 6 + 40) + 50,216 WINDOW_HEIGHT / 3 + int(i / 3) * (WINDOW_HEIGHT / 8 + 70),217 WINDOW_WIDTH / 8, WINDOW_HEIGHT / 6, str(skin))218 button.font = pygame.font.SysFont(None, 64)219 else:220 button = interface.Button(WINDOW_WIDTH / 5 + (i % 3) * (WINDOW_WIDTH / 6 + 40) + 50,221 WINDOW_HEIGHT / 3 + int(i / 3) * (WINDOW_HEIGHT / 8 + 70),222 WINDOW_WIDTH / 8, WINDOW_HEIGHT / 6, str(skin), True)223 button.font = pygame.font.SysFont(None, 64)224 buttons.append(button)225 while True:226 mouse_pos = pygame.mouse.get_pos() # gets mouse position227 for event in pygame.event.get():228 if event.type == KEYUP:229 if event.key == K_ESCAPE:230 return player231 for button in buttons:232 if button.is_over(mouse_pos):233 if event.type == pygame.MOUSEBUTTONDOWN and not button.is_off:234 player.current_skin = int(button.text)235 print("Current skin is", player.current_skin)236 return player237 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)238 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)239 text_title.draw(window_surface)240 for button in buttons:241 button.draw(window_surface)242 pygame.display.update()243def future_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT):244 rect = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3, 2 * WINDOW_HEIGHT / 3))245 rect_border = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3 + 10, 2 * WINDOW_HEIGHT / 3 + 10))246 rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)247 rect_border.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)248 font0 = pygame.font.SysFont(None, 120)249 font1 = pygame.font.SysFont(None, 70)250 text_title = interface.TextView(font0, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6, "Developers")251 text_title.rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 4)252 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)253 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)254 text_title.draw(window_surface)255 text_future = interface.TextView(font1, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6)256 text_future.rect.center = (WINDOW_WIDTH / 5, WINDOW_HEIGHT / 3)257 text_future.next_line(82)258 text_future.draw_this(window_surface, "Vladislav Cepelev (teamlead)")259 text_future.next_line(82)260 text_future.draw_this(window_surface, "Alexander Zorkin (programmer)")261 text_future.next_line(82)262 text_future.draw_this(window_surface, "Rufina Rafikova (programmer/storywriter)")263 text_future.next_line(82)264 text_future.draw_this(window_surface, "Anastasia Politova (game designer)")265 pygame.display.update()266 while True:267 for event in pygame.event.get():268 if event.type == KEYUP:269 return270 if event.type == MOUSEBUTTONDOWN:271 return272def two_players_victory_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT, score, time):273 rect = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3, 2 * WINDOW_HEIGHT / 3))274 rect_border = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3 + 10, 2 * WINDOW_HEIGHT / 3 + 10))275 rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)276 rect_border.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)277 font0 = pygame.font.SysFont(None, 140)278 font1 = pygame.font.SysFont(None, 80)279 font2 = pygame.font.SysFont(None, 60)280 text_victory = interface.TextView(font0, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6, "Nice game!")281 text_victory.rect.center = (WINDOW_WIDTH / 2, 2*WINDOW_HEIGHT / 8)282 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)283 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)284 handler = open("../stats/multiplayer_score.json", 'r')285 data = json.load(handler)286 handler.close()287 text_victory.draw(window_surface)288 score_and_time_text = interface.TextView(font1, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6)289 score_and_time_text.rect.center = (WINDOW_WIDTH / 5, WINDOW_HEIGHT / 3 + 30)290 score_and_time_text.draw_this(window_surface, "Your score is " + str(score))291 score_and_time_text.next_line(82)292 score_and_time_text.draw_this(window_surface, "Your time is " + str(time))293 score_and_time_text.next_line(82)294 handler = open("../stats/multiplayer_score.json", 'w')295 score_and_time_text.color = COLOR_RED296 if score > data["Top score"] and time > data["Top time"]:297 score_and_time_text.draw_this(window_surface, "New top score and time!")298 data["Top score"] = score299 data["Top time"] = time300 elif score > data["Top score"]:301 score_and_time_text.draw_this(window_surface, "New top score!")302 data["Top score"] = score303 elif time > data["Top time"]:304 score_and_time_text.draw_this(window_surface, "New top time!")305 data["Top time"] = time306 score_and_time_text.color = COLOR_BLACK307 json.dump(data, handler)308 handler.close()309 score_and_time_text.next_line(82)310 score_and_time_text.draw_this(window_surface, "Top score: " + str(data["Top score"]))311 score_and_time_text.next_line(82)312 score_and_time_text.draw_this(window_surface, "Top time: " + str(data["Top time"]))313 text_press_esc = interface.TextView(font2, COLOR_WHITE, 150, 2 * WINDOW_HEIGHT / 6, "Press ESC to exit")314 text_press_esc.rect.center = (4*WINDOW_WIDTH / 5, 7*WINDOW_HEIGHT / 8)315 text_press_esc.draw(window_surface)316 pygame.display.update()317 while True:318 for event in pygame.event.get():319 if event.type == KEYUP:320 if event.key == K_ESCAPE:321 return322def giving_port_layout(window_surface, WINDOW_WIDTH, WINDOW_HEIGHT):323 rect = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3, 2 * WINDOW_HEIGHT / 3))324 rect_border = pygame.Rect((0, 0), (2 * WINDOW_WIDTH / 3 + 10, 2 * WINDOW_HEIGHT / 3 + 10))325 rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)326 rect_border.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)327 port = random.randint(10000, 14000)328 font0 = pygame.font.SysFont(None, 140)329 text_victory = interface.TextView(font0, COLOR_BLACK, 150, 2 * WINDOW_HEIGHT / 6, "Your port is " + str(port))330 text_victory.rect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)331 pygame.display.update()332 button_done = interface.Button(2 * WINDOW_WIDTH / 3, 5 * WINDOW_HEIGHT / 8 + 60,333 WINDOW_WIDTH / 6, WINDOW_HEIGHT / 8, "We are ready!")334 while True:335 for event in pygame.event.get():336 mouse_pos = pygame.mouse.get_pos()337 if event.type == QUIT:338 exit(0)339 if event.type == KEYUP:340 if event.key == K_ESCAPE:341 return port342 if button_done.is_over(mouse_pos):343 if event.type == pygame.MOUSEBUTTONDOWN:344 return port345 pygame.draw.rect(window_surface, COLOR_BLACK, rect_border)346 pygame.draw.rect(window_surface, COLOR_BRIGHT_GREY, rect)347 text_victory.draw(window_surface)348 button_done.draw(window_surface)...

Full Screen

Full Screen

SurfingTurtles_BeachhacksSubmission.py

Source:SurfingTurtles_BeachhacksSubmission.py Github

copy

Full Screen

...25shark1.shape("circle")26shark1.color("light blue")27shark1.shapesize(stretch_wid=5, stretch_len=2)28shark1.penup()29shark1Start = random.randint(-(win.window_width()/2), (win.window_width()/2))30shark1.goto(shark1Start, (win.window_height()/2+250))31shark1.dy = .43233# attributes of shark 234shark2 = turtle.Turtle()35shark2.speed(0)36shark2.shape("triangle")37shark2.color("grey")38shark2.shapesize(stretch_wid=5, stretch_len=2)39shark2.penup()40shark2Start = random.randint(-(win.window_width()/2), (win.window_width()/2))41shark2.goto(shark2Start, (win.window_height()/2+250))42shark2.dy = .64344# attributes of shark 345shark3 = turtle.Turtle()46shark3.speed(0)47shark3.shape("circle")48shark3.color("grey")49shark3Width = 350shark3.shapesize(stretch_wid=shark3Width, stretch_len=2)51shark3.penup()52shark3Start = random.randint(-(win.window_width()/2), (win.window_width()/2))53shark3.goto(shark3Start, (win.window_height()/2+250))54shark3.dy = .85556# attributes of shark 457shark4 = turtle.Turtle()58shark4.speed(0)59shark4.shape("circle")60shark4.color("grey")61shark4Length = 462shark4.shapesize(stretch_wid=5, stretch_len=shark4Length)63shark4.penup()64shark4Start = random.randint(-(win.window_width()/2), (win.window_width()/2))65shark4.goto(shark4Start, (win.window_height()/2+250))66shark4.dy = .26768# boolean that states that the game isn't over until something happens to the surfer69gameOver = False70resetGame = False7172pen = turtle.Turtle()73pen.speed(0)74pen.color("white")75pen.penup()76pen.hideturtle()7778# lets surfer go up79def surfer_up():80 y = surfer.ycor()81 y += 2082 surfer.sety(y)8384# lets surfer go down85def surfer_down():86 y = surfer.ycor()87 y += -2088 surfer.sety(y)8990# lets surfer go left91def surfer_left():92 x = surfer.xcor()93 x += -2094 surfer.setx(x)9596# lets surfer go right97def surfer_right():98 x = surfer.xcor()99 x += 20100 surfer.setx(x)101102# sets False103def set_false(x):104 x = False105 return x106107# leaves the loopo108def leave_loop(x):109 new_x = set_false(x[0])110 x[0] = new_x111112113# keyboard binding up, down, left, right114win.listen()115win.onkeypress(surfer_up, "Up")116win.onkeypress(surfer_down, "Down")117win.onkeypress(surfer_left, "Left")118win.onkeypress(surfer_right, "Right")119120# loops the bring a new result121while True:122 win.update()123124 #move sharks125126 # border checking127 if surfer.ycor() > 300:128 surfer.sety(300)129130 if surfer.ycor() < -300:131 surfer.sety(-300)132133 if surfer.xcor() > 380:134 surfer.setx(380)135136 if surfer.xcor() < -380:137 surfer.setx(-380)138139# randomizes which shark goes down from 1-4140 currentShark = random.randint(1, 4)141142# brings shark 1143 if currentShark == 1:144 shark1.sety(shark1.ycor() - shark1.dy)145 if shark1.ycor() < -450:146 shark1Start147 shark1Start = random.randint(-(win.window_width() / 2), win.window_width() / 2)148 shark1.goto(shark1Start, ((win.window_height() / 2) + 250))149 shark1.dy += .1150# brings shark 2151 if currentShark == 2:152 shark2.sety(shark2.ycor() - shark2.dy)153 if shark2.ycor() < -450:154 shark2Start155 shark2Start = random.randint(-(win.window_width() / 2), win.window_width() / 2)156 shark2.goto(shark2Start, ((win.window_height() / 2) + 250))157 shark2.dy += .1158# brings shark 3159 if currentShark == 3:160 shark3.sety(shark1.ycor() - shark3.dy)161 if shark3.ycor() < -450:162 shark3Start163 shark3Start = random.randint(-(win.window_width() / 2), win.window_width() / 2)164 shark3.goto(shark1Start, ((win.window_height() / 2) + 250))165 shark3.dy += .1166# brings shark 4167 if currentShark == 4:168 shark4.sety(shark4.ycor() - shark4.dy)169 if shark4.ycor() < -450:170 shark4Start171 shark4Start = random.randint(-(win.window_width() / 2), win.window_width() / 2)172 shark4.goto(shark4Start, ((win.window_height() / 2) + 250))173 shark4.dy += .1174175# if any of the sharks hit the surfer, gameOver returns True ending the game176 #Game Over177 if (shark1.ycor() <= surfer.ycor() + 60) and (shark1.xcor() < surfer.xcor() + 20) and (shark1.xcor() > surfer.xcor() - 20)\178 and (shark1.ycor() >= surfer.ycor()):179 gameOver = True180181 if (shark2.ycor() <= surfer.ycor() + 60) and (shark2.xcor() < surfer.xcor() + 20) and (shark2.xcor() > surfer.xcor() - 20)\182 and (shark2.ycor() >= surfer.ycor()):183 gameOver = True184185 if (shark3.ycor() <= surfer.ycor() + 10 + (shark3Width*10)) and (shark3.xcor() < surfer.xcor() + 20) and (shark3.xcor() > surfer.xcor() - 20)\186 and (shark3.ycor() >= surfer.ycor()):187 gameOver = True188189 if (shark4.ycor() <= surfer.ycor() + 60) and (shark4.xcor() < surfer.xcor() + (10*shark4Length)) and (shark4.xcor() > surfer.xcor() - (10*shark4Length))\190 and (shark4.ycor() >= surfer.ycor()):191 gameOver = True192193# stops the sharks from continuing when gameOver, ending title is displayed194 if gameOver:195 shark1.dy = 0196 shark2.dy = 0197 shark3.dy = 0198 shark4.dy = 0199 surfer.hideturtle()200 pen.goto(0, 25)201 pen.write("Game Over", align="center", font=("Courier", 35, "normal"))202 pen.goto(0, -25)203 pen.write("Leave window to exit.", align="center", font=("Courier", 24, "normal"))204 resetGame = True205 gameOverArray = [gameOver]206207 #Uncomment when you have the function to SET gameOver FALSE208 win.onkeypress(leave_loop(gameOverArray), "enter")209 gameOver = gameOverArray[0]210 #Also make a function to set the loop to false, if possible. Maybe assign the loop bool to a value we change here211 #win.onkeypress(SETloopFALSE, "escape")212213# to start the game again214 else:215 if resetGame:216 pen.clear()217 surfer.showturtle()218 surfer.goto(0,0)219 shark1.dy = .2220 shark2.dy = .3221 shark3.dy = .4222 shark4.dy = .1223 shark1Start = random.randint(-(win.window_width()/2),win.window_width()/2)224 shark2Start = random.randint(-(win.window_width()/2),win.window_width()/2)225 shark3Start = random.randint(-(win.window_width()/2),win.window_width()/2)226 shark4Start = random.randint(-(win.window_width()/2),win.window_width()/2)227 shark1.goto(shark1Start, (win.window_height()/2+250))228 shark2.goto(shark2Start, (win.window_height()/2+250))229 shark3.goto(shark3Start, (win.window_height()/2+250))230 shark4.goto(shark4Start, (win.window_height()/2+250))231 resetGame = False232 ...

Full Screen

Full Screen

numba_sample_ridge.py

Source:numba_sample_ridge.py Github

copy

Full Screen

1from numba import jit, njit2import numpy as np3@njit(fastmath=True)4def numba_sample_ridge(window_width, ridge_mask, distance_map, distance_threshold):5 # Currently, this does not properly handle the borders of the6 # image (i.e., <= window_width of the image edges.7 h, w = ridge_mask.shape8 sample_map = np.zeros_like(ridge_mask, np.uint8)9 l_y_max = h - window_width10 l_x_max = w - window_width11 l_y = 012 while l_y < l_y_max:13 l_x = 014 while l_x < l_x_max:15 max_found = False16 max_value = 017 max_y = 018 max_x = 019 w_y = 020 while w_y < window_width:21 y = l_y + w_y22 w_x = 023 while w_x < window_width: 24 x = l_x + w_x25 if ridge_mask[y,x] > 0:26 value = distance_map[y,x]27 if (value > distance_threshold) and (value > max_value):28 max_found = True29 max_value = value30 max_y = y31 max_x = x32 w_x += 133 w_y += 134 if max_found:35 sample_map[max_y, max_x] = 25536 l_x += window_width37 l_y += window_width38 l_y = window_width//239 while l_y < l_y_max:40 l_x = window_width//241 while l_x < l_x_max:42 max_found = False43 max_value = 044 max_y = 045 max_x = 046 w_y = 047 while w_y < window_width:48 y = l_y + w_y49 w_x = 050 while w_x < window_width: 51 x = l_x + w_x52 if sample_map[y,x] > 0:53 sample_map[y,x] = 054 value = distance_map[y,x]55 if value > max_value:56 max_found = True57 max_value = value58 max_y = y59 max_x = x60 w_x += 161 w_y += 162 if max_found:63 sample_map[max_y, max_x] = 25564 l_x += window_width65 l_y += window_width66 return sample_map67@njit(fastmath=True)68def numba_sample_ridge_list(window_width, ridge_mask, distance_map, distance_threshold):69 # Currently, this does not properly handle the borders of the70 # image (i.e., <= window_width of the image edges.71 h, w = ridge_mask.shape72 73 sample_map = np.zeros_like(ridge_mask, np.uint8)74 l_y_max = h - window_width75 l_x_max = w - window_width76 l_y = 077 while l_y < l_y_max:78 l_x = 079 while l_x < l_x_max:80 max_found = False81 max_value = 082 max_y = 083 max_x = 084 w_y = 085 while w_y < window_width:86 y = l_y + w_y87 w_x = 088 while w_x < window_width: 89 x = l_x + w_x90 if ridge_mask[y,x] > 0:91 value = distance_map[y,x]92 if (value > distance_threshold) and (value > max_value):93 max_found = True94 max_value = value95 max_y = y96 max_x = x97 w_x += 198 w_y += 199 if max_found:100 sample_map[max_y, max_x] = 255101 l_x += window_width102 l_y += window_width103 sample_list = []104 105 l_y = window_width//2106 while l_y < l_y_max:107 l_x = window_width//2108 while l_x < l_x_max:109 max_found = False110 max_value = 0111 max_y = 0112 max_x = 0113 w_y = 0114 while w_y < window_width:115 y = l_y + w_y116 w_x = 0117 while w_x < window_width: 118 x = l_x + w_x119 if sample_map[y,x] > 0:120 value = distance_map[y,x]121 if value > max_value:122 max_found = True123 max_value = value124 max_y = y125 max_x = x126 w_x += 1127 w_y += 1128 if max_found:129 sample_list.append([max_x, max_y])130 l_x += window_width131 l_y += window_width...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful