#Hey guys, I am trying to create a puzzle
1 messages ยท Page 1 of 1 (latest)
For example, if Emoji are good enough for faces for you, the existing Python code and Python tool works, you can get any number of outputs like this:
using this code which you can copy/paste to the model:
import numpy as np
import random
# Define a set of emojis to use in the grid
emojis = ['๐', '๐', '๐', '๐', '๐', '๐
', '๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐']
# Function to create the grid with one pair of twins
def create_puzzle_grid(size=4):
# Randomly select (size*size - 1) unique emojis
selected_emojis = random.sample(emojis, size*size - 1)
# Duplicate one of the emojis to create the twin
twin = random.choice(selected_emojis)
selected_emojis.append(twin)
# Shuffle the list of emojis
random.shuffle(selected_emojis)
# Create the grid
grid = np.array(selected_emojis).reshape(size, size)
return grid
# Function to create and display a 4x4 emoji grid with square cell dimensions
def display_emoji_grid(size=4, font_size=30, scale_x=1.5, scale_y=5.0):
# Generate the puzzle grid with emojis
emoji_puzzle_grid = create_puzzle_grid()
# Display the grid
fig, ax = plt.subplots(figsize=(6, 6))
tb = plt.table(cellText=emoji_puzzle_grid, cellLoc='center', loc='center', edges='closed')
tb.auto_set_font_size(False)
tb.set_fontsize(font_size)
tb.scale(scale_x, scale_y)
ax.axis('off')
plt.show()
# Display the emoji grid with the final adjusted settings
display_emoji_grid()```
Actually, I would like to create a grid of objects, smileys, etc.
If you give the model an image of each object, smiley, and etc to use, it can make that grid for you.
You'd probably want to either give the images singly, or in an easy to separate fashion, like 4 quadrants of an uploaded image designed to be cut into quarters by its Python tool and handled 'as is' otherwise.
Here's one way to do it, I show you my inputs to the model:
[Lets explore your ability to cut this image into parts and manipulate the parts for our images.
We need 1 horizontal cut in the exact middle.
The 2 new pieces need 1 more horizontal cut in the exact middle.
The 4 new pieces need 1 vertical cut in the exact middle.
the 8 new pieces need 2 vertical cuts so they form exact thirds; we will have 24 pieces when done.
We will explore using 15 of these pieces in a game.]
[You did great!
Now, you've helped me with code that used 15 emoji and Python to make a grid with a single 'twin' image in it, can you adapt this code and use your Python tool to make the grid show our images? They may need sizes adjusted, but the goal is to display the grid with the images in it. Go ahead and use the first 15, and randomly twin one of them, randomly place all 16 including that 1 twin in the grid.
{in here is the code I pasted above to you}]
Here's what the model showed me:
I pasted that image in, then told it:
[You did awesome!!!!
Now, can we get 'gridlines' that show between the smilies? Here's what I see right now, maybe the images were drawn over the gridlines so we can't see them]
# Adjusting the approach to create a grid of PIL images
import matplotlib.pyplot as plt
import numpy as np
import random
from PIL import Image
# Load the images
image_paths = [
"/mnt/data/piece_1.png", "/mnt/data/piece_2.png", "/mnt/data/piece_3.png",
"/mnt/data/piece_4.png", "/mnt/data/piece_5.png", "/mnt/data/piece_6.png",
"/mnt/data/piece_7.png", "/mnt/data/piece_8.png", "/mnt/data/piece_9.png",
"/mnt/data/piece_10.png", "/mnt/data/piece_11.png", "/mnt/data/piece_12.png",
"/mnt/data/piece_13.png", "/mnt/data/piece_14.png", "/mnt/data/piece_15.png"
]
# Load images into a list
images = [Image.open(path) for path in image_paths]
# Resize images to a consistent size
image_size = (100, 100)
resized_images = [img.resize(image_size) for img in images]
# Add a twin image
twin_index = random.randint(0, len(resized_images) - 1)
resized_images.append(resized_images[twin_index])
# Shuffle the images
random.shuffle(resized_images)
# Create the grid as a list of lists
grid_size = 4
grid_images = [resized_images[i * grid_size:(i + 1) * grid_size] for i in range(grid_size)]
# Function to display the image grid with visible gridlines
def display_image_grid_with_gridlines(grid_images, grid_size=4):
fig, axs = plt.subplots(grid_size, grid_size, figsize=(8, 8))
for i in range(grid_size):
for j in range(grid_size):
axs[i, j].imshow(grid_images[i][j])
axs[i, j].axis('on')
axs[i, j].set_xticks([])
axs[i, j].set_yticks([])
for spine in axs[i, j].spines.values():
spine.set_edgecolor('black')
spine.set_linewidth(2)
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
# Display the image grid with gridlines
display_image_grid_with_gridlines(grid_images)
# Display the image grid
display_image_grid(grid_images)```
Now, that won't exactly work in your own code-running program, because the image locations are not where they'd be on your computer; there may be a few other issues too.
But that worked for the model and you can follow this format with your own image(s) to guide the model how to cut and process them, then use this code as an example how to format the images for your need.
you can also describe any other changes you want to the grid and format, be it a different color background.
Just know that the model cannot see what it makes, you would have to copy/paste the image into the conversation in order to adjust for that.
Like, if you wanted to show the model what it did, or explain a difference with visual information too - the model cannot see what it makes for us without us pasting it back in.