カタン、Pythonでは?―― 改めて、トークンの位置
pygameで図形を描く時、 polygon ではfloatでもできたのに、circle だとinteger しかダメなのか。不思議だが、改めて確認してみる。
import numpy as np import pygame tile12 = np.load('tileA.npy') tile2 = np.loadtxt(fname='dataC.csv', dtype=float, delimiter=",", skiprows=1) tt26 = np.array([[534, 260], [603, 260], [673, 260], [500, 320], [569, 320], [638, 320]]) gray = (237, 237, 237) red = (255, 0, 0) pygame.init() screen = pygame.display.set_mode((1280, 720)) myclock = pygame.time.Clock() screen.fill(gray) for tok2 in tt26: pygame.draw.circle(screen, red, tok2, 20) 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()
これならうまく行く。
しょうがない。円を置く位置を整数で指定しよう。19X2のリストぐらい、手で売っても大した手間ではないのだが、ここは意地でpythonに計算させたい。
まずは力づくでやってみよう。intでできるのかな。
import numpy as np tile12 = np.load('tileA.npy') tt24 = np.array([0,60]) tt25 = tile12[:,0,:] tt26 = tt25+tt24 tt27 = int(tt26) print(tt27)
できなかった。普通に、エラー。
TypeError: only size-1 arrays can be converted to Python scalars
1次元ならできるのかな?1次元にしてみよう。
import numpy as np tile12 = np.load('tileA.npy') tt24 = np.array([0,60]) tt25 = tile12[:,0,:] tt26 = tt25+tt24 tt27 = tt26.flatten() print(tt27)
1次元になった。では、やってみよう。
import numpy as np tile12 = np.load('tileA.npy') tt24 = np.array([0,60]) tt25 = tile12[:,0,:] tt26 = tt25+tt24 tt27 = tt26.flatten() print(tt27) tt28 = int(tt27) print(tt28)
TypeError: only size-1 arrays can be converted to Python scalars
やっぱり同じエラー。
整数か小数か、1次元か2次元か、ちょっと違っただけで動かなくなる。つかえねえ、、、。