John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Perl really is good for everything! I'm building a sofa, which is a story in itself and unrelated to Perl. Suffice to say that I started with a table saw and now I'm finishing with a tiny needle and thread.

Covering a complex curved surface with a flat piece of fabric is not trivial. A more specific example, I was trying to make a seat cushin with a "bullnose" design, which entails taking a long rectangle and bending it into a "U" shape to form the top, bottom, and front; then add sides that are flat U's.

Given shapes carefully drawn on slightly larger pieces of cloth, the effort is to match the edges of the two U's. I'm sure someone with experience would simply chalk that up to "skill", knowing just how to match the edges, how it feels when it's stretched just right, etc.

But what about me, a humble programmer who has trouble even holding a needle?

If I mark the edge of the long piece with dots every 5mm (for example), then do the same along the side "U", then I can simply make sure each stitch hits the corresponding dot on each layer being joined. It's like the difference between impressionistic painting and drafting, and I'm back on "technical" turf.

Making accurate dots on a curve (not a straight line) is not easy, if it's to be accurate enough to be any good.

But a program, though, would find it simple. I can do sin's and cos's, measure off pi/2 inches, or whatever, without being bothered by the physical limitations of a tape measure.

In short, I want to write a Perl script to generate a pattern that I can print out.

It reminds me of when I was much younger, playing around with BASIC on simple computers, amusing myself (as well as learning a lot) by writing programs that drew "black hole" plots, perspective drawings, spirograph-type curves, etc.

Well, Perl doesn't have a PLOT statement, or LINETO, or anything like that built-in (sigh).

What should I use? I suppose a package designed for web graphics plots could work with a large (e.g. 180 dpi) bitmap. Any suggestions on one to use on a Windows system? But, it might be better to use a vector-based system. I heard something about a PDF writer. Is that something I can use to encapsulate vector art? Any vector-drawing things out there than I can then print out?

—John

Replies are listed 'Best First'.
Re: Perl and sewing
by allolex (Curate) on Sep 10, 2003 at 20:35 UTC

    Mark-Jason Dominus' site appears to be down at the time of writing this node, but he did something similar with quilt patterns and turned it into a talk (of course). Ah, I just found the exact URL of the results on a Usenet archive.

    Update 2003-09-11 22:19:03 CEST:The site appears to be back up, as many of you have noticed. But just in case:

    Newsgroups: comp.lang.perl.moderated,comp.lang.perl.misc Subject: Re: So what do YOU use Perl for? References: <3ACFB415.63D2CA91@gmu.edu> <slrn9d02ft.ff7.tjla@thislove. +dyndns.org> Organization: Plover Systems Co. From: mjd@plover.com (Mark Jason Dominus) Message-ID: <3ad60451.2149$21a@news.op.net> In article <slrn9d02ft.ff7.tjla@thislove.dyndns.org>, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote: > >I use it to impress women. > Around 1993 or 1994 I started dating a woman who was a quilter. After seeing a lot of quilts and pictures of quilts, it seemed to me that most quilters stuck to a few traditional quilt blocks and that there might be a lot of quilt blocks that were rarely used. I wrote a suite of Perl programs to generate all the quilt blocks of a certain type (sixteen-patch half-square triangles with 90-degree rotational symmetry) and printed out the result: http://www.plover.com/~mjd/misc/quilt/composites/bindexs.jpg (I made an error; one block appears twice. Can you find it?) I was delighted, because the results confirmed my suspicion: There *are* a lot of excellent but rarely-seen quilt blocks. I was delighted even further when we got married, she made the program output into a real quilt and gave it to me as a wedding present. http://www.plover.com/~mjd/misc/quilt/quilt/ She must have been impressed. -- @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ" +;sub p{@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;m +ap{$P=$P[$f^ord ($p{$_})&6];$p{$_}=/^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[ +P.]/&&close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand( +2)if/\S/;print

    --
    Allolex

Re: Perl and sewing
by perrin (Chancellor) on Sep 10, 2003 at 20:21 UTC
    Andy Wardley solved this by generating PostScript. See his Kite module for an implementation.
      That looks interesting, but I don't see much in the way of documentation on how to create my own patterns.
        He gave a talk about it at OSCON one year. You could write to him and ask for a copy of the slides.
Re: Perl and sewing
by tachyon (Chancellor) on Sep 11, 2003 at 09:27 UTC

    Not that it would be near as much fun but my hobby business has been making hang-gliding harnesses for years so I know my way around a sewing machine.

    Just like programming the key is the algorithm, or in other words there is generally an easy way and a hard way to do it.

    Consider sewing the sleeves on a shirt. You can do it two ways:

    • The hard way - by making the vest part and the sleeve tubes and then trying to get the two to mate. In this scenario you are trying to get an exact fit for your sleeve tubes in your vest holes. A few mm off and you either have too much or too little fabric in your sleeve tube
    • The easy way. Sew the sleeve to the unjoined body then run a stitch along the sleeve and down the vest in one pass as shown:
    -------------------------------------------------- \\ // ---sev-sew-sew--+ == == +---sev-sew-sew--- | | s o s e o e w o w | o | s o s e o e w w

    Sometimes you do have to fit a tube into a hole or similar. To do so you would mark 4 quadrant points onto your two pieces to see how you are going. The way you fudge is to cut corners as it were - a little wide gives you extra length on on curve, the inside line is shorter.

    An important point to remeber. Depending on the fabric and stitch tension you will get a real shrinkage along the stitch lines. This can be up to 5% so if it end up just to small to fit don't say you were not warned!

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Perl and sewing
by jdtoronto (Prior) on Sep 10, 2003 at 20:30 UTC
    So PERL really can do EVERYTHING

    Not only is the duct tape of the internet, it is maybe officially the duct tape programming language. The loinger I spend looking at posts within the monastery the more convinced I become that somewhere, sometime, somebody has done with Perl just about anything that can possibly be done on a computer!

    jdtoronto

Re: Perl and sewing
by markguy (Scribe) on Sep 11, 2003 at 13:35 UTC

    All those proposed solutions look interesting, but I thought I'd offer up my own, possibly unique, solution. Marry a fantastic woman who just happens to be a senior designer for Hollister and have her do it. Sure, the API is undocumented, propietary and tricksie. Once you've figured all that out though, it's a snap!

    Already married? Poor planning, my friend... poor, poor planning! :)

Re: Perl and sewing
by Willard B. Trophy (Hermit) on Sep 11, 2003 at 21:36 UTC
    Non-Perl solution, so feel free to ignore: there are tools available that lay down a regular track of markers every few millimetres on cloth. The ones I've seen use a toothed wheel rubbing against a stick of chalk.

    No idea what they're called; stitching markers, perhaps? They look like they'd do the job for you.

    --
    bowling trophy thieves, die!