dimar has asked for the wisdom of the Perl Monks concerning the following question:

The Goal:

A simple script, module or app that generates a list of plots and draws simple text representation of arbitrary curves; OR the acknowledgement that no such thing exists and I have to write it myself.

The Rationale:

The purpose is for a quick-and-dirty way to sketch curves and see what they look like in text before sending the plot points off to another program, without having to use any sophisticated packages like GD or the like. Since the functionality is very simple, the question is whether someone has already written something like this that has support for a wide variety of quick-and-simple family of curves, as well as a way to quickly sketch them out in text.

An Example:
### GetTrigCurve($iLength,$iAmplitude,$fFreq,$sType); my @aCurve = GetTrigCurve(30,48,100,'cos'); print GetPoints( [@aCurve] ) print DrawCurve( [@aCurve] ); __END__ 0,3,12,24,36,45,47,44,34,22,10,2,0,4,14,26,38,46,47,42,32,20,8,1,0,5,1 +6,28,40,46,47 ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

Replies are listed 'Best First'.
Re: No-Frills Curve Sketches
by injunjoel (Priest) on Jul 03, 2004 at 18:03 UTC
    Greetings all,
    Though I haven't written any such thing Im fairly positive Erudil has. Have a look at How to (ab)use substr and the spoiler SPOILER! (Guildenstern)Re: How to (ab)use substr for ideas on how to go about doing something similar (?: yes I realize this is an obfus post but perhaps you can harvest some of the ideas and methodologies). Who knows maybe you can roll it into an ascii graphing module for CPAN?

    Speaking of which did you try CPAN? (which, as a good rule of thumb is a good place to start :)

    -injunjoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

      Yes, CPAN was the first stop on this particular quest, however it seems the requested functionality is far too trivial, or the search effort wasn't up to snuff, as there does not appear to be anything on CPAN that quite fits the bill. Really all I am looking for is a group of standard functions like you can find with a msft Excel spreadsheet, that lets you plot out a few datapoints (like you can with a spreadsheet) all within the confines of perl.

        Greetings again,
        A not so quick search pulled up Text::Graph which might help get you part of the way there.
        I would be interested to see what exactly you come up with in terms of your solution, Im sure there are people who would use it.
        HTH.

        -injunjoel
        "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
Re: No-Frills Curve Sketches
by YuckFoo (Abbot) on Jul 06, 2004 at 23:06 UTC
    Here is my graph program. Reads from STDIN and splits on whitespace. The first field is the label and the second field gets plotted. You did say no frills right?

    YuckFrill

    Example:

    perl -e 'print "$_ " . sin($_ / 10) . "\n" for (1..64)' | graph.pl
    #!/usr/bin/perl use strict; my ($WIDE) = @ARGV; $WIDE ||= 80; my (@list, $min, $max); my ($maxval, $maxkey); while (my $line = <STDIN>) { chomp $line; my ($key, $val) = split(' ', $line); if (defined($key) && defined($val)) { push (@list, { key => $key, val => $val}); if (!defined($min) || $val < $min) { $min = $val; } if (!defined($max) || $val > $max) { $max = $val; } if (!defined($maxkey) || length($key) > $maxkey) { $maxkey = length($key); } if (!defined($maxval) || length($val) > $maxval) { $maxval = length($val); } } } my $factor = ($max - $min) / ($WIDE - $maxkey - $maxval - 2); for my $i (@list) { printf STDOUT "%-*.*s %s $i->{val}\n", $maxkey, $maxkey, $i->{key}, '*' x (($i->{val} - $min) / $factor +); }