Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Pygame Modify the sample code so that the background color transitions through the sequence black, red, green, blue, orange, yellow, brown. The background color
Python Pygame
Modify the sample code so that the background color transitions through the sequence black, red, green, blue, orange, yellow, brown. The background color should change once per second (every 30 frames). You can use this list of colors to figure out the RGB color codes.
This is the Sample code
6 from future import division 7 import math import sys import pygame 10 12 class MyGame (object): def _init__(self): """Initialize a new game" "" pygame.mixer.init() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() 14 15 16 17 18 19 20 21 # set up a 640 x 480 window self.width800 self.height 600 self.screenpygame.display.set_mode((self.width, self.height)) # use a black background self.bg_color-0, 0, 25 26 27 28 29 30 31 32 # Setup a timer to refresh the display FPS times per second self.FPS3 self.REFRESH pygame. USEREVENT+1 pygame.time.set_timer (self.REFRESH, 1000//self. FPS) def run(self): Loop forever processing events" runningTrue while running: 35 event = pygame .event.wait() 37 38 39 40 41 # player is asking to quit if event.typepygame.QUIT: running = False q02.py* 35:23 LF UTF-8 Python GitHub Git (0) running-False 41 42 43 # time to draw a new frame elif event.type self. REFRESH: self.draw) 15 46 47 48 49 50 51 52 53 54 else: pass # an event type we don't handle def draw(self) "Update the display""" # everything we draw now is to a buffer that is not displayed self.screen.fill(self.bg_color) # flip buffers so that everything we have drawn gets displayed pygame.display.flip() 56 57 58 59 MyGame().run) 60 61 sys.exit() 62 63 pygame.quit() q02.py 33:19 LF UTF-8 Python GitHub O Git (0) 6 from future import division 7 import math import sys import pygame 10 12 class MyGame (object): def _init__(self): """Initialize a new game" "" pygame.mixer.init() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() 14 15 16 17 18 19 20 21 # set up a 640 x 480 window self.width800 self.height 600 self.screenpygame.display.set_mode((self.width, self.height)) # use a black background self.bg_color-0, 0, 25 26 27 28 29 30 31 32 # Setup a timer to refresh the display FPS times per second self.FPS3 self.REFRESH pygame. USEREVENT+1 pygame.time.set_timer (self.REFRESH, 1000//self. FPS) def run(self): Loop forever processing events" runningTrue while running: 35 event = pygame .event.wait() 37 38 39 40 41 # player is asking to quit if event.typepygame.QUIT: running = False q02.py* 35:23 LF UTF-8 Python GitHub Git (0) running-False 41 42 43 # time to draw a new frame elif event.type self. REFRESH: self.draw) 15 46 47 48 49 50 51 52 53 54 else: pass # an event type we don't handle def draw(self) "Update the display""" # everything we draw now is to a buffer that is not displayed self.screen.fill(self.bg_color) # flip buffers so that everything we have drawn gets displayed pygame.display.flip() 56 57 58 59 MyGame().run) 60 61 sys.exit() 62 63 pygame.quit() q02.py 33:19 LF UTF-8 Python GitHub O Git (0)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