I want to generate a square matrix of squares with parallel lines/stripes colored with different colors:
columnNumber = 10;
rowNumber = 10;
icolumn = 1;
Graphics[{EdgeForm[Black],
Table[{
If[(i == icolumn || i == icolumn + 2 || i == icolumn + 4 ||
i == icolumn + 6 || i == icolumn + 8),
Blue,
Green],
Rectangle[{1.07*i, 1.07*j}]},
{i, 1, columnNumber, 1.}, {j, 1, rowNumber, 1.}]},
AspectRatio -> 1, ImageSize -> 240]
Here is the result:
I substitute
for the If
condition,
(i == icolumn || i == icolumn+2 || i == icolumn+4 || i == icolumn+6 || i == icolumn+8)
the For
loop
For[icol = 1, icol < 10, icol = icol + 2, If[i == icol, Blue, Green]]
like this:
Graphics[{EdgeForm[Black],
Table[{
For[icol = 1, icol < 10, icol = icol + 2,
If[i == icol, Blue, Green]],
Rectangle[{1.05*i, 1.05*j}]},
{i, 1, columnNumber, 1}, {j, 1, rowNumber, 1}]},
AspectRatio -> 1, ImageSize -> 240]
But then it returns a black image:
Can anyone suggest what is wrong with my code that combines For
and If
?
For[]
? In any event:With[{rowNumber = 10, columnNumber = 10}, Graphics[{EdgeForm[Black], Table[{If[OddQ[i], Blue, Green], Rectangle[{1.07*i, 1.07*j}]}, {j, rowNumber}, {i, columnNumber}]}]]
$\endgroup$Mod[]
or something. $\endgroup$