Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- from pygame.locals import *
- from pygame.sprite import Group
- #import numpy
- import matplotlib
- import numpy as np
- from functions import *
- from button import Button
- from settings import Settings
- from stats import GameStats
- from scoreboard import Scoreboard
- from graph import Graph
- # Запускает matlotlib во встроенном режиме
- matplotlib.use("Agg")
- import matplotlib.pyplot as plt
- import matplotlib.backends.backend_agg as agg
- def run_game():
- pygame.init()
- settings = Settings()
- screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
- stats = GameStats(settings)
- #Generating Data
- np.seterr(divide='ignore', invalid='ignore')
- x = np.linspace(-2, 2, 100)
- y = (x ** 3)
- z = np.around(np.arange(-10, 10, 1), decimals=4)
- k = z
- a = np.around(np.arange(-10, 10, 1), decimals=4)
- b = a
- #Creating graph objects
- graphs = Graph(x, y, z, k, a, b)
- scoreboard = Scoreboard(settings, screen, stats)
- pygame.display.set_caption("Graphics")
- pygame.display.set_icon(pygame.image.load("stocks.bmp"))
- exit_button = Button(settings, screen, 'Exit')
- start_button = Button(settings, screen, 'Start')
- skip_button = Button(settings, screen, 'Skip')
- answer_button1 = Button(settings, screen, 'Answer 1')
- answer_button2 = Button(settings, screen, 'Answer 2')
- answer_button3 = Button(settings, screen, 'Answer 3')
- menu_buttons = {'exit_button': exit_button, 'start_button' : start_button}
- game_buttons = Group(answer_button1, answer_button2, answer_button3, skip_button)
- while True:
- update_screen(settings, screen, stats, menu_buttons, scoreboard, game_buttons)
- #draw_graphs
- #if stats.game_active:
- #for button in game_buttons:
- #button.draw_button()
- check_events(settings,screen,stats, menu_buttons, scoreboard)
- run_game()
- # Создание объекта графика и задание ему размера
- #fig = plt.figure(figsize=[3, 3])
- # Размер и расположение графика(последняя цифра показывает положение)
- # fig.add_subplot(221) #top left
- # fig.add_subplot(222) #top right
- # fig.add_subplot(223) #bottom left
- # fig.add_subplot(224) #bottom right
- #ax = fig.add_subplot(331)
- #ax = fig.add_subplot(111)
- # Добавление графика fig на холст
- # Отрисовка графика
- # def plot(data):
- #
- # # Создается график фигуры ax с данными data
- # #ax.plot(data)
- #
- #
- #
- # # Рендер
- # renderer = canvas.get_renderer()
- #
- # # Помещение буфера кодов цветов в string
- # raw_data = renderer.tostring_rgb()
- #
- # # Задание размера
- # size = canvas.get_width_height()
- #
- # return pygame.image.fromstring(raw_data, size, "RGB")
- # Добавление головы
- pygame.init()
- clock = pygame.time.Clock()
- #screen = pygame.display.set_mode((1001, 1001))
- # ОСНОВНОЙ КУСОК КОДА
- # fig = plt.figure()
- # axes = fig.add_axes([0,0,1,1,])
- # Костыль для игнорирования сообщения о делении на 0
- history = np.array([])
- surf = plot(history)
- while True:
- # Erase screen
- # Обновление экрана
- screen.fill((255, 255, 255))
- screen.blit(surf, (100, 100))
- # Отрисовка окна pygame
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- pygame.display.update()
- clock.tick(30)
Advertisement
Add Comment
Please, Sign In to add comment