Advertisement
fevzi02

Пример простой анимации треугольника

Dec 12th, 2021
1,002
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #1 Импорт Нужных библиотек
  2. import pygame, sys
  3. #/1
  4.  
  5. #2 Переменные
  6. fps = 24
  7. pygame.init()
  8. screen = pygame.display.set_mode((1080, 720))
  9. clock = pygame.time.Clock()
  10. display_width, display_height = pygame.display.Info().current_w, pygame.display.Info().current_h
  11.  
  12. #list_polygon_1 = [[, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ], [, ]]
  13. list_polygon_1 = [[100, 100], [300, 100], [200, 300]]
  14. color_polygon_1 = "red"
  15. otstup = 5
  16. #/2
  17.  
  18. #3 Отрисовка Анимации
  19. while True:
  20.     screen.fill("white")
  21.     #4 Тут твой код для анимации
  22.     for i in range(len(list_polygon_1)):
  23.         list_polygon_1[i][0] += otstup
  24.         if list_polygon_1[i][0] >= display_width or list_polygon_1[i][0] <= 0:
  25.             otstup *= -1
  26.     pygame.draw.polygon(screen, color_polygon_1, list_polygon_1)
  27.     #/4
  28.  
  29.     #5 Обработчик Событий
  30.     for event in pygame.event.get():
  31.         if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  32.             pygame.quit()
  33.             sys.exit()
  34.     #/5
  35.  
  36.     #6 Магия
  37.     pygame.display.flip()
  38.     clock.tick(fps)
  39.     #/6
  40.  
  41. #/3
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement