At first, I considered using planetary gears to achieve a square motion pattern. Unfortunately, I did not have a combination of gears that could achieve a square pattern shape.
Figure 2. Loci in Epicyclic gearing
So instead, I decided to develop a system of links and joints that could create a pseudo-random 2D motion pattern. I began with the single-crank 4-bar, a mechanism with 1 degree of freedom (DoF) which converts a circular motion into an oscillation of the output link. I knew I needed two single-crank 4-bars working together to provide the 2 DoFs required to draw a custom 2D pattern. To achieve a pseudo-random effect, I employed a gear train that spins the two slider cranks asynchronously and connected the output links into a 5-bar to produce a single output point.
Figure 3. Single crank 4-bar. Link AB is the input, link CD is the output. The mechanism has 1DoF.
Credit: https://www.cs.cmu.edu/~rapidproto/mechanisms/chpt5.html