I have a mansory-grid in a pdf-page. The grid is choosen randomly, so i do not know how much upright cells or cross cells I have to fill. In my list I have all images that I want to proceed, each marked if it is upright or cross. My approach is now:
- get the grid for the page
- iterate through the list and use the images which fit to the next grid-cell.
- remove this image from the list
- Proceed with the next cell.
- if the grid on the page is filled proceed with the next page (Step 1)
To test my approach, I used the following script:
imageSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
def fillLayout(images):print("Images in Stack", len(images))# Base condition to leave recursionif len(images) == 0: print("finished")return 1idx = 0for image in images: print(" index: ", idx, "item: ", image)del(images[idx]) # This marks the point, image is used on the cell layout and can be removedidx += 1if idx == 5: print("break at idx: ", idx) idx = 0break # This marks the point, grid is filled, proceed with the next pagefillLayout(images)fillLayout(imageSet)
I get the following output:
Images in Stack 16index: 0 item: 1index: 1 item: 3index: 2 item: 5index: 3 item: 7index: 4 item: 9
break at idx: 5
Images in Stack 11index: 0 item: 2index: 1 item: 6index: 2 item: 10index: 3 item: 12index: 4 item: 14
break at idx: 5
Images in Stack 6index: 0 item: 4index: 1 item: 11index: 2 item: 15
Images in Stack 3 <-- from now it does not proceed as expectedindex: 0 item: 8index: 1 item: 16
Images in Stack 1index: 0 item: 13
Images in Stack 0
finished
What I want is
...
Images in Stack 6index: 0 item: 4index: 1 item: 11index: 2 item: 15index: 0 item: 8index: 1 item: 16
break at idx: 5
Images in Stack 1index: 0 item: 13
finished
Any ideas what I am missing, or how to solve my problem.