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