Search Results for: spirograph

Spirograph Random Numbers: What Are The Odds?

The GCMC Spirograph Generator program chooses parameters using pseudo-random numbers based on a seed fed in from the Bash script, so I was surprised to see two plots overlap exactly:

Overlaid pattern - G-Code simulator

Overlaid pattern – G-Code simulator

The two overlapping traces are the 15 inward-pointing wedges around the central rosette.

The first one:

(PRNG seed: 38140045)
(Paper size: [16.50in,14in])
(PlotSize: [15.50in,13.00in])
(Stator 3: 150)
(Rotor  4: 40)
(GCD: 10)
(Offset: -0.94)
(Dia ratio: -0.27)
(Lobes: 15)
(Turns: 4)
(Plot scale: [5.11in,4.29in])
(Tool change: 1)
T1
M6

The second one:

(PRNG seed: 74359295)
(Paper size: [16.50in,14in])
(PlotSize: [15.50in,13.00in])
(Stator 3: 150)
(Rotor  4: 40)
(GCD: 10)
(Offset: -0.93)
(Dia ratio: -0.27)
(Lobes: 15)
(Turns: 4)
(Plot scale: [5.12in,4.30in])
(Tool change: 3)
T3
M6

The Offset isn’t quite the same, but the pen width covers up the difference.

With only four Stators and 17 Rotors, the probability of picking the same pair works out to 0.25 × 0.059 = 1.4%. You can sometimes get the same number of Lobes and Turns from several different Stator + Rotor combinations, but these were exact matchs with the same indices.

The Pen Offset within the Rotor comes from a fraction computed with ten bit resolution, so each Offset value represents slightly under 0.1% of the choices. If any four adjacent values look about the same, then it’s only eight bits of resolution and each represents 0.4%.

The Rotor and Stator set the Diameter ratio, but the sign comes from what’s basically a coin flip based on the sign of a fraction drawn from 256 possibilities; call it 50%.

Overall, you’re looking at a probability of 28 ppm = 0.0028%, so I (uh, probably) won’t see another overlay for a while …

I don’t know how to factor the PRNG sequence into those numbers, although it surely affects the probability. In this case, two different seeds produced nearly the same sequence of output values, within the resolution of my hack-job calculations.

Whatever. It’s good enough for my simple purposes!

,

Leave a comment

MPCNC: Spirograph Generator with Tool Changes

An improved version of my GCMC Spirograph pattern generator, now with better annotation and tool changes:

Spirograph pattern - overview

Spirograph pattern – overview

The GCMC code sets the stator and rotor gear tooth counts, the rotor diameter, and the pen offset using a pseudo-random number generator. This requires randomizing the PRNG seed, which I do in the calling script with the nanosecond of the current second: rnd=$(date +%N).

The G-Code file name also comes from the timestamp:

ts=$(date +%Y%m%d-%H%M%S)
fn='Spiro_'${ts}'.ngc'
# blank line to make the underscore visible

Which means you must call the Bash script slowly to generate a pile o’ plots:

for i in {1..60} ; do sh /mnt/bulkdata/Project\ Files/Mostly\ Printed\ CNC/Patterns/spiro.sh ; sleep 1 ; done

Sift through the heap with drag-n-drop action using an online G-Code previewer. There seems no clean way to convert G-Code to a bitmap on the command line, although you can do it manually, of course.

The GCMC program spits out the G-code for one plot at a time, so the Bash script calls it four times to fill a sheet of paper with random patterns:

for p in $(seq 4)
do
  rnd=$(date +%N)
  gcmc -D Pen=$p -D $Paper -D PRNG_Seed=$rnd $Flags $LibPath -q "$Spirograph" >> $fn
done

The -q parameter tells GCMC to not include the prolog and epilog files, because the calling script glues those onto the lump of G-Code for all four plots.

The -D Pen=$p parameter tells the GCMC program which “tool” to select with a Tn M6 tool change command before starting the plot. Although plotter pens have a well-defined position in the holder and a pretty nearly constant length, you must have a tool length probe installed and configured:

MPCNC Tool Length Probe - Plotter Pen

MPCNC Tool Length Probe – Plotter Pen

Set the overall sheet size in inches or millimeters to get a plot centered in the middle of the page with half-inch margins all around:

Paper='PaperSize=[16.5in,14in]

With all that in hand, those good old black ceramic-tip pens give impeccable results:

