Advertisement
fevzi02

5Лаба_графика 11.12.21

Dec 11th, 2021
3,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.57 KB | None | 0 0
  1. import pygame, sys, random
  2.  
  3. class Main:
  4.     def __init__(self, fps=60, screen_resolution=()):
  5.         self.fps = fps
  6.         pygame.init()
  7.         self.screen = pygame.display.set_mode((1080,720))
  8.         self.clock = pygame.time.Clock()
  9.         self.display_width, self.display_height = pygame.display.Info().current_w, pygame.display.Info().current_h
  10.         self.bool_pos = 0
  11.         self.x = 10
  12.         self.conter = 0
  13.         #0 - Левое Крыло; 2 - Правое крыло; 1 - Основа; 3 - Заднее Левое Крыло; 4 - Заднее Правое Крыло
  14.         self.list_0_coordinates = [[215, 100], [255, 100],
  15.                                     [365, 307], [265, 310]]
  16.         self.list_2_coordinates = [[215, 560], [255, 560],
  17.                                     [365, 353], [265, 350]]
  18.         self.list_3_coordinates = [[0, 250], [20, 250],
  19.                                     [90, 330], [30, 330]]
  20.         self.list_4_coordinates = [[0, 410], [20, 410],
  21.                                     [90, 330], [30, 330]]
  22.         self.list_1_coordinates = [[505, 330], [495, 345], [480, 360],
  23.                                     [50, 345], [30, 330],
  24.                                     [50, 315], [480, 300],[495, 315]]
  25.         #Тут Отрисовка перед циклом
  26.     def run_while(self):
  27.         while True:
  28.             self.conter += 1
  29.             if not self.bool_pos:
  30.                 self.drawing_in_a_loop()
  31.             self.event_handler()
  32.             pygame.display.flip()
  33.             self.clock.tick(self.fps)
  34.  
  35.     def event_handler(self):
  36.         for event in pygame.event.get():
  37.             if event.type == pygame.QUIT:
  38.                 pygame.quit()
  39.                 sys.exit()
  40.             if event.type == pygame.KEYDOWN :
  41.                 if event.key == pygame.K_ESCAPE:
  42.                     pygame.quit()
  43.                     sys.exit()
  44.             if event.type == pygame.MOUSEBUTTONDOWN :
  45.                 self.pos = event.pos
  46.                 print(self.pos)
  47.                 #if self.pos
  48.                 self.bool_pos = 1
  49.     def inPolygon(x, y, xp, yp):
  50.         c=0
  51.         for i in range(len(xp)):
  52.             if (((yp[i]<=y and y<yp[i-1]) or (yp[i-1]<=y and y<yp[i])) and
  53.                 (x > (xp[i-1] - xp[i]) * (y - yp[i]) / (yp[i-1] - yp[i]) + xp[i])): c = 1 - c
  54.         return c
  55.  
  56.         #print( inPolygon(100, 0, (-100, 100, 100, -100), (100, 100, -100, -100)))
  57.     def drawing_in_a_loop(self):
  58.         if self.list_4_coordinates[0][0] >=  pygame.display.Info().current_w:
  59.             self.list_0_coordinates = [[-290, 100], [-250, 100], [-140, 307], [-240, 310]]
  60.             self.list_2_coordinates = [[-290, 560], [-250, 560], [-140, 353], [-240, 350]]
  61.             self.list_3_coordinates = [[-505, 250], [-485, 250], [-415, 330], [-475, 330]]
  62.             self.list_4_coordinates = [[-505, 410], [-485, 410], [-415, 330], [-475, 330]]
  63.             self.list_1_coordinates = [[0, 330], [-10, 345], [-25, 360], [-455, 345],
  64.                                     [-475, 330], [-455, 315], [-25, 300], [-10, 315]]
  65.         self.screen.fill((125,249,255))
  66.         for i in range(len(self.list_0_coordinates)):
  67.             self.list_0_coordinates[i][0] += self.x
  68.         for i in range(len(self.list_1_coordinates)):
  69.             self.list_1_coordinates[i][0] += self.x
  70.         for i in range(len(self.list_2_coordinates)):
  71.             self.list_2_coordinates[i][0] += self.x
  72.         for i in range(len(self.list_3_coordinates)):
  73.             self.list_3_coordinates[i][0] += self.x
  74.         for i in range(len(self.list_4_coordinates)):
  75.             self.list_4_coordinates[i][0] += self.x
  76.  
  77.         pygame.draw.lines(self.screen, "black", True, self.list_0_coordinates, 5)
  78.         pygame.draw.lines(self.screen, "black", True, self.list_2_coordinates, 5)
  79.         pygame.draw.polygon(self.screen, (181,184,187), self.list_0_coordinates)
  80.         pygame.draw.polygon(self.screen, (181,184,187), self.list_2_coordinates)
  81.         pygame.draw.polygon(self.screen, (181,184,187), self.list_3_coordinates)
  82.         pygame.draw.polygon(self.screen, (181,184,187), self.list_4_coordinates)
  83.         pygame.draw.aalines(self.screen, "black", True, self.list_3_coordinates, 5)
  84.         pygame.draw.aalines(self.screen, "black", True, self.list_4_coordinates, 5)
  85.         pygame.draw.polygon(self.screen, (181,184,187), self.list_1_coordinates)
  86.         pygame.draw.aalines(self.screen, "black", True, self.list_1_coordinates, 5)
  87.  
  88.     def rendering(self):
  89.         pass
  90.         pygame.draw.circle(self.screen, "red", (100,100), 50)
  91.  
  92. Main(24).run_while()
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement