Page 5 of 5
Re: cutting irregular pieces from image for puzzle game
Posted: Fri Jul 11, 2025 9:49 am
by bn
I think it is due to the fact that the folder does not exist. It is not automatically created.
Here is what worked for me on a Mac.
Code: Select all
on mouseUp
put the number of images of this card into nImages
put specialFolderPath("documents") & "/app data/testing/tempImages" into tTempPath
set the itemDelimiter to slash
put itemOffset("Documents",tTempPath) into tOffset
put item 1 to tOffset of tTempPath into tRootPath
repeat with i = tOffset +1 to the number of items of tTempPath
if there is not a folder (item 1 to i of tTempPath) then
create folder (item 1 to i of tTempPath)
put the result into tResult
if tResult is not empty then breakpoint
end if
end repeat
set the itemDelimiter to comma
repeat with i = 1 to 1 -- nImages ## changed for testing
put the short name of image i into tImageFileName
put tTempPath & "/" & the short name of image i & ".png" into tFilePath
export image tImageFileName to file tFilePath as PNG
put the result into tResult
end repeat
end mouseUp
It first checks for the existence of a folder, if it not exists then it creates the folder(s) and only then exports the images to that folder.
Checking for the result after creating a folder makes sure that it worked. If successful the result is empty.
Kind regards
Bernd
Re: cutting irregular pieces from image for puzzle game
Posted: Fri Jul 11, 2025 10:05 pm
by rcmills
Thanks again! Even though I "thought" I had created the proper folders, going through the process of checking on them somehow fixed the problem!
Re: cutting irregular pieces from image for puzzle game
Posted: Wed Jul 16, 2025 8:55 pm
by bn
I made a script that arranges the Puzzle Pieces in correct order and position.
Consider it a "cheat" script or a final arrangement script since manual placement of puzzle pieces is difficult.
Code: Select all
on mouseUp
local tMaxColNum, tMaxRowNum, tNumPieces
local tCollect, tShortImgName, tExpectedNumPieces, tStartTL, tStartLeft, tStartTop
local tPieceSize = 60, tPuzzleWidth, tPuzzleHeight
local tImgColumn, tImgRow, tFudge, tTempLeft, tTempTop
repeat with i = 1 to the number of images
put the short name of image i into tShortImgName
if tShortImgName begins with "PP" then
put tShortImgName & return after tCollect
put max(char 3 to -1 of item 1 of tShortImgName, tMaxColNum) into tMaxColNum
put max(char 1 to -1 of item 2 of tShortImgName, tMaxRowNum) into tMaxRowNum
end if
end repeat
delete char -1 of tCollect
if tCollect is empty then
answer "No Puzzle Pieces found"
exit mouseUp
end if
put tMaxColNum * tMaxRowNum into tExpectedNumPieces
## check for number of Puzzle Pieces and bail out if there are too few or too many
if the number of lines of tCollect <> tExpectedNumPieces then
answer "Not all or too many Puzzle Pieces found"
exit mouseUp
end if
## format of name is "PP" & column & comma & row
## this sorts the images by column and then by row
## PP1,1; PP2,1 etc
## PP1,2; PP2,2 etc
sort tCollect numeric by char 3 to -1 of item 1 of each
sort tCollect numeric by char 1 to -1 of item 2 of each
put the topLeft of image line 1 of tCollect into tStartTL
put item 1 of tStartTL into tStartLeft
put item 2 of tStartTL into tStartTop
## check for space to arrange Puzzle Pieces; otherwise they could be placed beyond the card boundaries
if tStartLeft + (tMaxColNum * tPieceSize) > the width of this card or \
tStartTop + (tMaxRowNum * tPieceSize) > the height of this card then
answer "Place top-left Puzzle Piece near the top left of the card"
exit mouseUp
end if
repeat for each line anImage in tCollect
put char 3 to -1 of item 1 of anImage into tImgColumn
put char 1 to -1 of item 2 of anImage into tImgRow
put the uMarginFudge of image anImage into tFudge
put tStartLeft + ((tImgColumn - 1) * tPieceSize) into tTempLeft
put tStartTop + ((tImgRow -1) * tPieceSize) into tTempTop
put tTempLeft - item 1 of tFudge into tTempLeft
put tTempTop - item 2 of tFudge into tTempTop
set the topLeft of image anImage to tTempLeft, tTempTop
end repeat
end mouseUp
use this script in a button on a card that contains all the pieces of one puzzle. Not more not less.
Kind regards
Bernd
PS if you are still using the outerglow for the script of the puzzle pieces when they are move by the mouse then I changed "outerglow" to "innerglow" because the outerglow overlaps the neighboring pieces whereas "innerglow" does not but still marks the moving piece.
Re: cutting irregular pieces from image for puzzle game
Posted: Wed Jul 23, 2025 7:34 pm
by bn
Hi rcmills,
In trying to do a puzzle I noticed that it is at times hard to place the puzzle pieces exactly where they belong using the mouse.
I thought it would be a nice option to move the puzzle pieces and make them "magnetic". By that I mean that if you come to within 2 pixel of the correct position the pieces would snap into place on mouseUp.
Here is a small stack with the script for "magnetism". Copy the script from the contained button to your puzzle pieces or copy the button to your Puzzle Stack and set the behavior of the puzzle pieces to the long id of the button.
I tested the script fairly extensively and it seems to do what it is supposed to do.
The script is not very straightforward (due to the complexity of the task) and if you have questions feel free to ask.
Kind regards
Bernd
Re: cutting irregular pieces from image for puzzle game
Posted: Thu Jul 31, 2025 1:19 am
by rcmills
Thanks very much, Bernd. I will look this over, as I have indeed been having UI difficulties with moving the pieces.
I have been out of town, and left this fun task alone for a while, but am returning to it.
One thing I have learned in the past day is that in LC 10.0.2 the mobilePickPhoto "library" function no longer works properly in iOS. I use it to pick photos from my iPhone library to use in creating the puzzles. I reverted to compiling with 9.6.10, and it worked fine. Has anyone else noticed this, I wonder?
Re: cutting irregular pieces from image for puzzle game
Posted: Sat Aug 02, 2025 10:55 am
by bn
rcmills wrote: Thu Jul 31, 2025 1:19 am
One thing I have learned in the past day is that in LC 10.0.2 the mobilePickPhoto "library" function no longer works properly in iOS. I use it to pick photos from my iPhone library to use in creating the puzzles. I reverted to compiling with 9.6.10, and it worked fine. Has anyone else noticed this, I wonder?
Maybe you better post that question to the iOS forum.
I have no idea about iOS
Kind regards
Bernd
Re: cutting irregular pieces from image for puzzle game
Posted: Sat Aug 02, 2025 11:04 am
by Klaus
rcmills wrote: Thu Jul 31, 2025 1:19 am
Thanks very much, Bernd. I will look this over, as I have indeed been having UI difficulties with moving the pieces.
I have been out of town, and left this fun task alone for a while, but am returning to it.
One thing I have learned in the past day is that in LC 10.0.2 the mobilePickPhoto "library" function no longer works properly in iOS. I use it to pick photos from my iPhone library to use in creating the puzzles. I reverted to compiling with 9.6.10, and it worked fine. Has anyone else noticed this, I wonder?
Please report this as a bug!
It will not get fixed if it is not reported, and this seems to be a critical issue!
Re: cutting irregular pieces from image for puzzle game
Posted: Fri Aug 22, 2025 9:44 pm
by rcmills
Thanks, Klaus. I have reported the bug - ID # 24734
Re: cutting irregular pieces from image for puzzle game
Posted: Mon Sep 01, 2025 9:07 am
by bn
Hi rcmills,
I do not know if you are still working on your Puzzle.
I made a version for puzzle pieces that lets you create them at different sizes. I removed the hardcoded values for the puzzle pieces and replaced them with variables. The mask pieces now have the necessary information as custom properties.
If you (or anybody else) is interested I can post it here.
Kind regards
Bernd
Re: cutting irregular pieces from image for puzzle game
Posted: Mon Sep 01, 2025 9:33 am
by SparkOut
Hi bn
I am super interested, although I doubt I would get a chance to explore it much. But I do love to see other coders work and examine different techniques. Anything you show would be appreciated by more than one, thank you.
Re: cutting irregular pieces from image for puzzle game
Posted: Mon Sep 01, 2025 2:53 pm
by bn
Here are two stacks to
1. create image masks in the shape of a puzzle piece (actually 64 of them) stack "VariableImageMasks"
2. A stack that uses these masks to make puzzle pieces from an image using those masks stack "CreatePuzzleVariableSize".
Please feel free to indicate errors or suggestions for improvement.
Kind regards
Bernd