From: Vincent Pit Date: Thu, 22 Jul 2010 21:35:25 +0000 (+0200) Subject: Add a sample script X-Git-Tag: v0.01~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=f7b9f0d8c8d037ecb36c4d77aba3e7f202312f16 Add a sample script --- diff --git a/MANIFEST b/MANIFEST index f64fe45..bb50009 100644 --- a/MANIFEST +++ b/MANIFEST @@ -35,6 +35,7 @@ lib/LaTeX/TikZ/Set/Polyline.pm lib/LaTeX/TikZ/Set/Raw.pm lib/LaTeX/TikZ/Set/Rectangle.pm lib/LaTeX/TikZ/Set/Sequence.pm +samples/synopsis.pl t/00-load.t t/01-api.t t/10-set.t diff --git a/samples/synopsis.pl b/samples/synopsis.pl new file mode 100644 index 0000000..892e8bb --- /dev/null +++ b/samples/synopsis.pl @@ -0,0 +1,46 @@ +#!perl + +use strict; +use warnings; + +use blib; + +use LaTeX::TikZ; + +# A couple of lines +my $hline = Tikz->line(-1 => 1); +my $vline = Tikz->line([ 0, -1 ] => [ 0, -1 ]); + +# Paint them in red +$_->mod(Tikz->color('red')) for $hline, $vline; + +# An octogon +use Math::Complex; +my $octo = Tikz->closed_polyline( + map Math::Complex->emake(1, ($_ * pi)/4), 0 .. 7 +); + +# Only keep a portion of it +$octo->clip(Tikz->rectangle(-0.5*(1+i), 2*(1+i))); + +# Fill it with dots +$octo->mod(Tikz->pattern(class => 'Dots')); + +# Create a formatter object +my $tikz = Tikz->formatter; + +# Put those objects all together and print them +my $seq = Tikz->seq($octo, $hline, $vline); +my ($head, $decl, $body) = $tikz->render($seq); +my @lines = ( + "\\documentclass[12pt]{article}", + @$head, + "\\begin{document}", + "\\pagestyle{empty}", + @$decl, + "\\begin{center}", + @$body, + "\\end{center}", + "\\end{document}", +); +print "$_\n" for @lines;