Coloring a square grid by clicking
just select n for a nxn grid
n = 5;
Grid[Partition[
Table[DynamicModule[{col = White},
EventHandler[
Dynamic[Graphics[{EdgeForm[Thick], col, Rectangle[]},
ImageSize ->
Tiny]], {"MouseClicked" :> (col =
col /. {Black -> White, White -> Black})}]], {n^2}], n]]
here is the result
n = 10;
m = ConstantArray[0, {n, n}];
Row[{Dynamic[EventHandler[ArrayPlot[m, Mesh -> All, ImageSize -> 300],
{"MouseClicked" :> With[{p = Reverse[{1, n} + {1, -1} Floor@MousePosition["Graphics"]]},
m[[## & @@ p]] = m[[## & @@ p]] /. {0 -> 1, 1 -> 0}]}]],
Dynamic[Style[MatrixForm[m], 24]]}, Spacer[20]]