aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-028/dave-jacoby/blog.txt0
-rwxr-xr-xchallenge-028/dave-jacoby/perl5/ch-2.pl131
-rw-r--r--challenge-028/dave-jacoby/perl5/digital_clock.svg68
3 files changed, 199 insertions, 0 deletions
diff --git a/challenge-028/dave-jacoby/blog.txt b/challenge-028/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/challenge-028/dave-jacoby/blog.txt
diff --git a/challenge-028/dave-jacoby/perl5/ch-2.pl b/challenge-028/dave-jacoby/perl5/ch-2.pl
new file mode 100755
index 0000000000..27810d33f2
--- /dev/null
+++ b/challenge-028/dave-jacoby/perl5/ch-2.pl
@@ -0,0 +1,131 @@
+#!/usr/bin/env perl
+
+# This program displays the time
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+use Carp;
+use DateTime;
+use SVG;
+
+my $now = DateTime->now->set_time_zone('America/Indianapolis');
+
+ my $dark = '#333333';
+ my $lite = '#b0ec13';
+
+digital_clock( map { sprintf '%02d', $_ } $now->hour,
+ $now->minute, $now->second );
+
+sub digital_clock ( $h, $m, $s ) {
+
+ # create the SVG object
+ my $svg = SVG->new(
+ height => 230,
+ width => 800,
+ );
+
+ # use a rectangle to make the background dark
+ $svg->rectangle(
+ x => 0,
+ y => 0,
+ height => 230,
+ width => 800,
+ fill => '#222222',
+ );
+
+ # draw semicolons to separate hours from minutes from seconds
+ for my $x ( 530, 260 ) {
+ for my $y ( 70, 140 ) {
+ $svg->circle(
+ cx => $x,
+ cy => $y,
+ r => 8,
+ style => { fill => $lite }
+ );
+
+ }
+ }
+
+ # get separate numbers for separate segments
+ my ( $h1, $h2 ) = split //, $h;
+ my ( $m1, $m2 ) = split //, $m;
+ my ( $s1, $s2 ) = split //, $s;
+
+ #draw the segments
+ draw_digit( $svg, 10, 10, segments($h1) );
+ draw_digit( $svg, 140, 10, segments($h2) );
+
+ draw_digit( $svg, 280, 10, segments($m1) );
+ draw_digit( $svg, 410, 10, segments($m2) );
+
+ draw_digit( $svg, 550, 10, segments($s1) );
+ draw_digit( $svg, 680, 10, segments($s2) );
+
+ # export the file
+ my $output = $svg->xmlify;
+ my $file = 'digital_clock.svg';
+ if ( open my $fh, '>', $file ) {
+ print $fh $output;
+ close $fh;
+ }
+}
+
+sub draw_digit ( $svg, $x, $y, @s ) {
+
+ # the abstract endpoints of each segment
+ # offset by the passed-in x and y coordinates
+ # x1,y1,x2,y2
+ my @segments;
+ push @segments, [ 0, 0, 100, 0 ];
+ push @segments, [ 0, 0, 0, 100 ];
+ push @segments, [ 100, 0, 100, 100 ];
+ push @segments, [ 0, 100, 100, 100 ];
+ push @segments, [ 0, 100, 0, 200 ];
+ push @segments, [ 100, 100, 100, 200 ];
+ push @segments, [ 0, 200, 100, 200 ];
+
+ my $group = $svg->group(
+ style => {
+ fill => 'none',
+ }
+ );
+ for my $segment ( 0 .. @segments ) {
+ next unless defined $segments[$segment];
+ my $stroke = $s[$segment] ? $lite : $dark;
+ my $x1 = $x + $segments[$segment][0];
+ my $y1 = $y + $segments[$segment][1];
+ my $x2 = $x + $segments[$segment][2];
+ my $y2 = $y + $segments[$segment][3];
+ $group->line(
+ x1 => $x1,
+ y1 => $y1,
+ x2 => $x2,
+ y2 => $y2,
+ style => {
+ stroke => $stroke,
+ 'stroke-width' => '10',
+ }
+ );
+ }
+
+}
+
+sub segments ( $d ) {
+ return ( 0, 1, 2, 3, 4, 5, 6 ) if 0;
+ return ( 1, 1, 1, 0, 1, 1, 1 ) if $d == 0;
+ return ( 0, 0, 1, 0, 0, 1, 0 ) if $d == 1;
+ return ( 1, 0, 1, 1, 1, 0, 1 ) if $d == 2;
+ return ( 1, 0, 1, 1, 0, 1, 1 ) if $d == 3;
+ return ( 0, 1, 1, 1, 0, 1, 0 ) if $d == 4;
+ return ( 1, 1, 0, 1, 0, 1, 1 ) if $d == 5;
+ return ( 1, 1, 0, 1, 1, 1, 1 ) if $d == 6;
+ return ( 1, 0, 1, 0, 0, 1, 0 ) if $d == 7;
+ return ( 1, 1, 1, 1, 1, 1, 1 ) if $d == 8;
+ return ( 1, 1, 1, 1, 0, 1, 0 ) if $d == 9;
+ croak 'Out of Range Number';
+}
diff --git a/challenge-028/dave-jacoby/perl5/digital_clock.svg b/challenge-028/dave-jacoby/perl5/digital_clock.svg
new file mode 100644
index 0000000000..8320b9ed03
--- /dev/null
+++ b/challenge-028/dave-jacoby/perl5/digital_clock.svg
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg height="230" width="800" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <rect fill="#222222" height="230" width="800" x="0" y="0" />
+ <circle cx="530" cy="70" r="8" style="fill: #b0ec13" />
+ <circle cx="530" cy="140" r="8" style="fill: #b0ec13" />
+ <circle cx="260" cy="70" r="8" style="fill: #b0ec13" />
+ <circle cx="260" cy="140" r="8" style="fill: #b0ec13" />
+ <g style="fill: none">
+ <line style="stroke: #333333; stroke-width: 10" x1="10" x2="110" y1="10" y2="10" />
+ <line style="stroke: #333333; stroke-width: 10" x1="10" x2="10" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="110" x2="110" y1="10" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="10" x2="110" y1="110" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="10" x2="10" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="110" x2="110" y1="110" y2="210" />
+ <line style="stroke: #333333; stroke-width: 10" x1="10" x2="110" y1="210" y2="210" />
+ </g>
+ <g style="fill: none">
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="140" x2="240" y1="10" y2="10" />
+ <line style="stroke: #333333; stroke-width: 10" x1="140" x2="140" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="240" x2="240" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="140" x2="240" y1="110" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="140" x2="140" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="240" x2="240" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="140" x2="240" y1="210" y2="210" />
+ </g>
+ <g style="fill: none">
+ <line style="stroke: #333333; stroke-width: 10" x1="280" x2="380" y1="10" y2="10" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="280" x2="280" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="380" x2="380" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="280" x2="380" y1="110" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="280" x2="280" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="380" x2="380" y1="110" y2="210" />
+ <line style="stroke: #333333; stroke-width: 10" x1="280" x2="380" y1="210" y2="210" />
+ </g>
+ <g style="fill: none">
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="410" x2="510" y1="10" y2="10" />
+ <line style="stroke: #333333; stroke-width: 10" x1="410" x2="410" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="510" x2="510" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="410" x2="510" y1="110" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="410" x2="410" y1="110" y2="210" />
+ <line style="stroke: #333333; stroke-width: 10" x1="510" x2="510" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="410" x2="510" y1="210" y2="210" />
+ </g>
+ <g style="fill: none">
+ <line style="stroke: #333333; stroke-width: 10" x1="550" x2="650" y1="10" y2="10" />
+ <line style="stroke: #333333; stroke-width: 10" x1="550" x2="550" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="650" x2="650" y1="10" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="550" x2="650" y1="110" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="550" x2="550" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="650" x2="650" y1="110" y2="210" />
+ <line style="stroke: #333333; stroke-width: 10" x1="550" x2="650" y1="210" y2="210" />
+ </g>
+ <g style="fill: none">
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="680" x2="780" y1="10" y2="10" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="680" x2="680" y1="10" y2="110" />
+ <line style="stroke: #333333; stroke-width: 10" x1="780" x2="780" y1="10" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="680" x2="780" y1="110" y2="110" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="680" x2="680" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="780" x2="780" y1="110" y2="210" />
+ <line style="stroke: #b0ec13; stroke-width: 10" x1="680" x2="780" y1="210" y2="210" />
+ </g>
+ <!--
+ Generated using the Perl SVG Module V2.84
+ by Ronan Oger
+ Info: http://www.roitsystems.com/
+ -->
+</svg> \ No newline at end of file