File talk:Euler brick.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Generated by Perl

[edit]

This SVG file and the one for the perfect Euler brick has been generated by the following Perl script. Please remove column one in order to run it. --Gfis (talk) 14:44, 13 July 2015 (UTC)[reply]

#!perl
# generate SVG for Euler bricks
# 2015-07-13, Dr. Georg Fischer
#
# Usage:
#  perl gen_brick.pl [-perfect] > outfile
#-------------------------------------------
use strict;

my $opt = "";
if (scalar(@ARGV) > 0) {
   $opt = ucfirst(substr(shift(@ARGV), 1)) . " ";
}
my $margin = 10;
my $a = 44; 
my $skew = 0.7;
my $b = 117; my $bx = 88*$skew; my $by = 45*$skew;
my $c = 240;
my $width  = $margin*2 + $c + $bx;
my $height = $margin*2 + $a + $by;
my $xor = $margin + $bx;
my $yor = $margin + $a;
print <<"GFis";
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" 
   xmlns="http://www.w3.org/2000/svg" 
   xmlns:xlink="http://www.w3.org/1999/xlink" 
   x="0" y="0" width ="$width" height="$height" 
   viewBox="0 0 $width $height">
<title>$opt Euler brick</title>
GFis
# <rect style="stroke:green; fill:none" x="0" y="0" width="$width" height="$height" />
print <<"GFis";
<g transform="translate(0,0)" style="stroke:black;">
<g transform="scale(1)">
   <g>
       <path fill="wheat" d="M$xor $yor m-$bx $by m$c 0 l-$c 0 l0 -$a l$c 0 l0 $a l$bx -$by l0 -$a l-$c 0 l-$bx $by m$c 0 l$bx -$by" />
       <path fill="yellow" fill-opacity="0.2" d="M$xor $yor m-$bx $by m$c 0 l-$c -$a l$c 0 Z" />
       <path fill="red"    fill-opacity="0.2" d="M$xor $yor m-$bx $by m$c 0 l0 -$a l$bx -$by Z" />
       <path fill="blue"   fill-opacity="0.2" d="M$xor $yor m-$bx $by m0 -$a l$c 0 l$bx -$by Z" />
   </g>
   <g style="stroke-dasharray: 5 2;">
       <path fill="none" d="M$xor $yor l-$bx $by M$xor $yor l0 -$a M$xor $yor l$c 0" />
   </g>
GFis
       &text("a", $c - $margin, $a*0.65);
       &text("b", $c+$bx*0.1, -$by*0.3);
       &text("c", $c*0.8, -$margin*0.4);
       &text("d", $c+$bx*0.7, 0);
       &text("f", $c*0.6, -$by*0.55);
       &text("e", $c*0.4,  $a*0.65);
if ($opt !~ m{erfect}) {
   print "\n";
}
print <<"GFis";
</g>
</g>
</svg>
GFis
sub text {
   my ($letter, $tx, $ty, $stroke) = @_;
   if (length($stroke) <= 0) {
       $stroke = "black";
   }
   my $txo = $xor - $bx + $tx;
   my $tyo = $yor + $by - $a + $ty;
   print "\t\t<text x=\"$txo\" y=\"$tyo\" style=\"stroke: $stroke; font-family:Courier\">$letter</text>\n";
} # text