Expressions can only access a value at time, they cannot scan through a timeline and look for a value then do something with that value. You could control a property like opacity or a frame by using time remapping by referencing a color. There isn't any way to write a single expression that would automatically create a pattern. Expressions are based on Java but they are not as versatile as Java Script.
For example if you sampled an area of the frame and tied that color sample to a frame of an image sequence which had time remapping applied you could cause a certain frame to be displayed when the color matched the preset. You would have to write a different expression for each color.
I'd create an image sequence of lego blocks carefully shot to they are in exactly the same position. One frame for each colored block. When you have the image sequence complete you apply time remapping then add your expression. Depending on the complexity of the Lego illustration it would probably take less time to just do this manually. Without seeing a sketch of your idea and having a lot more detail I can't give you much more help than that. The description of your project does not give me much to go on.
Expressions cannot generate layers. You can only re-position and re-color already existing blocks to mimic the behavior, but even then the sheer number of layers, the color sampling and having to run everything in loops to re-evaluate all parameters with every frame will bring AE to its knees.