METraps is a Ruby module which contains MarkingEngine traps that I use constantly in my vehicle graphics factory.  If you recall, a MarkingEngine trap is a way to dynamically assemble a stream of MarkingEngine instructions dynamically.

The first trap is called rdraw, or Radial Draw.  This trap is used to create a path that can be replicated radially in a circle around a central origin point.  It takes 2 to 3 arguments:

  • ntimes :: the number of copied paths you want to draw
    • For example: a value of 4 will draw four paths around the circle, one up, one down, one left, one right
  • inst :: the MarkingEngine instructions which define the path
    • The reference path assumes positive X and positive Y away from the center point
  • first :: the initial angle at which to begin drawing (default is 0°)

This trap is very useful for painting bolts, spokes, cutouts and other decorations in wheels and other round objects.

The second trap is tpdraw, or Tread Path Draw.  This trap is used to trace a path of tank tread links around a defined set of bogies, or wheels.  The math here is fairly involved and the current version lacks support for catenary curves for those tanks that use gravity to keep the treads in place (Panther and Tiger tanks).  Let’s just say it works well enough for now with an updated version in the works.

The third trap is star_draw.  This path will create a graphic around a circle where points on two different radii are connected.  There are two styles currently supported: sawtooth and sine.  A sawtooth star will create a starburst style of graphic by connecting points on the two orbits with straight lines.  A sine star will connect the points with curves, which can simulate a rounded tooth gear.  It connects the points with quadratic bezier curves.