📝 More drawing
This commit is contained in:
@ -33,6 +33,7 @@ def drawHex(channel):
|
||||
for hexagon in hexList:
|
||||
d.polygon(hexagon, fill = 'white',outline='black')
|
||||
|
||||
# TESTING BOARD
|
||||
board = [ [ 0 for i in range(11) ] for j in range(11) ]
|
||||
board[0][0] = 1
|
||||
board[1][0] = 1
|
||||
@ -62,7 +63,38 @@ def drawHex(channel):
|
||||
im.save("board"+channel+".png")
|
||||
#im.save(filename="resources/games/hexBoards/board"+channel+".png")
|
||||
|
||||
def drawHexPlacement(channel,player,position):
|
||||
# Opens the image
|
||||
try:
|
||||
im = loadsomethingsomething("board"+channel+".png")
|
||||
except:
|
||||
logThis("Error loading board-image (error code 1541")
|
||||
# 'd' is a shortcut to drawing on the image
|
||||
d = ImageDraw.Draw(im,"RGBA")
|
||||
|
||||
CANVAS_WIDTH = 800
|
||||
CANVAS_HEIGHT = 600
|
||||
SIDELENGTH = 25
|
||||
X_OFFSET = CANVAS_WIDTH/2 - 8*math.sqrt(3)*SIDELENGTH # The offsets centers the board in the picture
|
||||
Y_OFFSET = CANVAS_HEIGHT/2 - 8*SIDELENGTH # The offsets are the coordinates of the upperleft point in the upperleftmost hexagon
|
||||
hexagonwidth = math.sqrt(3) * SIDELENGTH # the whole width
|
||||
hexagonheight = 1.5 * SIDELENGTH # not really the entire height, but the height difference between two layers
|
||||
pieceColor = {1:(200,0,0),2:(0,0,200)} # player1 is red, player2 is blue
|
||||
pieceDiameter = 30
|
||||
|
||||
# Translates position
|
||||
# We don't need to check, because the position is already checked in placeOnHexBoard()
|
||||
position = position.lower()
|
||||
column = ord(position[0])-97 # ord() translates from letter to number
|
||||
row = int(position[1])
|
||||
|
||||
# Draws the piece
|
||||
x = X_OFFSET + hexagonwidth*(column + row/2 + 1/2) - pieceDiameter/2
|
||||
y = Y_OFFSET + hexagonheight*row + hexagonheight/2 - pieceDiameter/math.sqrt(2)
|
||||
d.ellipse([(x,y),(x + pieceDiameter,y + pieceDiameter)], fill = pieceColor[player])
|
||||
|
||||
|
||||
|
||||
|
||||
def generate_unit_hexagons():
|
||||
h = math.sqrt(3)/2 # Half the width of the hexagon
|
||||
|
Reference in New Issue
Block a user