-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpygame_window.py
More file actions
32 lines (26 loc) · 925 Bytes
/
pygame_window.py
File metadata and controls
32 lines (26 loc) · 925 Bytes
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
import pygame
import numpy as np
import redis
import pickle
redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
def visualize():
pygame.init()
window_size = 500
screen = pygame.display.set_mode((window_size, window_size))
pygame.display.set_caption("Minigrid Visualization")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if redis_client.llen('frames') > 0:
frame = redis_client.rpop('frames')
print("POPPIN'")
img = pickle.loads(frame)
surface = pygame.surfarray.make_surface(np.transpose(img, (1, 0, 2)))
surface = pygame.transform.scale(surface, (window_size, window_size))
screen.blit(surface, (0, 0))
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
visualize()