Effacer les filtres
Effacer les filtres

I am trying to create a puzzle type game that allows people to click on a portion of an image, click another image, then swap the two.

3 vues (au cours des 30 derniers jours)
Hello, I want to try to create a puzzle type game where I can allow the user to see the original image
as a figure 1, and then a figure 2 mixed image, and then have the person try to click and rearrange
the images. I already have a code that breaks the original image into a 3x3 random mix and
scrambles the image, I am just not sure how to code it to where someone can click on one of the
squares, then click on another one and swap the two to assemble the original image. The code I
have below only divides the original picture into a 3x3 mix.
initiation = menu('Would you like to take a mental health break and complete our puzzle?','Yes','No');
if initiation == 1
% First you need to load in the image you are trying to use and crop the
% image to match the dimensions desired
imageDATA = imread('puzzleIMAGE.jpg');
DIMENSIONSnew = size(imageDATA) - rem(size(imageDATA), 3);
imageDATA = imageDATA(1:DIMENSIONSnew(1),1:DIMENSIONSnew(2), :);
%You need to arrange the puzzle in the 3 x 3 dimensions
DIMENSIONSblocks = DIMENSIONSnew./[3 3 1];
blocks = mat2cell(imageDATA, DIMENSIONSblocks(1)*ones(3,1),
DIMENSIONSblocks(2)*ones(3,1), DIMENSIONSblocks(3));
% sort the 3 x 3 pieces randomly this will scramble the original image and
% give the puzzle effect
blocks(1:9) = blocks(randperm(9));
%%Set one block to zero
blocks(ceil(9*rand(1))) = {zeros(DIMENSIONSblocks, class(imageDATA))};
% return back the original images
puzzle = cell2mat(blocks);
%Plot the input image and plot the final scrambled output image
figure(1)
image(imageDATA)
figure(2)
image(puzzle)
end

Réponses (1)

Image Analyst
Image Analyst le 5 Avr 2022

Catégories

En savoir plus sur Number games dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by