Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!

# How to chop image into blocks for assembly puzzle?

sean cronin
Ranch Hand
Posts: 38
Didn't really know how I'd describe this in the title, but if you've ever played a room escape game, I'm looking to take a picture, break
it into chunks, then when a user clicks on a piece it will rotate 90 degrees each time and this will be done for all chunks until the picture
is assembled. The image below shows what I mean.

In this image a piece of the puzzle is missing, which mine won't. So as you can see by rotating each block you recreate the image.

How can I do this with java? It's part of an android project I'm working.

Thanks.

Giovanni Montano
Ranch Hand
Posts: 250
4
sean cronin wrote:Didn't really know how I'd describe this in the title, but if you've ever played a room escape game, I'm looking to take a picture, break
it into chunks, then when a user clicks on a piece it will rotate 90 degrees each time and this will be done for all chunks until the picture
is assembled. The image below shows what I mean.

In this image a piece of the puzzle is missing, which mine won't. So as you can see by rotating each block you recreate the image.

How can I do this with java? It's part of an android project I'm working.

Thanks.

you want to look at Matrix

Les Morgan
Rancher
Posts: 711
17
Sean,

It's all done with math, simple math.  You look at your picture and decided how many blocks you want to cut it into, your using a 2D grid, so how many rows and how many columns do you want to have? The next thing you have to look at, is if your picture divisible evenly by the numbers you chose? If you have a 1024x768 image and you want to cut it into a 20x20 grid, then you'll have 51 pixels across and 32 pixels high for each tile (picture for each grid). That gives us 1020x760 for the image that can be used in that grid--what do you want to do with the extra 4 pixels on the original width and 8 pixels on the original height?

The next thing you need to figure out is how do you want to allow the tiles to be moved? You said yours will not have an empty tile, so how are you going to move the tiles--what rules govern that?

Once you make those decisions, then you can start to work a little more on the coding of the project.

Les

sean cronin
Ranch Hand
Posts: 38
Les Morgan wrote:Sean,

It's all done with math, simple math.  You look at your picture and decided how many blocks you want to cut it into, your using a 2D grid, so how many rows and how many columns do you want to have? The next thing you have to look at, is if your picture divisible evenly by the numbers you chose? If you have a 1024x768 image and you want to cut it into a 20x20 grid, then you'll have 51 pixels across and 32 pixels high for each tile (picture for each grid). That gives us 1020x760 for the image that can be used in that grid--what do you want to do with the extra 4 pixels on the original width and 8 pixels on the original height?

The next thing you need to figure out is how do you want to allow the tiles to be moved? You said yours will not have an empty tile, so how are you going to move the tiles--what rules govern that?

Once you make those decisions, then you can start to work a little more on the coding of the project.

Les

Thanks Les, I must have a crack off this tonight or tomorrow. You kind of described how I was feeling it should be done, so should be fun trying to figure this out