1#!/usr/bin/perl -w
2
3use lib qw(blib/lib blib/arch);
4
5use Imager;
6use Imager::Plot;
7
8Imager::Font->priorities(qw(w32 ft2 tt t1));
9
10@X  = linspace(-5, 10, 100);
11@Y  = map { sin($_) } @X;
12@XY = map { [$_, sin($_/2)+sin($_/4) ] } linspace(-2, 13, 15);
13
14$plot = Imager::Plot->new(Width  => 600,
15			  Height => 400,
16                          LeftMargin   => 40,
17                          BottomMargin => 40,
18                          TopMargin => 30,
19			  GlobalFont => get_font() );
20
21$plot->GetAxis()->{XgridShow} = 0;
22$plot->GetAxis()->{YgridShow} = 0;
23
24$plot->AddDataSet(X  => \@X, Y => \@Y);
25$plot->AddDataSet(XY => \@XY, style=>{marker=>{size=>4,
26					       symbol=>'circle',
27					       color=>Imager::Color->new(90,90,90),
28					      },
29				      line=>{
30					     color=>Imager::Color->new(255,0,0)
31					    }
32				     });
33
34
35$plot->GetAxis()->{BackGround} = undef;
36
37$plot->Set(Xlabel=> "time [sec]" );
38$plot->Set(Ylabel=> "Amplitude [mV]" );
39$plot->Set(Title => "Patheticity measured in millivolts" );
40
41$img = Imager->new(xsize=>600, ysize => 400)->box(filled=>1, color=>Imager::Color->new(190,220,255));
42
43$plot->Render(Image => $img, Xoff =>0+2, Yoff => 400+3);
44
45$new = $img->convert(matrix=>[ [ 0.6, 0.3, 0.3 ],
46			       [ 0.3, 0.6, 0.3 ],
47			       [ 0.3, 0.3, 0.6 ] ]);
48
49$new->filter(type=>'gaussian', stddev => 2.5) or die $new->errstr;
50
51$plot->Render(Image => $new, Xoff =>0, Yoff => 400);
52
53mkdir("sampleout", 0777) unless -d "sampleout";
54$new->write(file => "sampleout/sample2.ppm");
55
56
57
58
59
60
61sub linspace {
62  my ($min,$max,$N) = @_;
63  map { $_ * ($max-$min) / ($N-1) + $min } 0..$N-1;
64}
65
66
67sub get_font {
68  my %opts = (size=>12, color=>Imager::Color->new('black'));
69
70  my $font = Imager::Font->new(file=>"ImUgly.ttf", %opts)
71    || Imager::Font->new(file=>"./dcr10.pfb", %opts);
72  die "Couldn't load any font!\n" unless $font;
73
74  return $font;
75}
76