Article

Tests

BeginPackage["Wikicode`Square`"]

CreateSquare::usage = "CreateSquare[{x,y},length,angle] returns the \
points of a square located at the given position, with the given side \
length, and rotated by the given angle."

CreateRandomSquares::usage = "CreateRandomSquares[n] creates n randomly \
positioned, sized, and rotated squares."

Begin["`Private`"]

CreateSquare[p : {px_, py_}, L_, \[Theta]_] :=
 Module[{\[Phi]}, \[Phi] = Range[0, 3 \[Pi]/2, \[Pi]/2] + \[Theta];
  L/2 {px + Cos[\[Phi]], py + Sin[\[Phi]]}\[Transpose]]

CreateRandomSquares[n_] :=
 Module[{r, L, \[Phi], \[Theta], sqrs}, r = RandomReal[{1.5, 2}, n];
  \[Phi] = Range[0, (1 - 1/n) 2 \[Pi], 2 \[Pi]/n];
  \[Theta] = RandomReal[{0, 2 \[Pi]}, n];
  L = RandomReal[{0.3, 0.5}, n];
  sqrs = MapThread[
   CreateSquare[#1 {Cos[#3], Sin[#3]}, #2, #4] &, {r,
    L, \[Phi], \[Theta]}];
  Append[sqrs, CreateSquare[{0, 0}, 0.75, RandomReal[{0, 2 \[Pi]}]]]]

End[]
EndPackage[]