just a little drawing program. nothing fancy (surely not good code either), but something that at least entertained me for a little while, and a little history of how it was born :-)

first of all, let's picture the situation. some days ago, I was stuck in a meeting; you know, one of these long-term-strategy-planning meetings.

there's always one point, in such meetings, when everybody around the table seems to be spreading nonsense (things like "this database can handle 10k simultaneous connection, guaranteed" or "it is necessary that we use XML to store our data", or even "let's write it in Java").

at that point I (as most others do, I tend to believe) started sketching something on the noteblock. the sheets had small square blocks, so I initially went with something geometric.

after a while (and a lot of nonsense) I started drawing circles, and ended up playing with variations on the yin-yang theme (the tao circle, the tai chi, whatever you call it, I'm not a zen expert :-).

for some strange reason, I came home with the idea of producing something more beautiful than my handmade version on paper. so I enumerated my possibilities:

1) buy a compass, some good paper and a marker.
2) use some drawing software (CorelDRAW? AutoCAD? Sodipodi?)

neither of these were satisfying and/or easy, so I decided for:

3) write a little program to draw this for me!

and the choice was obvious. the morning after, the first thing I've done (in the first 20 minutes of just another boring workday) was tao.pl. I coded, I hacked, I ran it. I saw the result and it was good :-)

here you find the latest (re)incarnation of my 20-minutes script, beautified just a little for your viewing pleasure. a "proof of concept" page showing the produced images is at http://dada.perl.it/tao.html.

#!perl -w # note: should be saved as tao.pl use strict; use GD; use Getopt::Long; use vars qw( $PARTS $DIM $HELP ); GetOptions( 'parts=i' => \$PARTS, 'dimension=i' => \$DIM, 'help!' => \$HELP, ) or warn(qq(try "$0 --help"\n)), exit(1); if($HELP) { print usage(); exit(0); } $DIM ||= 500; $PARTS ||= 2; # zero is balance of powers anyway. my $arcw = $DIM/$PARTS; my $TAO = GD::Image->new($DIM, $DIM); my $yin = $TAO->colorAllocate(0x00, 0x00, 0x00); my $yang = $TAO->colorAllocate(0xFF, 0xFF, 0xFF); my @shade = (); foreach (0..$PARTS) { push(@shade, $TAO->colorAllocate( ( 255 * ($_+1) / ($PARTS+1) ) x 3 )); } $TAO->filledRectangle( 0, 0, $DIM, $DIM, $yang ); foreach my $arc (1..$PARTS) { $TAO->arc( ($arc*$arcw)/2, $DIM/2, $arc*$arcw, $arc*$arcw, 180, 0, $yin ); } foreach my $arc (1..$PARTS) { $TAO->arc( $DIM-($arc*$arcw)/2, $DIM/2, $arc*$arcw, $arc*$arcw, 0, 180, $yin ); } foreach my $arc (1..$PARTS-2) { $TAO->fill( $arcw/2+$arc*$arcw, $DIM/2, $shade[$arc-1] ); $TAO->arc( $arcw/2+$arc*$arcw, $DIM/2, $arcw/5, $arcw/5, 0, 360, $shade[$PARTS-$arc-1] ); $TAO->fill( $arcw/2+$arc*$arcw, $DIM/2, $shade[$PARTS-$arc-1] ); } $TAO->fill( $arcw/2-$arcw/5-2, $DIM/2, $yin ); $TAO->arc( $arcw/2, $DIM/2, $arcw/5+1, $arcw/5+1, 0, 360, $yang ); $TAO->fill( $arcw/2, $DIM/2, $yang ); $TAO->arc( $DIM-$arcw/2, $DIM/2, $arcw/5, $arcw/5, 0, 360, $yin ); $TAO->fill( $DIM-$arcw/2, $DIM/2, $yin ); open TAO, ">tao-$PARTS.png"; binmode TAO; print TAO $TAO->png(); close TAO; print "take a look at tao-$PARTS.png. have a nice day -- dada.\n"; sub usage { <<EOF; $0 (c) 2003 Aldo Calpini <dada\@perl.it> usage: $0 [OPTIONS] options: -d=N (--dimension=N) width and height, in pixels, of the resulting image. -p=N (--parts=N) number of parts (2 for a "regular" tao image). -h (--help) show this text. the defaults, if OPTIONS are not specified, are: -d=500 -p=2 output will be saved in "tao-N.png", where N is the value of the -p option. EOF }

update: removed some silliness (just realized that $x/($x/$y) is $y).

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris


In reply to tao degradation by dada

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.