Created
November 3, 2020 10:03
-
-
Save sizumita/e08f6c3c604b9d327f924d3a206c8456 to your computer and use it in GitHub Desktop.
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 matplotlib.pyplot as plt | |
import random | |
import numpy as np | |
import itertools | |
from matplotlib.patches import RegularPolygon, Circle | |
CITY_COUNT = 10 | |
width = 16 | |
height = 16 | |
# ここからパクリ(ポリゴンどう使うのかわからん) | |
coord = [] | |
for x in range(0, width): | |
for y in range(0, height, 2): | |
if x % 2: | |
y += 1 | |
coord.append([x, y, 0]) | |
# Horizontal cartesian coords | |
hcoord = [c[0] for c in coord] | |
# Vertical cartersian coords | |
vcoord = [2. * np.sin(np.radians(60)) * (c[1] - c[2]) / 3. for c in coord] | |
fig, ax = plt.subplots(1) | |
ax.set_aspect('equal') | |
hexagons = [] | |
# Add some coloured hexagons | |
for x, y in zip(hcoord, vcoord): | |
hex = RegularPolygon((x, y), numVertices=6, radius=2. / 3., | |
orientation=np.radians(30), | |
facecolor='white', alpha=0.2, edgecolor='k') | |
ax.add_patch(hex) | |
hexagons.append((x, y + 0.2)) | |
# Also add a text label | |
# ax.text(x, y+0.2, l[0]+'abc', ha='center', va='center', size=20) | |
# Also add scatter points in hexagon centres | |
ax.scatter(hcoord, vcoord, c=['white' for _ in coord], alpha=0.5) | |
cities = [] | |
for i in random.sample(hexagons, CITY_COUNT): | |
l = list(i) | |
n = random.choice(list('ABCDEFG')) | |
l.append(n) | |
ax.text(l[0], l[1]-0.5, n, ha='center', va='center', size=10) | |
cities.append(l) | |
c = Circle(xy=(l[0], l[1]-0.2), radius=0.1, fill='blue') | |
ax.add_patch(c) | |
# 戦争 | |
for lhs, rhs in itertools.combinations(cities, 2): | |
a = np.array([lhs[0], lhs[1]]) | |
b = np.array([rhs[0], rhs[1]]) | |
diff = np.linalg.norm(b - a) | |
if int(diff) <= 3: | |
c = Circle(xy=(lhs[0], lhs[1]-0.2), radius=0.45, fill=False, ec='#FFCC00', linewidth=3) | |
c2 = Circle(xy=(lhs[0], lhs[1]-0.2), radius=0.45, fill=False, ec='#FFCC00', linewidth=3) | |
ax.add_patch(c) | |
ax.add_patch(c2) | |
# 疫病 | |
target = random.choice(cities) | |
c = Circle(xy=(target[0], target[1]-0.2), radius=0.45, fill=False, ec='red', linewidth=3) | |
ax.add_patch(c) | |
# 交易路 | |
# うんち〜w | |
if __name__ == '__main__': | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment