Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python Let's explore some of the design choices that PyGame made by answering a couple of questions about them. Why do we need to flip
python
Let's explore some of the design choices that PyGame made by answering a couple of questions about them.
- Why do we need to "flip" the display in order to see what we've drawn? Of course, the short answer is "So we can see what we drew!", but that's not really the interesting question. The interesting question is this: Why was PyGame designed so that we have to flip the display before we see what was drawn?
- What is the purpose of using PyGame's Clock class? We saw that we can call tick on a Clock object to, for example, establish a frame rate of 30 frames per second. But what is a practical benefit of doing that, when we could instead run at a much higher rate?
import math import pygame class Blip: def __init__(self): self._radius = 0 self._angle = 0 def move(self) -> None: self._radius += 0.001 self._angle += 1 def radius(self) -> float: return self._radius def angle(self) -> float: return self._angle def _determine_blip_center(surface: pygame.Surface, blip: Blip) -> (float, float): return (0.0, 0.0) def run() -> None: pygame.init() try: surface = pygame.display.set_mode((700, 700), pygame.RESIZABLE) running = True clock = pygame.time.Clock() blips = [] next_blip = 30 while running: clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False break elif event.type == pygame.VIDEORESIZE: surface = pygame.display.set_mode(event.size, pygame.RESIZABLE) for blip in blips: blip.move() next_blip -= 1 if next_blip == 0: blips.append(Blip()) next_blip = 30 surface.fill(pygame.Color(64, 64, 64)) for blip in blips: pygame.draw.circle( surface, pygame.Color(255, 255, 0), _determine_blip_center(surface, blip), 10) pygame.display.flip() finally: pygame.quit() if __name__ == '__main__': run()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started