You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB
Python

# generate random ID for the pieces
from shortuuid import uuid
# to draw the background
from wand.image import Image
from wand.drawing import Drawing
# rows and columns for the puzzle
rows = 10
columns = 15
# resolution for the print
dpi = 300
# width and height in cm
image_width = 15
image_height = 10
# name of the puzzle to be more legible?
name = "katamari"
# width and height in pixel
width = int(dpi / 2.54 * image_width)
height = int(dpi / 2.54 * image_height)
# piece sizes in pixel
piece_width = width / rows
piece_height = height / columns
pieces = []
with Image(width=width, height=height) as img:
draw = Drawing()
draw.font_size = 11
draw.text_alignment = "center"
for x in range(rows):
row = []
for y in range(columns):
# generate a random ID for each piece
ID = uuid()[:4]
# write the id in the center of each piece
draw.text(
int(x * piece_width + piece_width / 2),
int(y * piece_height + piece_height / 2),
f"{name}\n{ID}",
)
# store the id in the pieces dictionary
row.append(ID)
pieces.append(row)
draw(img)
img.save(filename=f"chaospuzzles/puzzles/{name}/retro.png")
print("Done!")
def adjacents():
adjacents = {}
for x in range(rows):
for y in range(columns):
current = pieces[x][y]
if y > 0:
n = pieces[x][y - 1]
else:
n = None
if y < columns - 1:
s = pieces[x][y + 1]
else:
s = None
if x > 0:
w = pieces[x - 1][y]
else:
w = None
if x < rows - 1:
e = pieces[x + 1][y]
else:
e = None
adjacents[current] = (n, e, s, w)
return adjacents