#!/bin/perl
use Math::Trig;
# SVG Gosper curve generator by Blotwell
# Released under GFDL

BEGIN{ print <<HEREDOC
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    <svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
                width="320px" height="320px"
                         viewBox="100 500 2800 2800">
HEREDOC
;}
my $x=200, $y=2000, $a=90;
printf "<polyline points=\"%i,%i,",$x,$y;
sub p {printf "%i,%i,",$x,$y;}
sub fd {my $n=shift; $x+=$n*cos(deg2rad($a)); $y-=$n*sin(deg2rad($a)); p();}
sub tl {$a+=shift;}
sub rt {$a-=shift;}
my $ln=100;
rg(3);

sub gl
{my $st=-1+shift;
if ($st<0) {fd($ln);}
else {tl(60); rg($st); rt(60); gl($st); gl($st); rt(120);
gl($st); rt(60); rg($st); tl(120); rg($st); tl(60); gl($st);}}

sub rg
{my $st=-1+shift;
if ($st<0) {fd($ln);}
else {rg($st); rt(60); gl($st); rt(120); gl($st); tl(60);
rg($st); tl(120); rg($st); rg($st); tl(60); gl($st); rt(60);}}

END{print '" stroke="black" stroke-width="30" stroke-linejoin="round" fill-opacity="0" />',"\n</svg>\n";}
