aboutsummaryrefslogtreecommitdiff
path: root/challenge-165
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-165')
-rw-r--r--challenge-165/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-165/laurent-rosenfeld/perl/ch-1.pl35
-rw-r--r--challenge-165/laurent-rosenfeld/raku/ch-1.raku38
3 files changed, 74 insertions, 0 deletions
diff --git a/challenge-165/laurent-rosenfeld/blog1.txt b/challenge-165/laurent-rosenfeld/blog1.txt
new file mode 100644
index 0000000000..ca12e04afb
--- /dev/null
+++ b/challenge-165/laurent-rosenfeld/blog1.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/laurent_r/2022/05/perl-weekly-challenge-165-scalable-vestor-graphics.html
diff --git a/challenge-165/laurent-rosenfeld/perl/ch-1.pl b/challenge-165/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..0f047872f7
--- /dev/null
+++ b/challenge-165/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+use feature "say";
+use constant SCALE => 5;
+
+my ( @points, @lines);
+my $out = qq{<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"
+xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="500">\n};
+my @input = qw<53,10 53,10,23,30 23,30 34,35,36>;
+for my $val (@input) {
+ my @items = split /,/, $val;
+ # say "@items";
+ if (@items == 2) {
+ make_point(@items)
+ } elsif (@items == 4) {
+ make_line(@items);
+ } else {
+ warn "Error on item ", @items;
+ }
+}
+$out .= "</svg>";
+say $out;
+
+sub make_point {
+ my @dots = map $_ * SCALE, @_;
+ my $point = qq{<circle cx= "$dots[0]" cy="$dots[1]" r="3" fill="forestgreen"/>\n};
+ $out .= $point;
+}
+
+sub make_line {
+ my @dots = map $_ * SCALE, @_;
+ my $line = qq{<line x1="$dots[0]" y1="$dots[1]" x2="$dots[2]" y2="$dots[3]" };
+ $line .= qq{stroke="navy" />\n};
+ $out .= $line
+}
diff --git a/challenge-165/laurent-rosenfeld/raku/ch-1.raku b/challenge-165/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..4fb50d256c
--- /dev/null
+++ b/challenge-165/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,38 @@
+use SVG;
+my \SCALE = 5;
+
+my ( @points, @lines);
+my @input = <53,10 53,10,23,30 23,30 34,35,36>;
+for @input -> $val {
+ my @items = split /','/, $val;
+ if @items.elems == 2 {
+ make-point(@items)
+ } elsif @items.elems == 4 {
+ make-line(@items);
+ } else {
+ note "Error on item ", @items;
+ }
+}
+
+say ( SVG.serialize(svg => [ width => 500, height => 500, |@points, |@lines ] ));
+
+sub make-point (@dots) {
+ @dots = map { $_ * SCALE }, @dots;
+ my $point = circle =>
+ [ cx => @dots[0],
+ cy => @dots[1],
+ r => 3,
+ fill => 'forestgreen' ];
+ push @points, $point;
+}
+
+sub make-line (@dots) {
+ @dots = map { $_ * SCALE }, @dots;
+ my $line = line =>
+ [ x1 => @dots[0],
+ y1 => @dots[1],
+ x2 => @dots[2],
+ y2 => @dots[3],
+ stroke => 'navy' ];
+ push @lines, $line;
+}