Spirograph pattern - black ceramic pen - detail

Spirograph pattern – black ceramic pen – detail

The surviving ones, anyhow. I must apply my collection of Sakura Micron pens to this task.

The other three colors come from fiber pens with reasonably good tips:

Spirograph pattern - central details

Spirograph pattern – central details

They’re a lot like diatoms: all different and all alike.

The GCMC and Bash source code as a GitHub Gist:

,

1 Comment

A Spirograph for Christmas

Gotta play with my new toy:

Spirograph - liquid ink - ceramic tip

Spirograph – liquid ink – ceramic tip

That’s with a set of liquid ink and ceramic tip plotter pens. They’re unbelievably cranky, but produce wonderfully fine lines:

Spirograph - liquid ink pen - detail

Spirograph – liquid ink pen – detail

Text comes out exactly the way vector lettering should look:

Spirograph - liquid ink pen text - detail

Spirograph – liquid ink pen text – detail

There’s a slight shake visible at 500 mm/min = 8.3 mm/s, but it’s Good Enough.

All the pen-and-ink traffic around the center produced a ring of damp green fuzz:

Spirograph - liquid ink - ceramic tip - center detail

Spirograph – liquid ink – ceramic tip – center detail

The artsy part of the plot ran at 1800 mm/min = 30 mm/s, with little of the wobbulation at 6000 mm/min = 100 mm/s. None of that would matter with a router, of course.

It’s a nice, Christmasy design in kinda-red and sorta-green.

From the stack of plots accumulating near the MPCNC bench:

This slideshow requires JavaScript.

Plots 7 and 9 show the tape sutures required to produce a 26×18 inch sheet covering the MPCNC’s full work area. The squat plots fit on B-size sheets and the rest come from 17×14 inch artist’s sketchpad sheets.

I used Google PhotoScan to capture and rectangularize paper sheets from the floor or atop the bench, then battered the contrast and crushed the file size with a one-liner:

i=1 ; for f in 1* ; do printf -v dn "Spiro %02d.jpg" $(( i++ )) ; convert $f -level '10,80%' -density 300 -define jpeg:extent=300KB tweaked/"$dn" ; done

The plots look great in person (modulo some incremental software improvements), but the slideshow images look awful because:

  • Google PhotoScan produces surprisingly low-res images
  • I’m overly compressing the results

They’re not (yet) art and there’s no point in a high-quality workflow.

Enjoy the day …

,

6 Comments

MPCNC: Spirograph Exerciser

Both bCNC and GCMC include Spirograph generators with more-or-less fixed patterns and sizes, because the code serves to illustrate the software’s capabilities:

MPCNC - bCNC Spirograph patterns

MPCNC – bCNC Spirograph patterns

GGMC Cycloids test patterns

GGMC Cycloids test patterns

I wanted to exercise my MPCNC’s entire range of travel, familiarize myself with some new GCMC features, and, en passant, mimic the actual gears in a classic Spirograph, so, of course, I had to write a Spirograph emulator from scratch:

MPCNC - Full-platform Spirograph - multicolor

MPCNC – Full-platform Spirograph – multicolor

The perspective makes a 29×19 inch sheet of paper (made from three B sheets and one A sheet) look not much larger than the 17×11 inch B size sheets in the first two pictures. IRL, it’s a billboard!

My GCMC code uses notation and formulas from a paper (tidy PDF) on a Gnuplot spirograph generator, with a dash of error checking from the GCMC source.

The code enumerates the possible gear tooth counts in a pair of vectors from which you select the desired stator and rotor gears using integer subscripts. Because I eventually scale the results to fit the plot area, there’s no need to keep track of actual gear pitch diameters.

Similarly, the pen offset from the center of the rotor gear is a pure number, which you can think of as the ratio of the offset to the rotor diameter. It can have either sign and may exceed unity, as needed, either of which would be difficult with a physical gear.

Figuring the number of rotor turns required to complete the pattern requires reducing the gear ratio to a fraction with no common factors, so I wrote a Greatest Common Divisor function using Euclid’s algorithm adapted for GCMC’s bitwise tests and shifts.

With those values in hand, a loop iterates around the entire pattern to produce a list of XY coordinates in normalized space. Because the formula doesn’t have the weird properties of the Superformula I used with the HP 7475 plotter, I think there’s no need to prune the list to eliminate tiny moves.

