#! /usr/bin/perl -w use strict; use warnings; use Math::Trig; # for pi (not \$pi) # assumes \$r1 and \$r2 are positive integers sub ring { my (\$p, \$r1, \$r2, \$fill) = @_; my @pos = @\$p; print STDOUT < EoF } # assumes \$r1 and \$r2 are positive integers sub cog { my (\$p, \$r1, \$r2, \$phase, \$fill) = @_; my @pos = @\$p; print STDOUT < EoF my \$nt = 36; # number of teeth my \$da = 360/\$nt/2; # size of tooth = size of spacer my \$deg = pi/180; my (\$xa1, \$ya1, \$xb1, \$yb1, \$xa2, \$ya2, \$xb2, \$yb2); for (my \$thx = 0; \$thx < 360; \$thx += 2*\$da) { my \$theta = \$thx + 2*\$phase*\$da; \$xa1 = \$r1 * cos(\$deg * (\$theta)); \$ya1 = \$r1 * sin(\$deg * (\$theta)); \$xb1 = \$r1 * cos(\$deg * (\$theta + \$da)); \$yb1 = \$r1 * sin(\$deg * (\$theta + \$da)); \$xa2 = \$r2 * cos(\$deg * (\$theta)); \$ya2 = \$r2 * sin(\$deg * (\$theta)); \$xb2 = \$r2 * cos(\$deg * (\$theta + \$da)); \$yb2 = \$r2 * sin(\$deg * (\$theta + \$da)); print STDOUT < EoF } print STDOUT < EoF } sub disk{ my (\$p, \$rrr, \$fill) = @_; my @pos = @\$p; # rotate so that if you put text on the path, the text is at 12:00 print STDOUT < EoF } #xx sizes suitable for some other machine: #xx my \$d1 = 2245; #xx my \$d2 = 2365; #xx my \$d3 = 2625; # sizes suitable for vidaXL badge machine: my \$d1 = 2283; my \$rim = 100; # approximate size of rim my \$d2 = \$d1 + 2*\$rim; my \$d3 = 2756; # 70 mm cover disk sub maxdisk{ my (\$p) = @_; disk(\$p, \$d3, "gray"); } sub mindisk{ my (\$p) = @_; disk(\$p, \$d1, "gray"); } sub userdisk{ my (\$p) = @_; disk(\$p, \$d3, "blue"); } sub rimring { my (\$p) = @_; ring(\$p, \$d1, \$d2, "yellow"); } sub backring { my (\$p) = @_; ring(\$p, \$d2, \$d3, "green"); } sub backrimring { my (\$p) = @_; ring(\$p, \$d1, \$d3, "white"); } sub cutring { my (\$p) = @_; cog(\$p, \$d3, \$d3+100, 0, "red"); cog(\$p, \$d3, \$d3+100, 0.5, "blue"); } sub layout_layer{ my (\$ID, \$content) = @_; print STDOUT < EoF my \$x1; \$x1 = 1750; # layout looks good with no grid \$x1 = 1700; # aligns better with grid my \$x2 = \$x1 + 2500; my \$x3 = \$x2 + 2500; my \$dy = 3000; # should be even multiple of grid size my \$y1 = 1800; my \$y2 = \$y1 + \$dy; my \$y3 = \$y2 + \$dy; my \$yo = \$dy/2; for my \$pos ( [\$x1,\$y1], [\$x2,\$y1+\$yo], [\$x3,\$y1], [\$x1,\$y2], [\$x2,\$y2+\$yo], [\$x3,\$y2], [\$x1,\$y3], [\$x2,\$y3+\$yo], [\$x3,\$y3], ) { \$content->(\$pos); } print STDOUT < EoF } sub margin_layer{ my \$ID = 'margins'; my \$mmm = 250; my \$wbig = 8500; my \$woff = \$wbig - \$mmm; my \$hbig = 11000; my \$hoff = \$hbig - \$mmm; print STDOUT < EoF } # a square, to check the dimensional accuracy # of the printing process sub ref_layer{ my \$ID = 'reference-square'; print STDOUT < EoF } sub all_layers{ # in order, from back to front: layout_layer('maxdisk', \&maxdisk); layout_layer('mindisk', \&mindisk); layout_layer('user-artwork', \&userdisk); ref_layer(); layout_layer('cut', \&cutring); layout_layer('rim', \&rimring); layout_layer('back', \&backring); layout_layer('backrim', \&backrimring); margin_layer(); } sub svg { # user units are milli-inches: print STDOUT < EoF all_layers(); print STDOUT < EoF } main: { svg(); }