JigSaw

Community Forums/General Help/JigSaw

JBR(Posted 2014) [#1]
Hi, I'd like to create all the pieces for a jigsaw puzzle.

i.e. a rectangle jigsaw with a variable number of pieces.

Any ideas how to do this in code?

Jim


Kryzon(Posted 2014) [#2]
Divide each dimension of the rectangle by the required amount of pieces on that axis. This gives you the amount of rows (height / num_vertical_pieces) and the amount of columns (width / num_horizontal_pieces) that the puzzle should have.

Now you need to add the rounded parts of the pieces.
They have a certain pattern depending on their location on the puzzle. You start with rectangular pieces and add the round holes and round limbs based on that.
For example, the corner and edge pieces are different than the ones on the middle, as they don't have round holes or round limbs going outside of the puzzle rectangle.
These patterns are always interposed, so you can use an "even" and "odd" numerical logic.

You need to take note of these patterns and implement them algorithmically with a nested FOR...NEXT loop.

Const numColumns%	= 20
Const numRows%	 	= 10

Dim Jigsaw( numColumns, numRows )

Local xEven% = 1 ;Start "odd" so that the first iteration is even.
Local yEven% = 1 ;The odd value is "1," the even value is "0." 

For x = 1 To numColumns

	xEven = 1 - xEven ;Implement an even-odd variable horizontally.

	For y = 1 To numRows
		
		yEven = 1 - yEven ;Implement an even-odd variable vertically.

		Select x

			Case 1
				
				Select y
					
					Case 1
						;This piece is on the top-left corner (and left edge).

					Case numRows
						;This piece is on the bottom-left corner (and left edge).
					
					Default
						;This piece is somewhere on the left edge.

				End Select

			Case numColumns
				
				Select y
					
					Case 1
						;This piece is on the top-right corner (and right edge). 

					Case numRows
						;This piece is on the bottom-right corner (and right edge).
					
					Default
						;This piece is somewhere on the right edge.

				End Select
				

			Default

				Select y
					
					Case 1
						;This piece is somewhere on the top edge.

					Case numRows
						;This piece is somewhere on the bottom edge.
					
					Default
						;This piece is not on any of the edges, it is inside the puzzle.

				End Select

		End Select

	Next

Next
You need to style each piece - that is, add the rounded limbs and holes - depending on the cases above and if the occurrence of the piece is "even" or "odd" with different relations between horizontal oddness and vertical oddness.


JBR(Posted 2014) [#3]
Thanks Kryzon. This is a good start for me.
Jim