Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

jigsaw puzzle

goldokhtargoldokhtar Member Posts: 4
hi
i have a graphic picture ,,,,how can i cut into pieces for the jigsaw puzzle?? i know that i have to put in a 5*5 array...but how???

Comments

  • Phat NatPhat Nat Member Posts: 757
    [b][red]This message was edited by Phat Nat at 2007-2-10 0:29:19[/red][/b][hr]
    : hi
    : i have a graphic picture ,,,,how can i cut into pieces for the jigsaw puzzle?? i know that i have to put in a 5*5 array...but how???
    :

    If you put your picture into an array, then you can just use a second array to track the start and end points of each tile.
    or just use math to do it.

    If your picture is 20x20 pixels, then just divide the height by the number of desired tiles. In this case, 4. Same with width, so each tile is 4x4.

    So, you can just make an array[0..4,0..4] of BYTE and put the tile numbers in the array: (eg.)
    [03,18,07,12,21]
    [25,05,20,01,10]
    [13,17,02,15,08]
    [16,06,09,14,22]
    [24,04,23,11,19]

    So now, you can draw all the tiles in the mixed up order like so:
    [code]
    CONST
    TileCountX = 5;
    TileCountY = 5;
    TileWidth = 4;
    TileHeight = 4;

    TileArrangement : Array[1..TileCountX,1..TileCountY] Of Byte =
    ((03,18,07,12,21),
    (25,05,20,01,10),
    (13,17,02,15,08),
    (16,06,09,14,22),
    (24,04,23,11,19));


    VAR
    PictureArray[1..TileCountX*TileWidth, 1..TileCountY*TileHeight] Of Byte;

    Begin
    For TileNumX := 0 to TileCountX-1 Do
    For TileNumY := 0 to TileCountY-1 Do
    Begin
    TileNum := TileArrangement[TileNumX,TileNumY];
    For X := 1 to TileWidth do
    For Y := 1 to TileHeight do
    PutPixel(TileNumX*TileWidth + X,TileNumY*TileHeight + Y,PictureArray[TileNum DIV TileCountX + X, TileNum MOD TileCountY + Y]);
    End;
    End.
    [/code]

    Something close to this anyways. This isn't tested. You get the idea though hopefully. Just load your picture into the PictureArray.

    Instead of a constant for the TileArrangement, it would be simple to make it randomly arranged each time. and then you could quickly change the tile sizes, etc as well.

    Phat Nat

Sign In or Register to comment.