Answered step by step
Verified Expert Solution
Link Copied!

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.

  1. 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?
  2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago

Question

3. Who would the members be?

Answered: 1 week ago