How to color elements within Graphics[Table[]] independently?

2018-02-18 20:16:17

I've used a Table[] to generate multiple rounded squares, with Rectangle[{m, n}, RoundingRadius -> .35]. So far, I've been able to color all the squares with the same color, for instance, with LightBlue:


Table[{LightBlue, Rectangle[{m, n}, RoundingRadius -> .35]}, {m,

5}, {n, 5}]}, Frame -> True]

Or generate random colors for each square, for instance, with Hue[RandomReal[]]:



Rectangle[{m, n}, RoundingRadius -> .35]}, {m, 5}, {n, 5}]},

Frame -> True]

But, generally, I'd like to control the color of each of the squares independently, because I already have a vector of Hue[#] colors that I want to use. For instance, I'd like to use this 25 colors in correspondence to each of the (m,n) squares in the grid:



Split@Hue[#] & /@ Range[1/(m*n), 1, 1/(m*n)]

I've tried to do something like the following, but it doesn't seem right:



  • Starting with slightly modified color code:

    m = 5;

    n = 5;

    colors = Hue /@ Range[1/(m*n), 1, 1/(m*n)];

    rectangles = Table[Rectangle[{m, n}, RoundingRadius -> .35], {m, 5}, {n, 5}];

    We may use either of these, among others of course:

    Graphics[{EdgeForm[Black], {colors, Flatten@rectangles}\[Transpose]}, Frame -> True]

    Graphics[{EdgeForm[Black], Riffle[colors, Flatten@rectangles]}, Frame -> True]

    Reference Transpose and Riffle.

    Also possible:

    i = 1;


    Table[{colors[[i++]], Rectangle[{m, n}, RoundingRadius -> .35]}, {m, 5}, {n, 5}]},

    Frame -> True]

    2018-02-18 21:06:17