✨ Constants
This commit is contained in:
@ -14,14 +14,14 @@ def drawBoard(channel):
|
||||
SIDELENGTH = 75
|
||||
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 of one hexagon
|
||||
hexagonheight = 1.5 * SIDELENGTH # not really the entire height, but the height difference between two layers
|
||||
fontsize = 45
|
||||
textcolor = (0,0,0)
|
||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', fontsize)
|
||||
hexThickness = 6
|
||||
xThickness = hexThickness * math.cos(math.pi/6)
|
||||
yThickness = hexThickness * math.sin(math.pi/6)
|
||||
HEXAGONWIDTH = math.sqrt(3) * SIDELENGTH # the whole width of one hexagon
|
||||
HEXAGONHEIGHT = 1.5 * SIDELENGTH # not really the entire height, but the height difference between two layers
|
||||
FONTSIZE = 45
|
||||
TEXTCOLOR = (0,0,0)
|
||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', FONTSIZE)
|
||||
HEXTHICKNESS = 6
|
||||
X_THICKNESS = HEXTHICKNESS * math.cos(math.pi/6)
|
||||
Y_THICKNESS = HEXTHICKNESS * math.sin(math.pi/6)
|
||||
|
||||
# Creates the empty image
|
||||
im = Image.new('RGB', size=(CANVAS_WIDTH, CANVAS_HEIGHT),color='lightgrey')
|
||||
@ -29,7 +29,7 @@ def drawBoard(channel):
|
||||
d = ImageDraw.Draw(im,"RGBA")
|
||||
|
||||
# These are the coordinates for the upperleft corner of every hex
|
||||
boardCoordinates = [ [(X_OFFSET + hexagonwidth*(column + row/2),Y_OFFSET + hexagonheight*row) for column in range(11)] for row in range(11)]
|
||||
boardCoordinates = [ [(X_OFFSET + HEXAGONWIDTH*(column + row/2),Y_OFFSET + HEXAGONHEIGHT*row) for column in range(11)] for row in range(11)]
|
||||
# The board is indexed with [row][column]
|
||||
for column in boardCoordinates:
|
||||
for startingPoint in column:
|
||||
@ -45,12 +45,12 @@ def drawBoard(channel):
|
||||
(x, y+SIDELENGTH),
|
||||
],fill="black")
|
||||
d.polygon([
|
||||
(x+xThickness, y + yThickness),
|
||||
(x+h, y-0.5*SIDELENGTH + hexThickness),
|
||||
(x+2*h-xThickness, y + yThickness),
|
||||
(x+2*h-xThickness, y+SIDELENGTH - yThickness),
|
||||
(x+h, y+1.5*SIDELENGTH - hexThickness),
|
||||
(x+xThickness, y+SIDELENGTH - yThickness),
|
||||
(x+X_THICKNESS, y + Y_THICKNESS),
|
||||
(x+h, y-0.5*SIDELENGTH + HEXTHICKNESS),
|
||||
(x+2*h-X_THICKNESS, y + Y_THICKNESS),
|
||||
(x+2*h-X_THICKNESS, y+SIDELENGTH - Y_THICKNESS),
|
||||
(x+h, y+1.5*SIDELENGTH - HEXTHICKNESS),
|
||||
(x+X_THICKNESS, y+SIDELENGTH - Y_THICKNESS),
|
||||
],fill="white")
|
||||
|
||||
# Draw color on the outside of the board
|
||||
@ -60,13 +60,13 @@ def drawBoard(channel):
|
||||
# Writes "abc..", "123.." on the columns and rows
|
||||
for i in range(11):
|
||||
# Top letters
|
||||
d.text( (X_OFFSET + hexagonwidth*i, Y_OFFSET-66) , "ABCDEFGHIJK"[i], font=fnt, fill=textcolor)
|
||||
d.text( (X_OFFSET + HEXAGONWIDTH*i, Y_OFFSET-66) , "ABCDEFGHIJK"[i], font=fnt, fill=TEXTCOLOR)
|
||||
# Bottom letters
|
||||
d.text( (X_OFFSET + hexagonwidth*(i+11.5/2), Y_OFFSET - 15 + 11*hexagonheight) , "ABCDEFGHIJK"[i], font=fnt, fill=textcolor)
|
||||
d.text( (X_OFFSET + HEXAGONWIDTH*(i+11.5/2), Y_OFFSET - 15 + 11*HEXAGONHEIGHT) , "ABCDEFGHIJK"[i], font=fnt, fill=TEXTCOLOR)
|
||||
# Left numbers
|
||||
d.multiline_text( (X_OFFSET + hexagonwidth*i/2 - 72 -4*(i>8), Y_OFFSET + 18 + i*hexagonheight) , str(i+1), font=fnt, fill=textcolor, align="right")
|
||||
d.multiline_text( (X_OFFSET + HEXAGONWIDTH*i/2 - 72 -4*(i>8), Y_OFFSET + 18 + i*HEXAGONHEIGHT) , str(i+1), font=fnt, fill=TEXTCOLOR, align="right")
|
||||
# Right numbers
|
||||
d.text( (X_OFFSET + hexagonwidth*(i/2+11) + 30 , Y_OFFSET + 6 + i*hexagonheight) , str(i+1), font=fnt, fill=textcolor)
|
||||
d.text( (X_OFFSET + HEXAGONWIDTH*(i/2+11) + 30 , Y_OFFSET + 6 + i*HEXAGONHEIGHT) , str(i+1), font=fnt, fill=TEXTCOLOR)
|
||||
|
||||
im.save("board"+channel+".png")
|
||||
#im.save("resources/games/hexBoards/board"+channel+".png")
|
||||
@ -81,8 +81,8 @@ def drawHexPlacement(channel,player,position):
|
||||
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
|
||||
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
|
||||
|
||||
@ -93,8 +93,8 @@ def drawHexPlacement(channel,player,position):
|
||||
row = int(position[1])-1
|
||||
|
||||
# Find the coordinates for the piece-drawing
|
||||
x = X_OFFSET + hexagonwidth*(column + row/2 + 1/2) - pieceDiameter/2
|
||||
y = Y_OFFSET + hexagonheight*row + hexagonheight/2 - pieceDiameter/math.sqrt(2)
|
||||
x = X_OFFSET + HEXAGONWIDTH*(column + row/2 + 1/2) - pieceDiameter/2
|
||||
y = Y_OFFSET + HEXAGONHEIGHT*row + HEXAGONHEIGHT/2 - pieceDiameter/math.sqrt(2)
|
||||
|
||||
# Opens the image
|
||||
#logThis("Finding and opening the board-image at hex"+channel+".png")
|
||||
|
Reference in New Issue
Block a user