Scaling the entire plot requires keeping track of the actual extents along both axes, which happens in the loop generating the normalized coordinates. A pair of gears producing an odd number of lobes can have different extents in the positive and negative directions, particularly with only a few lobes (3, 5, 7 …):

Spirograph - 3 lobes - QnD Simulator

Spirograph – 3 lobes – QnD Simulator

So I accumulate all four, then scale based on the absolute maximum; I added scalar min() and max() functions.

Converting the list of scaled points into G-Code turns out to be a one-liner using GCMC’s tracepath() library function. Previewing the results in a Web-based simulator helps weed out the duds.

The code needs cleanup, in particular to let a Bash script set various parameters, but it’s a good start.

The GCMC source code as a GitHub Gist:

, ,

9 Comments

MPCNC: GCMC Spirograph Shakedown

The MPCNC instructions recommend running it for a while, taking it apart, then putting it back together, so all the parts have a chance to relax and get used to working together. To that end, I figured doing some full platform plots would run the rollers over the entire length of the rails:

MPCNC - Full-platform Spirograph - first pass

MPCNC – Full-platform Spirograph – first pass

I taped three B-size sheets together, with an A-size sheet in the far right corner, into a 29×19 inch sheet to put borders around the MPCNC’s 28×18 inch work area. The tape is on the top surface to prevent embarrassing accidents where the pen snags on an edge, at the cost of blurry lines where the ink doesn’t stick quite right.

The far left corner of the paper washes up on the tool length probe’s base, but the pen position turns out to be so repeatable (it should be!) you can swap them with gleeful abandon and get good results:

MPCNC - Full-platform Spirograph - multicolor

MPCNC – Full-platform Spirograph – multicolor

The pen rumbles along at 12000 mm/min = 200 mm/s = 7.8 inch/s with no hint of wobblulation. Most likely, those big loops aren’t particularly challenging, although watching the big central assembly whip around a tight curve can be startling.

I modified the pen holder for 3-point support, as the recess for the pen flange isn’t quite deep enough:

MPCNC - Pen holder - 3 point grip

MPCNC – Pen holder – 3 point grip

Good old masking tape holds the pens securely enough for now.

The glass plate I’d been using for B-size plots doesn’t cover the full area, but I’d set the Z axis limit switch to trip just before the bottom of the rails whacked into the glass. Extending the travel by 5 mm required a snippet of black tape:

MPCNC - Z axis switch - table limit

MPCNC – Z axis switch – table limit

The patterns come from a scratch-built Spirograph generator, because I wanted to review what’s new in GCMC. More on the software tomorrow …

, ,

1 Comment

GCMC Platter Engraving

Engraving Spirograph / Guilloché patterns on scrap CDs and hard drive platters now works better than ever:

Spirograph - 674203941 - preview
Spirograph – 674203941 – preview

After, that is, I realized:

  • Any Rotor will work, as long as it’s smaller than the Stator
  • You must pick pen offset L so the pattern never crosses the stator center point
  • L ≥ 1 is perfectly fine
  • You must scale the resulting pattern to fit the actual space on the disk

One of my final doodles showing how the variables relate to each other, although the Wikipedia article may be useful for the underlying math and other posts have more pix on various machines:

Spirograph Scaling doodles
Spirograph Scaling doodles

Cheat sheet:

  • Stator has tooth count (∝ radius) R
  • Rotor has tooth count (∝ radius) r
  • K = r/R, so if you normalize R=1, K=r
  • Pen offset L puts it at radius rL in the rotor

Picking a suitable rotor requires iterating with random choices until one fits:

  RotorTeeth = Stators[-1];
  n = 0;
  while (RotorTeeth >= floor(0.95 * StatorTeeth) || RotorTeeth < 5) {
    RotorTeeth = (XORshift() & 0x007f);       // this is why Stator can't have more than 127 teeth
    n++;
  }
  comment("Rotor: ",RotorTeeth," in ",n," iterations");

The 5% buffer on the high end ensures there will be an L keeping a hole in the middle of the pattern. Requiring at least five teeth on the low end just seems like a Good Idea.

Given the stator & rotor tooth counts, iterate on random L values until one works:

  n = 0;
  do {
    L = (to_float((XORshift() & 0x1f) + 1) / 32.0) * (1.0/K - 1.0);   // allow L > 1.0
    n++;
  } while (L >= (1.0/K - 1.0) || L < 0.01);
}
comment("Offset L: ", L," in ",n," iterations");

