-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.py
More file actions
54 lines (40 loc) · 1.46 KB
/
display.py
File metadata and controls
54 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pygame
# from bitmap import Bitmap
class Display:
def __init__(self, width, height, title):
self.width = width
self.height = height
self.title = title
self.displayImage = None
self.displayComponents = None
# self.frameBuffer = None
self.clock = pygame.time.Clock()
self.timedelta = 1.0
# initialize pygame
pygame.init()
self.display = pygame.display.set_mode((self.width,self.height))
pygame.display.set_caption(self.title)
self.running = True
# self.frameBuffer = Bitmap(self.width, self.height)
self.displayComponents = pygame.Surface((self.width,self.height)).get_buffer()
self.displayImage = pygame.image.frombuffer(self.displayComponents, (self.width,self.height), 'RGBA')
def poll_events(self):
# poll all events
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
def render(self):
self.timedelta = self.clock.tick(60) / 1000 # convert to milliseconds
# blit to surface
self.display.blit(self.displayImage, (0, 0))
pygame.display.update()
def clean_up(self):
pygame.quit()
def get_delta(self):
return self.timedelta
def get_target(self):
return self.displayImage
def get_aspect_ratio(self):
return self.width/self.height
def is_running(self):
return self.running