If you look at my code example in the topic How do I present one questionnaire after the participant clicks on one image displayed in sequence? (March) you can see an example of how to do this (my tiles happened to be in a circular arrangement but the idea is similar). Depending on your task instructions (‘click what you can remember’ vs ‘you must click at least n out of m squares’) you will want to change wrap the mouse part in a timer, a counter, or offer a ‘done’ button (could be ‘click outside the grid when done’).
I think doing the grid with filled rectangles is a good strategy, though someone with a better idea of draw-times, and memory usage would be able to comment. My guess is that this is a very low footprint experiment so it may not matter.