├── README.md ├── ascii-map.png ├── main.py ├── map.c └── map.png /README.md: -------------------------------------------------------------------------------- 1 | # ascii-map 2 | How to create an ASCII map [YouTube](https://youtu.be/j40OZ2g-dao) 3 | 4 | ![Map of Bangladesh](./ascii-map.png) 5 | -------------------------------------------------------------------------------- /ascii-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riadafridishibly/ascii-map/d52313d0dcba1a93ce0b5e7dbf7f5c9542115f1c/ascii-map.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | import pygame 3 | pygame.init() 4 | 5 | 6 | # image width and height 7 | width = 640 8 | height = 800 9 | 10 | screen = pygame.display.set_mode((width, height)) 11 | pygame.display.set_caption('BD map ASCII Encoder') 12 | 13 | img_path = 'map.png' 14 | img = pygame.image.load(img_path) 15 | imgRect = img.get_rect() 16 | 17 | 18 | # cell size 19 | W, H = 10, 20 20 | offsetX = W // 2 21 | offsetY = H // 2 22 | 23 | 24 | def drawRect(surf, loc): 25 | pygame.draw.rect(surf, (0, 0, 0), (*loc, W, H), 1) 26 | 27 | 28 | def drawCircle(surf, loc): 29 | pygame.draw.circle(surf, (255, 0, 255), loc, 2, 2) 30 | 31 | 32 | running = True 33 | clock = pygame.time.Clock() 34 | 35 | data = [] 36 | 37 | while running: 38 | 39 | clock.tick(60) 40 | 41 | for event in pygame.event.get(): 42 | if event.type == pygame.QUIT: 43 | running = False 44 | 45 | screen.fill((255, 255, 255)) 46 | screen.blit(img, imgRect) 47 | 48 | for j in range(height // H): 49 | for i in range(width // W): 50 | x, y = (i * W, j * H) 51 | drawRect(screen, (x, y)) 52 | # move the points in the middle 53 | if img.get_at((x + offsetX, y + offsetY)) != (0, 0, 0, 0): 54 | drawCircle(screen, (x + offsetX, y + offsetY)) 55 | print('*', end='') 56 | data.append(1) 57 | else: 58 | print(' ', end='') 59 | data.append(0) 60 | print() 61 | running = False 62 | 63 | pygame.display.flip() 64 | 65 | pygame.quit() 66 | 67 | group = [len(list(g)) for k, g in groupby(data)] 68 | # remapping the chars 69 | encodedString = ''.join([chr(126 - val) for val in group]) 70 | 71 | # This is the magic string 72 | print(repr(encodedString)) 73 | 74 | -------------------------------------------------------------------------------- /map.c: -------------------------------------------------------------------------------- 1 | // Wednesday 24 Jul, 2019 05:34:01 AM 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | // Details in python file 8 | const char *magic = 9 | "y}@z?{|{HtJpy|TgUhQjPlKqIphynJsHw}}JuGwG}}tLmOhXe[`]b[tzn\\tzl]xvn[" 10 | "xwj_}}zvl[}tlOm]}pn_zqmd{}xsmer{|xmfr}zxmfmxm||phwm||z}|{{gwl}WxCxF|y}" 11 | "="; 12 | 13 | const int len = strlen(magic); 14 | 15 | int counter = 0; 16 | for (int i = 0; i < len; ++i) { 17 | int value = 126 - magic[i]; 18 | for (int j = 0; j < value; ++j, ++counter) { 19 | if (counter == 64) { 20 | counter = 0; 21 | puts(""); 22 | } 23 | putchar(i & 0x1 ? '*' : ' '); 24 | } 25 | } 26 | puts(""); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riadafridishibly/ascii-map/d52313d0dcba1a93ce0b5e7dbf7f5c9542115f1c/map.png --------------------------------------------------------------------------------