File: advanced_scrolling.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 (78 lines) | stat: -rwxr-xr-x 2,129 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict;
use warnings;

use HiPi::Interface::MicroDotPHAT;

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

print q(Advanced Scrolling
Advanced scrolling example which displays a message line-by-line
and then skips back to the beginning.
Press Ctrl+C to exit.
);

my $rewind = 1;
my $delay = 30;

my $line_height = $phat->height + 2;
my $offset_left = 0;

my @lines = ("Fifteen men on the dead man's chest",
         "Yo ho ho, and a bottle of rum!",
         "Drink and the devil had done for the rest",
         "Yo ho ho, and a bottle of rum!",
         "But one man of her crew alive,",
         "Yo ho ho, and a bottle of rum!",
         "What put to sea with seventy-five",
         "Yo ho ho, and a bottle of rum!");

my $numlines = scalar( @lines );

my @lengths = ( 0 ) x $numlines;


for (my $i = 0; $i < @lines; $i ++ ) {
    $lengths[$i] = $phat->write_string( $lines[$i], $offset_left, $line_height * $i );
    $offset_left += $lengths[$i];
}

my $current_line = 0;
$phat->show;

while (1) {
    my $starttime = time;
    my $pos_x = 0;
    my $pos_y = 0;
    for ( my $current_line = 0; $current_line < $numlines; $current_line ++) {
        $phat->sleep_milliseconds( $delay * 10 );
        for (my $y = 0; $y < $lengths[$current_line]; $y ++) { 
            $phat->scroll(1,0);
            $pos_x += 1;
            $phat->sleep_milliseconds( $delay );
            $phat->show();
        }
        if ( $current_line == $numlines - 1 && $rewind ) {
            for ( my $y = 0; $y < $pos_y; $y ++ ) {
                $phat->scroll(- int($pos_x/$pos_y), - 1);
                $phat->show();
                $phat->sleep_milliseconds( $delay );
            }
            $phat->scroll_to(0,0);
            $phat->show();
            $phat->sleep_milliseconds( $delay );
            my $endtime = time;
            $starttime = time;
        } else {
            for (my $i = 0; $i < $line_height; $i++) {
                $phat->scroll(0,1);
                $pos_y += 1;
                $phat->show();
                $phat->sleep_milliseconds( $delay );
            }
        }
    }
    
}

1;