File: transform.pl

package info (click to toggle)
libgd-perl 2.84-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,060 kB
  • sloc: perl: 2,693; pascal: 336; sh: 18; makefile: 9
file content (43 lines) | stat: -rwxr-xr-x 1,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/local/bin/perl

use GD;
use Math::Trig;

# test scaling, translation, transformation
$im = new GD::Image(380,225);
$black = $im->colorAllocate(0, 0, 0);
$white = $im->colorAllocate(255, 255, 255);        
$red = $im->colorAllocate(255, 0, 0);      
$blue = $im->colorAllocate(0,0,255);
$yellow = $im->colorAllocate(255,250,205);

# Create a triangle
$poly = new GD::Polygon;
$poly->toPt(50,50);
$poly->toPt(100,0);
$poly->toPt(-50,50);
$poly->toPt(-50,-50);

$im->filledPolygon($poly,$yellow);

# Stretch it a bit
#$poly->scale(1.8,1.0);
#$poly->offset(100,0);
#$im->filledPolygon($poly,$red);

# Rotate it (scale by 0.5,0.2, rotate by 0,1, move by -25,50)
#$poly->transform(0.5,0.2, 0,1, -25,50);
#$poly->scale(1.5);
$poly->rotate(deg2rad(45));
$poly->offset(50,100);
warn "blue: [", join(' ',$poly->bounds), "]";
$im->filledPolygon($poly,$blue);

$poly->rotate(deg2rad(-90));
$poly->offset(180,0);
warn "red:  [", join(' ',$poly->bounds), "]";
$im->filledPolygon($poly,$red);

binmode STDOUT;

print $im->png;