-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal.pl
47 lines (37 loc) · 1.02 KB
/
signal.pl
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 -w
use strict;
use warnings;
use Time::HiRes qw(usleep);
sub signal {
my ($t) = @_;
my $y = sin($t) + rand(.2) - .1;
return ($y < -1 ? -1 : ($y >= 1 ? 1 : $y));
}
my $t = 0;
my $signal_columns = 70;
my $text_columns = 40;
my @chars = ("A".."Z", "a".."z", '0'..'9', ' ');
my $rate_max = .05;
my $rate = rand $rate_max;
my $oldcol = -1;
my $iterations = 0;
while (1) {
if ($iterations > 100) {
$rate = rand $rate_max;
$iterations = 0;
}
$t += $rate;
my $col = int(((signal($t) + 1) / 2) * $signal_columns);
#my $char = ( $oldcol < $col ? '\\' : ( $oldcol > $col ? '/' : '|'));
my $char = $chars[rand @chars];
$oldcol = $col;
my $leading_columns = ($col-1);
my $trailing_columns = ($signal_columns - $leading_columns - 1);
my $signal_str = (" " x $leading_columns) . $char . (" " x $trailing_columns) . "|";
my $random_str = "";
$random_str .= $chars[rand @chars] for 1..$text_columns;
my $str = $signal_str . $random_str . "\n";
print $str;
usleep(1000);
++$iterations;
}