Last active
August 14, 2024 18:00
-
-
Save MawKKe/8bfc064b09cf0ec6e835937dd25d3a05 to your computer and use it in GitHub Desktop.
Voronoi diagram in terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
M = 80 | |
points = [(10, 20), (40, 30), (40, 35), (65, 25), (55, 60), (20,60), (75,75)] | |
def dist(p1, p2): | |
dx = abs(p1[0] - p2[0]) | |
dy = abs(p1[1] - p2[1]) | |
return math.sqrt(dx*dx + dy*dy) | |
def gen_sym(pixel): | |
if pixel in points: | |
return ' ' | |
else: | |
dists = [(i, dist((x,y), p)) for i,p in enumerate(points)] | |
closest = min(dists, key=lambda d: d[1]) | |
return closest[0] | |
for y in range(M): | |
for x in range(M): | |
print(gen_sym((x,y)), end='') | |
print("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00000000000000000000000000000000001111111111111133333333333333333333333333333333 | |
00000000000000000000000000000000001111111111111133333333333333333333333333333333 | |
00000000000000000000000000000000011111111111111133333333333333333333333333333333 | |
00000000000000000000000000000000011111111111111133333333333333333333333333333333 | |
00000000000000000000000000000000011111111111111133333333333333333333333333333333 | |
00000000000000000000000000000000111111111111111113333333333333333333333333333333 | |
00000000000000000000000000000000111111111111111113333333333333333333333333333333 | |
00000000000000000000000000000000111111111111111113333333333333333333333333333333 | |
00000000000000000000000000000001111111111111111113333333333333333333333333333333 | |
00000000000000000000000000000001111111111111111113333333333333333333333333333333 | |
00000000000000000000000000000001111111111111111111333333333333333333333333333333 | |
00000000000000000000000000000011111111111111111111333333333333333333333333333333 | |
00000000000000000000000000000011111111111111111111333333333333333333333333333333 | |
00000000000000000000000000000011111111111111111111333333333333333333333333333333 | |
00000000000000000000000000000111111111111111111111333333333333333333333333333333 | |
00000000000000000000000000000111111111111111111111133333333333333333333333333333 | |
00000000000000000000000000000111111111111111111111133333333333333333333333333333 | |
00000000000000000000000000001111111111111111111111133333333333333333333333333333 | |
00000000000000000000000000001111111111111111111111133333333333333333333333333333 | |
00000000000000000000000000001111111111111111111111133333333333333333333333333333 | |
0000000000 000000000000000011111111111111111111111113333333333333333333333333333 | |
00000000000000000000000000011111111111111111111111113333333333333333333333333333 | |
00000000000000000000000000011111111111111111111111113333333333333333333333333333 | |
00000000000000000000000000111111111111111111111111113333333333333333333333333333 | |
00000000000000000000000000111111111111111111111111113333333333333333333333333333 | |
00000000000000000000000000111111111111111111111111111333333333333 33333333333333 | |
00000000000000000000000001111111111111111111111111111333333333333333333333333333 | |
00000000000000000000000001111111111111111111111111111333333333333333333333333333 | |
00000000000000000000000001111111111111111111111111111333333333333333333333333333 | |
00000000000000000000000011111111111111111111111111111333333333333333333333333333 | |
0000000000000000000000001111111111111111 111111111111133333333333333333333333333 | |
00000000000000000000000011111111111111111111111111111133333333333333333333333333 | |
00000000000000000000000111111111111111111111111111111133333333333333333333333333 | |
00000000000000000000000222222222222222222222222222222233333333333333333333333333 | |
00000000000000000000002222222222222222222222222222222223333333333333333333333333 | |
0000000000000000000000222222222222222222 222222222222223333333333333333333333333 | |
00000000000000000000022222222222222222222222222222222223333333333333333333333333 | |
00000000000000000000022222222222222222222222222222222222333333333333333333333333 | |
00000000000000000000222222222222222222222222222222222222333333333333333333333333 | |
00000000000000000000222222222222222222222222222222222222233333333333333333333333 | |
00000000000000005555522222222222222222222222222222222222233333333333333333333333 | |
00000000000055555555552222222222222222222222222222222222233333333333333333333333 | |
00000000555555555555555522222222222222222222222222222222244333333333333333333333 | |
00005555555555555555555552222222222222222222222222222222444444333333333333333333 | |
55555555555555555555555555222222222222222222222222222244444444444433333333333333 | |
55555555555555555555555555522222222222222222222222224444444444444444433333333333 | |
55555555555555555555555555555222222222222222222222244444444444444444444443333333 | |
55555555555555555555555555555522222222222222222224444444444444444444444444443333 | |
55555555555555555555555555555552222222222222222444444444444444444444444444444444 | |
55555555555555555555555555555555222222222222224444444444444444444444444444444446 | |
55555555555555555555555555555555552222222222444444444444444444444444444444444446 | |
55555555555555555555555555555555555222222244444444444444444444444444444444444466 | |
55555555555555555555555555555555555522222444444444444444444444444444444444444666 | |
55555555555555555555555555555555555552244444444444444444444444444444444444446666 | |
55555555555555555555555555555555555555444444444444444444444444444444444444446666 | |
55555555555555555555555555555555555555444444444444444444444444444444444444466666 | |
55555555555555555555555555555555555555444444444444444444444444444444444444666666 | |
55555555555555555555555555555555555555444444444444444444444444444444444446666666 | |
55555555555555555555555555555555555555444444444444444444444444444444444446666666 | |
55555555555555555555555555555555555555444444444444444444444444444444444466666666 | |
55555555555555555555 5555555555555555544444444444444444 444444444444444666666666 | |
55555555555555555555555555555555555555444444444444444444444444444444446666666666 | |
55555555555555555555555555555555555555444444444444444444444444444444446666666666 | |
55555555555555555555555555555555555555444444444444444444444444444444466666666666 | |
55555555555555555555555555555555555555444444444444444444444444444444666666666666 | |
55555555555555555555555555555555555555444444444444444444444444444446666666666666 | |
55555555555555555555555555555555555555444444444444444444444444444446666666666666 | |
55555555555555555555555555555555555555444444444444444444444444444466666666666666 | |
55555555555555555555555555555555555555444444444444444444444444444666666666666666 | |
55555555555555555555555555555555555555444444444444444444444444446666666666666666 | |
55555555555555555555555555555555555555444444444444444444444444446666666666666666 | |
55555555555555555555555555555555555555444444444444444444444444466666666666666666 | |
55555555555555555555555555555555555555444444444444444444444444666666666666666666 | |
55555555555555555555555555555555555555444444444444444444444446666666666666666666 | |
55555555555555555555555555555555555555444444444444444444444446666666666666666666 | |
555555555555555555555555555555555555554444444444444444444444666666666666666 6666 | |
55555555555555555555555555555555555555444444444444444444444666666666666666666666 | |
55555555555555555555555555555555555555444444444444444444446666666666666666666666 | |
55555555555555555555555555555555555555444444444444444444446666666666666666666666 | |
55555555555555555555555555555555555555444444444444444444466666666666666666666666 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment