You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
from .mapfile import MapFile
|
|
|
|
import pygame
|
|
|
|
colors = {
|
|
'?' : (192, 192, 192), # Non-tried
|
|
'*' : (0 , 0 , 255), # Non-trimmed
|
|
'/' : (255, 255, 0) , # Non-scraped
|
|
'-' : (255, 0 , 0) , # Bad
|
|
'+' : (0 , 128, 0) , # Recovered
|
|
None: (0 , 0 , 0) , # Not on disk
|
|
}
|
|
|
|
BORDERCOLOR = (64,64,64)
|
|
|
|
W = 1900
|
|
H = 1000
|
|
CELLSIZE = 7
|
|
CELLBORDER = 1
|
|
CELLMARGIN = 1
|
|
|
|
CELLOFFSET = CELLSIZE + 2*CELLBORDER + CELLMARGIN
|
|
COLUMNS = W // CELLOFFSET
|
|
ROWS = H // CELLOFFSET
|
|
CELLS = COLUMNS * ROWS
|
|
|
|
class Visualisation:
|
|
def __init__(self, fn):
|
|
pygame.init()
|
|
self.disp = pygame.display.set_mode((W, H))
|
|
|
|
self.mapfile = MapFile(fn)
|
|
self.mapfile.load()
|
|
|
|
def draw(self):
|
|
self.disp.fill((0,0,0)) # Dark theme :-)
|
|
|
|
sz = self.mapfile.size
|
|
sqsz = sz / CELLS
|
|
for cid in range(CELLS):
|
|
start = cid * sqsz
|
|
end = (cid + 1) * sqsz
|
|
hist = self.mapfile.get_hist(start, end).items()
|
|
# Majority
|
|
symb, _count = max(hist, key=lambda x: x[1])
|
|
color = colors[symb]
|
|
|
|
line = cid // COLUMNS
|
|
col = cid % COLUMNS
|
|
pos = (line, col)
|
|
|
|
rect = pygame.Rect(col * CELLOFFSET + CELLBORDER, line * CELLOFFSET + CELLBORDER, CELLSIZE+2*CELLBORDER, CELLSIZE+2*CELLBORDER)
|
|
pygame.draw.rect(self.disp, color, rect)
|
|
pygame.draw.rect(self.disp, BORDERCOLOR, rect, width=CELLBORDER)
|
|
|
|
pygame.display.flip()
|