Reference link: https://www.geogebra.org/m/RHYH3UQ8 , https://www.geogebra.org/m/xkzsqcyx , https://www.netpad.net.cn/svg.html#posts/55789
I want to generate an rotating squares animation like this, my code only workd for 3×3 squares, how can I expand to more squares ( (2n-1) × (2n-1) )?
pts = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
Manipulate[Graphics[{
EdgeForm[Gray], LightRed,
RotationTransform[θ + Pi/2, #]@pts & /@ pts // Polygon,
LightGreen, Polygon[pts],
TranslationTransform[RotationTransform[θ + Pi/2, #2]@# - #]@pts & @@@
Partition[pts, 2, 1, 1] // Polygon
}, PlotRange -> {{-2, 3}, {-2, 3}}], {θ, 0, Pi}]
Build a chessboard without rotating:
Graphics[{EdgeForm[Gray],
Table[{If[Mod[i+j, 2]==0,LightRed,LightGreen],Rectangle[{i,j}]},{i,5},{j,5}]} ]
or
ArrayPlot[Mod[Array[Plus,{5,5}],2],ColorRules->{0->LightRed,1->LightGreen},Mesh->All]