fr0stn1k

Untitled

Jan 29th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4. from pygame.sprite import Group
  5. #import numpy
  6. import matplotlib
  7. import numpy as np
  8. from functions import *
  9. from button import Button
  10. from settings import Settings
  11. from stats import GameStats
  12. from scoreboard import Scoreboard
  13. from graph import Graph
  14.  
  15. # Запускает matlotlib во встроенном режиме
  16. matplotlib.use("Agg")
  17.  
  18. import matplotlib.pyplot as plt
  19. import matplotlib.backends.backend_agg as agg
  20.  
  21. def run_game():
  22. pygame.init()
  23.  
  24. settings = Settings()
  25. screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
  26. stats = GameStats(settings)
  27.  
  28. #Generating Data
  29. np.seterr(divide='ignore', invalid='ignore')
  30.  
  31. x = np.linspace(-2, 2, 100)
  32. y = (x ** 3)
  33.  
  34. z = np.around(np.arange(-10, 10, 1), decimals=4)
  35. k = z
  36.  
  37. a = np.around(np.arange(-10, 10, 1), decimals=4)
  38. b = a
  39.  
  40. #Creating graph objects
  41.  
  42. graphs = Graph(x, y, z, k, a, b)
  43.  
  44.  
  45.  
  46.  
  47. scoreboard = Scoreboard(settings, screen, stats)
  48.  
  49. pygame.display.set_caption("Graphics")
  50. pygame.display.set_icon(pygame.image.load("stocks.bmp"))
  51.  
  52. exit_button = Button(settings, screen, 'Exit')
  53. start_button = Button(settings, screen, 'Start')
  54. skip_button = Button(settings, screen, 'Skip')
  55.  
  56. answer_button1 = Button(settings, screen, 'Answer 1')
  57. answer_button2 = Button(settings, screen, 'Answer 2')
  58. answer_button3 = Button(settings, screen, 'Answer 3')
  59.  
  60. menu_buttons = Group()
  61. menu_buttons.add(exit_button)
  62. menu_buttons.add(start_button)
  63. game_buttons = Group(answer_button1, answer_button2, answer_button3, skip_button)
  64.  
  65.  
  66.  
  67.  
  68. while True:
  69. update_screen(settings, screen, stats, menu_buttons, scoreboard, game_buttons)
  70. draw_graphs
  71. if stats.game_active:
  72. for button in game_buttons:
  73. button.draw_button()
  74.  
  75. run_game()
  76.  
  77.  
  78. # Создание объекта графика и задание ему размера
  79. #fig = plt.figure(figsize=[3, 3])
  80.  
  81. # Размер и расположение графика(последняя цифра показывает положение)
  82. # fig.add_subplot(221) #top left
  83. # fig.add_subplot(222) #top right
  84. # fig.add_subplot(223) #bottom left
  85. # fig.add_subplot(224) #bottom right
  86. #ax = fig.add_subplot(331)
  87. #ax = fig.add_subplot(111)
  88.  
  89.  
  90.  
  91. # Добавление графика fig на холст
  92.  
  93.  
  94. # Отрисовка графика
  95. # def plot(data):
  96. #
  97. # # Создается график фигуры ax с данными data
  98. # #ax.plot(data)
  99. #
  100. #
  101. #
  102. # # Рендер
  103. # renderer = canvas.get_renderer()
  104. #
  105. # # Помещение буфера кодов цветов в string
  106. # raw_data = renderer.tostring_rgb()
  107. #
  108. # # Задание размера
  109. # size = canvas.get_width_height()
  110. #
  111. # return pygame.image.fromstring(raw_data, size, "RGB")
  112.  
  113. # Добавление головы
  114. pygame.init()
  115. clock = pygame.time.Clock()
  116. #screen = pygame.display.set_mode((1001, 1001))
  117.  
  118. # ОСНОВНОЙ КУСОК КОДА
  119. # fig = plt.figure()
  120. # axes = fig.add_axes([0,0,1,1,])
  121.  
  122.  
  123. # Костыль для игнорирования сообщения о делении на 0
  124.  
  125.  
  126.  
  127. history = np.array([])
  128. surf = plot(history)
  129.  
  130. while True:
  131. # Erase screen
  132. # Обновление экрана
  133. screen.fill((255, 255, 255))
  134.  
  135.  
  136. screen.blit(surf, (100, 100))
  137.  
  138. # Отрисовка окна pygame
  139. for event in pygame.event.get():
  140. if event.type == QUIT:
  141. pygame.quit()
  142. sys.exit()
  143.  
  144. pygame.display.update()
  145. clock.tick(30)
Advertisement
Add Comment
Please, Sign In to add comment