def _flip_image(self, num_sides):
images = {
Side.heads: self._heads_image,
Side.tails: self._tails_image,
}
stats = collections.Counter()
root = num_sides ** 0.5
height, width = round(root), int(math.ceil(root))
sides = (random.choices(SIDES, WEIGHTS)[0] for _ in range(num_sides))
size = self.image_size
image = Image.new('RGBA', (width * size, height * size))
for i, side in enumerate(sides):
y, x = divmod(i, width)
image.paste(images[side], (x * size, y * size))
stats[side] += 1
message = ' and '.join(pluralize(**{str(side)[:-1]: n}) for side, n in stats.items())
f = io.BytesIO()
image.save(f, 'png')
f.seek(0)
return message, discord.File(f, filename='flipcoins.png')
评论列表
文章目录