This script is a close variant of Re^2: [ASCII art graphs] Kisses. It's drawing Lissajous curves in ascii-art.

Big thanks to dewey and blazar who gave me the idea in that thread.

#!perl use warnings; use strict; sub pie() { 2 * atan2(1, 0); } sub asin { atan2($_[0], sqrt(1 - $_[0]**2)); } sub liss { my($p_m, $p_n, $p_d) = @_; my($ht, $wd) = (24, 60); my $ou; for my $l (0 .. 2 * $ht - 1) { 0 == $l % 2 and $ou = " " x ($wd + 1); my($y0, $y1) = (2 * $l / (2 * $ht) - 1, 2 * ($l + 1) / (2 * $h +t) - 1); my($su0, $su1) = (asin($y0), asin($y1)); for my $br (0 .. $p_m - 1) { for my $sgn (0, 1) { my($u0, $u1) = ($br * 2 * pie + $sgn * pie + $su0 * ($sgn?-1:1), +$br * 2 * pie + $sgn * pie + $su1 * ($sgn?-1:1)); my($v0, $v1) = ($u0 / $p_m * $p_n + $p_d, $u1 / $p_m * + $p_n + $p_d); my($x0, $x1) = (sin($v0), sin($v1)); $x1 < $x0 and ($x0, $x1) = ($x1, $x0); int(($v0 - pie / 2) / 2 / pie) == int(($v1 - pie / 2) +/ 2 / pie) or $x1 = 1; int(($v0 + pie / 2) / 2 / pie) == int(($v1 + pie / 2) +/ 2 / pie) or $x1 = -1; my($p0, $p1) = (($x0 + 1) / 2 * $wd, ($x1 + 1) / 2 * $ +wd); my ($ps, $pd) = int($p0) < int($p1) ? (int($p0), int($p1) - int($p0)) : (int(($p0 + $p1 + 1) / 2), 1); my $repl = \substr($ou, $p0, $pd); 0 == $l % 2 ? $$repl =~ y/ /'/ : $$repl =~ y/ '/,;/; } } 1 == $l % 2 and print $ou, "\n"; } } for (0 .. 19) { print "\n" x 4; my $r = sub { int(1 - log(1-rand(0.999)) / $_[0]) }; my($m, $n) = (&$r(0.7), &$r(0.9)); liss $m, $n, rand(2*pie); sleep 3; } __END__

Here's an example output:

,'''', ,'''''', ,'', ; ', ,' ', ,' ', ; ; ; ; ; ; ; ; ; ', ; ; ; ; ; ', ,' ; ; ', ; ', ; ; ; ',; ', ; ; ; ;' ; ,' ; ; ,'; ; ; ; ; ; ; ; ; ; ; ; ', ; ,' ; ; ,' ', ', ; ; ; ; ; ; ; ; ; ; ; ; ,' ; ; ,' ', ; ; ; ; ; ', ',; ; ; ; ', ;, ,' ; ,' ; ,'; ; ; ; ; ,' ; ; ; ; ; ,' ; ,' ; ,' ; ,' ', ; ; ; ', ,' ', ,' ; ; ', ,' ', ; ;,' ',,,,,,' ;,,,'

Update: liverpole pointed out to Spiro Japh, his obfu that's also producing Lissajous curves.


In reply to Lissajous curves by ambrus

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.