カタン、Pythonでは?―― 正六角形19個を並べる
正六角形の、一つの頂点の位置から、他の5つの頂点の位置の計算ができたので、今度は19個の頂点を一気に計算し、描画してみる。できるかな。
import numpy as np
import pygame
# 長すぎるので、t1に頂点19個の位置を入れるところまでは省略
t3 = np.array([[[0, 0], [-17.32, 10.00], [-17.32, 30.00], [0.00, 40.00],[17.32, 30.00],[17.32, 10.00]]])
t4 = np.arange(12).reshape(1,6,2)
for t0b in t1:
t0c = t0b + t3
t4 = np.append(t4, t0c, axis = 0)
t4 = np.delete(t4,0,0)
pygame.init()
screen = pygame.display.set_mode
black = (0, 0, 0)
blue = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode*1
myclock = pygame.time.Clock()
screen.fill(black)
for hec in t4:
pygame.draw.polygon(screen, blue, hec)
pygame.display.flip()
endflag = 0
while endflag ==0:
for event in pygame.event.get():
if event.type == pygame.QUIT: endflag = 1
myclock.tick(60)
pygame.quit()
結果
無意味に長い部分が沢山ある。もっと簡略化できるはずだが、ともあれ、六角形が19個できた。塗りつぶしていると分かりづらいので、枠だけにしてみる。
下の方で、
pygame.draw.polygon(screen, blue, hec)
を
pygame.draw.polygon(screen, blue, hec, 5)
とすればいい。
とりあえず、できた。よしよし。
*1:640, 480