File: graph.pl

package info (click to toggle)
libhipi-perl 0.93-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 20,048 kB
  • sloc: perl: 471,917; ansic: 22; makefile: 10
file content (47 lines) | stat: -rwxr-xr-x 937 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use strict;
use warnings;

use HiPi::Interface::MicroDotPHAT;

my $phat = HiPi::Interface::MicroDotPHAT->new();

print q(Graph
Plots random numbers scross the screen in a bar graph.
Press Ctrl+C to exit.
);

my @graph = ();
my $filled = 1;

while(1) {
    $phat->clear();
    push @graph, int(rand(7));
    
    while( @graph > 45 ) {
        shift @graph;
    }
    
    for (my $x = 0; $x < @graph; $x ++ ) {
        if ($filled ) {
            # bar graph
            $phat->set_col($x + ($phat->width- scalar @graph ), (
                0,
                0b1000000,
                0b1100000,
                0b1110000,
                0b1111000,
                0b1111100,
                0b1111110,
                0b1111111)[$graph[$x]] );
        } else {
            # plot
            $phat->set_col($x, 1 << ( 7 -  $graph[$x] ));
        }
    }

    $phat->show();
    $phat->sleep_milliseconds( 50 );
}

1;