Tiny program to print out somewhat ASCII-artish graphs with "sensible" words, which in my case were qw/baci besos kisses/: it's thought as a sort of gift for a very special person who happens to be much mathematically inclined and talented, let alone artistically.

(The most relevant part of the code is in the process() sub, which in fact is run only once and thus may have been inlined instead. But I preferred to factor it away, so I'm perhaps slightly violating YAGNI, however it may make life easier for further developments.)

#!/usr/bin/perl use strict; use warnings; use constant { LEN => 75, PI => 3.14159265359 }; sub process; process [0, 2.3875*PI], [-1, 1], 382, baci => sub { cos(1/($_[0]+.05)**.5) }, besos => sub { -cos(1/($_[0]+.15)**.78) }, kisses => sub { sin($_[0]) }; sub process { my ($xr, $yr, $lines, %funcs)=@_; my $m=($xr->[1]-$xr->[0])/($lines-1); my $q=$xr->[0]-$m; my %m = map { $_ => (LEN-length)/($yr->[1]-$yr->[0]) } keys %funcs; my %q = map { $_ => -$m{$_} * $yr->[0] } keys %funcs; for (1..$lines) { my $x=$m*$_+$q; my @str = sort {length($b) <=> length($a)} map ' ' x ($m{$_} * $funcs{$_}($x) + $q{$_}) . $_, keys %funcs; my $base=shift @str; substr $base, 0, length, $_ for @str; print $base, "\n"; } } __END__

In reply to [ASCII art graphs] Kisses by blazar

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.