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__
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [ASCII art graphs] Kisses
by dewey (Pilgrim) on Jun 13, 2007 at 16:01 UTC | |
by ambrus (Abbot) on Jun 13, 2007 at 21:25 UTC | |
by blazar (Canon) on Jun 13, 2007 at 18:32 UTC |