🎨 Drawing stuff
This commit is contained in:
@ -1,13 +1,18 @@
|
||||
import json
|
||||
import json, random
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
border = 100
|
||||
placement = [0,0]
|
||||
rotation = 0
|
||||
|
||||
def drawImage(channel):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', 50)
|
||||
fntSmol = ImageFont.truetype('resources/futura-bold.ttf', 40)
|
||||
borderSmol = int(border/3.5)
|
||||
|
||||
table = Image.open("resources/games/blackjackTable.png")
|
||||
placement = [2,1,3,0,4]
|
||||
@ -22,18 +27,18 @@ def drawImage(channel):
|
||||
else:
|
||||
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],False,dealerBusted,dealerBlackjack)
|
||||
|
||||
table.paste(dealerHand,(800,20),dealerHand)
|
||||
table.paste(dealerHand,(800-borderSmol,20-borderSmol),dealerHand)
|
||||
|
||||
for x in range(len(hands)):
|
||||
key, value = list(hands.items())[x]
|
||||
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
||||
|
||||
if value["split"]:
|
||||
table.paste(userHand,(32+(384*placement[x]),560),userHand)
|
||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
|
||||
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
||||
table.paste(userOtherHand,(32+(384*placement[x]),700),userOtherHand)
|
||||
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
||||
else:
|
||||
table.paste(userHand,(32+(384*placement[x]),680),userHand)
|
||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),680-borderSmol),userHand)
|
||||
|
||||
textWidth = fnt.getsize(key)[0]
|
||||
if textWidth < 360:
|
||||
@ -58,21 +63,30 @@ def drawHand(hand, dealer, busted, blackjack):
|
||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
|
||||
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
|
||||
length = len(hand)
|
||||
background = Image.new("RGBA", (691+(125*(length-1)),1065),(0,0,0,0))
|
||||
background = Image.new("RGBA", ((border*2)+691+(125*(length-1)),(border*2)+1065),(0,0,0,0))
|
||||
textImage = ImageDraw.Draw(background)
|
||||
|
||||
if dealer:
|
||||
img = Image.open("resources/games/cards/"+hand[0].upper()+".png")
|
||||
background.paste(img,(0,0),img)
|
||||
#rotation = (random.randint(-20,20)/10.0)
|
||||
img = img.rotate(rotation,expand = 1)
|
||||
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||
background.paste(img,(border+placement[0],border+placement[1]),img)
|
||||
img = Image.open("resources/games/cards/red_back.png")
|
||||
background.paste(img,(125,0),img)
|
||||
#rotation = (random.randint(-20,20)/10.0)
|
||||
img = img.rotate(rotation,expand = 1)
|
||||
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||
background.paste(img,(125+border+placement[0],border+placement[1]),img)
|
||||
else:
|
||||
for x in range(length):
|
||||
img = Image.open("resources/games/cards/"+hand[x].upper()+".png")
|
||||
background.paste(img,(x*125,0),img)
|
||||
#rotation = (random.randint(-20,20)/10.0)
|
||||
img = img.rotate(rotation,expand = 1)
|
||||
#placement = [random.randint(-20,20),random.randint(-20,20)]
|
||||
background.paste(img,(border+(x*125)+placement[0],border+placement[1]),img)
|
||||
|
||||
w, h = background.size
|
||||
textHeight = 290
|
||||
textHeight = 390+border
|
||||
|
||||
if busted:
|
||||
textWidth = fnt.getsize("BUSTED")[0]
|
||||
|
Reference in New Issue
Block a user