-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.py
73 lines (50 loc) · 1.48 KB
/
main.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from itertools import groupby
import pygame
pygame.init()
# image width and height
width = 640
height = 800
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('BD map ASCII Encoder')
img_path = 'map.png'
img = pygame.image.load(img_path)
imgRect = img.get_rect()
# cell size
W, H = 10, 20
offsetX = W // 2
offsetY = H // 2
def drawRect(surf, loc):
pygame.draw.rect(surf, (0, 0, 0), (*loc, W, H), 1)
def drawCircle(surf, loc):
pygame.draw.circle(surf, (255, 0, 255), loc, 2, 2)
running = True
clock = pygame.time.Clock()
data = []
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((255, 255, 255))
screen.blit(img, imgRect)
for j in range(height // H):
for i in range(width // W):
x, y = (i * W, j * H)
drawRect(screen, (x, y))
# move the points in the middle
if img.get_at((x + offsetX, y + offsetY)) != (0, 0, 0, 0):
drawCircle(screen, (x + offsetX, y + offsetY))
print('*', end='')
data.append(1)
else:
print(' ', end='')
data.append(0)
print()
running = False
pygame.display.flip()
pygame.quit()
group = [len(list(g)) for k, g in groupby(data)]
# remapping the chars
encodedString = ''.join([chr(126 - val) for val in group])
# This is the magic string
print(repr(encodedString))