test split to pieces

Co-authored-by: grgrce <grgrce@users.noreply.github.com>
master
km0 3 years ago
parent f0e3510341
commit 4054257698

@ -23,7 +23,6 @@ def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY="dev",
# DATABASE=os.path.join(app.instance_path, 'puzzles'),
)
if test_config is None:
@ -43,6 +42,6 @@ def create_app(test_config=None):
app.register_blueprint(puzzle.bp)
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix="/soupboat/chaospuzzles")
# app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix="/soupboat/chaospuzzles")
return app

@ -0,0 +1,90 @@
# 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

@ -2,6 +2,8 @@
"name": "katamari",
"rows": 10,
"columns": 15,
"width": 1280,
"height": 720,
"image": "katamari.jpg",
"clusters": []
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 KiB

@ -0,0 +1,34 @@
from wand.image import Image
from math import floor
import os
def split(image, name, output, width, height, rows, columns):
try:
os.makedirs(output)
except OSError:
pass
piece_width = floor(width / columns)
piece_height = floor(height / rows)
with Image(filename=image) as img:
for y in range(0, columns):
for x in range(0, rows):
x_start = x * piece_width
y_start = y * piece_height
x_end = x_start + piece_width
y_end = y_start + piece_height
with img[x_start:x_end, y_start:y_end] as piece:
piece.save(filename=f"{output}/{name}-{x}-{y}.jpg")
split(
"chaospuzzles/puzzles/katamari/katamari.jpg",
"katamari",
"chaospuzzles/static/puzzles/katamari/pieces",
3368,
2380,
10,
14,
)

@ -8,6 +8,17 @@
</head>
<body>
<h1>{{puzzle}}</h1>
{{rows}}, {{columns}}, {{clusters}}
<div>
{% for column in range(columns) %} {% for row in range(rows) %}
<img
src="{{url_for('static', filename='puzzles/' + puzzle + '/pieces/'+ puzzle + '-' +
row|string + '-' + column|string + '.jpg')}}"
/>
{%endfor%}
<br />
{% endfor %}
</div>
</body>
</html>

@ -1,13 +1,10 @@
from setuptools import find_packages, setup
setup(
name='Chaos Puzzles',
version='1.0.0',
name="Chaos Puzzles",
version="1.0.0",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=[
'flask',
'shortuuid'
],
install_requires=["flask", "shortuuid", "wand"],
)

Loading…
Cancel
Save