Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

""" 

Opens a window that displays an image. 

Usage: 

 

from viewer import GlobalViewer 

GlobalViewer.update(image) 

 

""" 

import numpy as np 

 

class PygameViewer: 

 

def __init__(self, title="HyperGAN", enabled=True): 

self.screen = None 

self.title = title 

self.enabled = enabled 

 

def update(self, image): 

if not self.enabled: return 

 

image = np.transpose(image, [1, 0,2]) 

size = [image.shape[0], image.shape[1]] 

if not self.screen: 

import pygame 

self.pg = pygame 

self.screen = self.pg.display.set_mode(size) 

self.pg.display.set_caption(self.title) 

self.pg.event.get() 

surface = self.pg.Surface(size) 

self.pg.surfarray.blit_array(surface, image) 

self.screen.blit(surface, (0,0)) 

self.pg.display.flip()