You can model the problem as a "Game Tree" where the state (node) is the current matrix/image that gets built and the "move" (edge) is adding something to the image so that you go into another state.
In the end, you should hit a final state in which the image is complete. In the case of a pattern, think well at the "moves" you have to do to keep your solution valid. Hope this helps.