diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-01 15:59:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-01 15:59:52 +0100 |
| commit | 2579bf2e1e9d493d4a1d2c9d9a9f6e2d699273eb (patch) | |
| tree | 6fe862bc2967b461d6ce2481395c3f014816b1d9 | |
| parent | 8a6365fa79d7ddf641fbc2c7b679ebbeb92e0d61 (diff) | |
| parent | d3a90575d0a2af3786c2618a425f6fafcd63079e (diff) | |
| download | perlweeklychallenge-club-2579bf2e1e9d493d4a1d2c9d9a9f6e2d699273eb.tar.gz perlweeklychallenge-club-2579bf2e1e9d493d4a1d2c9d9a9f6e2d699273eb.tar.bz2 perlweeklychallenge-club-2579bf2e1e9d493d4a1d2c9d9a9f6e2d699273eb.zip | |
Merge pull request #699 from simbabque/master
Perl 5 solution for Challenge 28, Task 2.
| -rw-r--r-- | challenge-028/julien-fiegehenn/perl5/ch-2.pl | 67 | ||||
| -rw-r--r-- | challenge-028/julien-fiegehenn/perl5/cpanfile | 3 |
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-028/julien-fiegehenn/perl5/ch-2.pl b/challenge-028/julien-fiegehenn/perl5/ch-2.pl new file mode 100644 index 0000000000..fc6c1dce98 --- /dev/null +++ b/challenge-028/julien-fiegehenn/perl5/ch-2.pl @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Time::Piece; +use Term::ANSIScreen qw(cls locate); +use Term::ReadKey 'GetTerminalSize'; +use feature 'say'; + +# Write a script to display Digital Clock. +# Feel free to be as creative as you can when displaying digits. +# We expect bare minimum something like “14:10:11”. + +my %alphabet = ( + 1 => [" 11", " 11", " 11", " 11", " 11"], # This matrix holds the digits of our + 2 => ["222222", " 22", "222222", "22 ", "222222"], # digital clock. Each digit contains + 3 => ["333333", " 33", "333333", " 33", "333333"], # five sets of strings, which will be + 4 => ["44 44", "44 44", "444444", " 44", " 44"], # transposed into rows further down in + 5 => ["555555", "55 ", "555555", " 55", "555555"], # the code. They look confusing here + 6 => ["666666", " 66", "666666", "66 66", "666666"], # because the code is indented to be + 7 => ["777777", " 77", " 77", " 77", " 77"], # more compact. See below the __END__ + 8 => ["888888", "88 88", "888888", "88 88", "888888"], # section for a more readable example + 9 => ["999999", "99 99", "999999", " 99", "999999"], # of what this looked like before I + 0 => ["000000", "00 00", "00 00", "00 00", "000000"], # ran perltidy on it. + ':' => [" ", " :: ", " ", " :: ", " "], +); + +# This is our main loop. Note while () is equivalent to while (1). +while () { + + # clear the screen after every frame + cls(); + + # Grab the screen size and half it so we can start from (roughly) the middle. + # Doing that in the loop means we can handle resizing of the terminal during run time. + my ($x, $y) = map { int $_ / 2 } GetTerminalSize(); + + my @letters = split //, localtime->hms; + + # Each row is represented by a column above in the hash with our alphabet. + foreach my $row (0 .. 4) { + + # Our "digits" are 6 characters wide and there are 8 of them, plus 1 space after + # all but the last. That gives us 62 characters in total, so we move half of that + # to the left from the centre of the screen to start writing. + + # The "digits" are 5 characters high, so we start off at 2 characters above the + # middle of the screen. + locate($y + ($row - 2), $x - 31); + say map { $alphabet{$_}->[$row] . q{ } } @letters; + } + + # I wonder how long this needs to run until it gets out of sync... + sleep 1; +} + +__END__ +" 11", +" 11", +" 11", +" 11", +" 11" + +"222222", +" 22", +"222222", +"22 ", +"222222"
\ No newline at end of file diff --git a/challenge-028/julien-fiegehenn/perl5/cpanfile b/challenge-028/julien-fiegehenn/perl5/cpanfile new file mode 100644 index 0000000000..155df901de --- /dev/null +++ b/challenge-028/julien-fiegehenn/perl5/cpanfile @@ -0,0 +1,3 @@ +requires 'Term::ANSIScreen'; +requires 'Term::ReadKey'; +requires 'Time::Piece'; |
