🎨
This commit is contained in:
@ -11,8 +11,9 @@ def hangmanStart(channel,user):
|
|||||||
with urllib.request.urlopen("https://random-word-api.herokuapp.com/word?number=10") as p:
|
with urllib.request.urlopen("https://random-word-api.herokuapp.com/word?number=10") as p:
|
||||||
words = json.load(p)
|
words = json.load(p)
|
||||||
word = list(random.choice(words).upper())
|
word = list(random.choice(words).upper())
|
||||||
|
guessed = [False] * len(word)
|
||||||
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
data[channel] = {"player" : user,"guessed letters" : [],"word" : word,"game ID" : gameID}
|
data[channel] = {"player" : user,"guessed letters" : [],"word" : word,"game ID" : gameID,"misses" : 0,"guessed" : guessed}
|
||||||
|
|
||||||
remainingLetters = list(string.ascii_uppercase)
|
remainingLetters = list(string.ascii_uppercase)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import math, random
|
import math, random, json
|
||||||
|
|
||||||
from PIL import ImageDraw, Image, ImageFont
|
from PIL import ImageDraw, Image, ImageFont
|
||||||
from funcs import logThis
|
from funcs import logThis
|
||||||
@ -14,8 +14,11 @@ armPosition = 200
|
|||||||
manx = (limbSize*2)+lineWidth*4
|
manx = (limbSize*2)+lineWidth*4
|
||||||
many = (circleSize+bodySize+limbSize)+lineWidth*4
|
many = (circleSize+bodySize+limbSize)+lineWidth*4
|
||||||
|
|
||||||
letterSize = 200
|
letterSize = 250
|
||||||
textSize = 50
|
textSize = 70
|
||||||
|
|
||||||
|
letterLineLength = 300
|
||||||
|
letterLineDistance = 100
|
||||||
|
|
||||||
gallowx, gallowy = 1200,2000
|
gallowx, gallowy = 1200,2000
|
||||||
goldenRatio = 1-(1 / ((1 + 5 ** 0.5) / 2))
|
goldenRatio = 1-(1 / ((1 + 5 ** 0.5) / 2))
|
||||||
@ -164,7 +167,12 @@ def drawGallows():
|
|||||||
return background
|
return background
|
||||||
|
|
||||||
def drawImage(channel):
|
def drawImage(channel):
|
||||||
background = Image.new("RGBA",(1920,1080),color=backgroundColor)
|
with open("resources/games/hangmanGames.json", "r") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
random.seed(data[channel]["game ID"])
|
||||||
|
|
||||||
|
background = Image.new("RGBA",(1600,1000),color=backgroundColor)
|
||||||
try:
|
try:
|
||||||
gallow = drawGallows()
|
gallow = drawGallows()
|
||||||
except:
|
except:
|
||||||
@ -173,7 +181,7 @@ def drawImage(channel):
|
|||||||
gallow = gallow.resize((smolGallowx,smolGallowy))
|
gallow = gallow.resize((smolGallowx,smolGallowy))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
man = drawMan(6)
|
man = drawMan(data[channel]["misses"])
|
||||||
except:
|
except:
|
||||||
logThis("Error drawing stick figure (error code 1712)")
|
logThis("Error drawing stick figure (error code 1712)")
|
||||||
|
|
||||||
@ -185,4 +193,22 @@ def drawImage(channel):
|
|||||||
background.paste(gallow,(100,100),gallow)
|
background.paste(gallow,(100,100),gallow)
|
||||||
background.paste(man,(280,210),man)
|
background.paste(man,(280,210),man)
|
||||||
|
|
||||||
|
letterLines = Image.new("RGBA",((letterLineLength+letterLineDistance)*len(data[channel]["word"]),300+lineWidth*3),color=(0,0,0,0))
|
||||||
|
for x, letter in enumerate(data[channel]["word"]):
|
||||||
|
line = badLine(letterLineLength,True)
|
||||||
|
letterLines.paste(line,(x*(letterLineLength+letterLineDistance),300),line)
|
||||||
|
if data[channel]["guessed"][x]:
|
||||||
|
letterDrawing = badText(letter,True)
|
||||||
|
letterWidth = fnt.getsize(letter)[0]
|
||||||
|
letterx = int(x*(letterLineLength+letterLineDistance)-(letterWidth/2)+(letterLineLength*0.5)+(lineWidth*2))
|
||||||
|
letterLines.paste(letterDrawing,(letterx,0),letterDrawing)
|
||||||
|
|
||||||
|
llw, llh = letterLines.size
|
||||||
|
letterLines = letterLines.resize((int(llw*(3/10)),int(llh*(3/10))))
|
||||||
|
|
||||||
|
background.paste(letterLines,(120,860),letterLines)
|
||||||
|
|
||||||
|
d = ImageDraw.Draw(background,"RGBA")
|
||||||
|
d.text((850,50),"Misses",font=smolfnt,fill=(0,0,0,255))
|
||||||
|
|
||||||
background.save("resources/games/hangmanBoards/hangmanBoard"+channel+".png")
|
background.save("resources/games/hangmanBoards/hangmanBoard"+channel+".png")
|
||||||
|
Reference in New Issue
Block a user