With L chosen to leave a hole in the middle of the pattern, then the pattern traced by the pen in the rotor is centered at 1.0 – K (the normalized Stator radius minus the normalized Rotor radius) and varies by ±LK (the offset times the normalized Rotor radius) on either side:

RotorMin = 1.0 - 2*K;
comment("Rotor Min: ",RotorMin);

BandCtr = 1.0 - K;                      // band center radius
BandMin = BandCtr - L*K;                //  ... min radius
BandMax = BandCtr + L*K;                //  ... max radius

BandAmpl = BandMax - BandCtr;

comment("Band Min: ",BandMin," Ctr: ",BandCtr," Max: ",BandMax);

Knowing that, rescaling the pattern to fit the disk limits goes like this:

FillPath = {};

foreach (Path; pt) {

  a = atan_xy(pt);                      // recover angle to point
  r = length(pt);                       //  ... radius to point

  br = (r - BandCtr) / BandAmpl;        // remove center bias, rescale to 1.0 amplitude
  dr = br * (OuterRad - MidRad);        // rescale to fill disk
  pr = dr + MidRad;                     // set at disk centerline

  x = pr * cos(a);                      // find new XY coords
  y = pr * sin(a);

  FillPath += {[x,y]};
}

comment("Path has ",count(FillPath)," points");

The final step prunes coordinates so close together as to produce no useful motion, which I define to be 0.2 mm:

PointList = {FillPath[0]};                // must include first point

lp = FillPath[0];
n = 0;

foreach (FillPath; pt) {
  if (length(pt - lp) <= Snuggly) {       // discard too-snuggly point
    n++;
  }
  else {
    PointList += {pt};                    // otherwise, add it to output
    lp = pt;
  }
}

PointList += {FillPath[-1]};                // ensure closure at last point

comment("Pruned ",n," points, ",count(PointList)," remaining");

The top of the resulting G-Code file contains all the various settings for debugging:

(Disk type: CD)
(Outer Diameter: 117.000mm)
(        Radius: 58.500mm)
(Inner Diameter: 38.000mm)
(        Radius: 19.000mm)
(Mid Diameter: 77.500mm)
(      Radius: 38.750mm)
(Legend Diameter: 30.000mm)
(         Radius: 15.000mm)
(PRNG seed: 674203941)
(Stator 8: 71)
(Rotor: 12 in 1 iterations)
(Dia ratio K: 0.169 1/K: 5.917)
(GCD: 1)
(Lobes: 71)
(Turns: 12)
(Offset L: 3.227 in 1 iterations)
(Rotor Min: 0.662)
(Band Min: 0.286 Ctr: 0.831 Max: 1.376)
(Path has 43201 points)
(Pruned 14235 points, 28968 remaining)

The GCMC source code as a GitHub Gist:

, ,

1 Comment

HP 7475A Plotter: Ceramic-Tip Pen EOL

Ceramic-tip plotter pens draw wonderfully crisp lines:

Spirograph pattern - black ceramic pen - detail
Spirograph pattern – black ceramic pen – detail

Eventually, though, the fiber tip wears flush with the ceramic shell, becomes slightly indented, and ceases to make its mark in the world:

HP 7475A Plotter - Ceramic pen - worn tip
HP 7475A Plotter – Ceramic pen – worn tip

As the lady says, “Starting from zero, got nothing to lose”, so I applied a fine diamond file around the tip:

HP 7475A Plotter - Ceramic pen - filed tip
HP 7475A Plotter – Ceramic pen – filed tip

Well, all I can say is it seemed like a good idea at the time.

Alas, even the newly exposed fiber didn’t make much of a mark on the paper and, as you’d expect, the ragged ceramic tip dragged painfully across the paper. I assume the fiber had filled with fossilized dry ink.

A New Old Stock bag of fiber-tip pens emerged from the Big Box o’ Pens while I was flailing around:

HP 7475A Plotter - NOS Green pen package
HP 7475A Plotter – NOS Green pen package

I think the “812” in the lower right corner is a date code, most likely early in 1988, so the pens started their lifetime countdown at least three decades ago. They still work, though:

HP 7475A Plotter - NOS Green pens
HP 7475A Plotter – NOS Green pens

The plotter appeared at HV Open’s Mad Science Fair, because everybody loves a plotter!

4 Comments