I want to color one of the diagonal elements of a matrix that consists of 45° rotated and zigzag arranged squares. The addressing condition is following j=2*i and j=2*i-1, where j and i are the vertical and horizontal order numbers.
sideLength = 1;
rotatedSqare[x0_, y0_] := Polygon[{{x0, y0}, {x0 + sideLength*0.7,
y0 - sideLength*0.7}, {x0 + sideLength*1.4,
y0}, {x0 + sideLength*0.7, y0 + sideLength*0.7}}]
Applying the conditions individually If [j == 2*i , Blue, Green] and If [j == 2*i - 1 , Blue, Green] for coloring works properly, as shown below:
{Graphics[{EdgeForm[Thickness[0.0013]], LightBlue, Table[{If [j == 2*i - 1 , Blue, Green], rotatedSqare[
x0 + (period)*(i - 1) + Boole[OddQ[j + 1]]*(period)/2,
y0 + (period/2) j]}, {i, 1, 11}, {j, 1, 22}]}, PlotRange -> {{0, 20}, {0, 15}}, ImageSize -> 300], Graphics[{EdgeForm[Thickness[0.0013]], LightBlue, Table[{If [j == 2*i , Blue, Green], rotatedSqare[
x0 + (period)*(i - 1) + Boole[OddQ[j + 1]]*(period)/2,
y0 + (period/2) j]}, {i, 1, 11}, {j, 1, 22}]}, PlotRange -> {{0, 20}, {0, 15}}, ImageSize -> 300]}
When I combine two conditions together “ If [(j == 2*i And j == 2*i-1), Blue, Green]”, then I get this message:
“If is not a Graphics primitive or directive.”
Can someone help me to get around this? Thanks!!!
And
with&&
or useAnd
with infix notation asIf[(j == 2*i)~And~(j == 2*i - 1), Blue, Green]
. $\endgroup$x0
,y0
andperiod
in your code. Please edit and update your question accordingly. $\endgroup$