1#!/usr/bin/perl
2
3use SWF::File;
4
5my $swf = SWF::File->new;
6
7# Set the frame size and rate.
8
9$swf->FrameSize(0, 0, 400, 400);
10$swf->FrameRate(30);
11
12# At first, you should set background color.
13
14SWF::Element::Tag::SetBackgroundColor->new(
15    BackgroundColor => [
16      Red => 255,
17      Green => 255,
18      Blue => 255,     # white
19    ],
20)->pack($swf);
21
22# Define the pink, half-transparent rectangle.
23
24SWF::Element::Tag::DefineShape3->new(
25    ShapeID => 1,
26    ShapeBounds =>   # A region of the shape.
27    [                # Minimum and maximum coordinates adjusted with the line width.
28      Xmin => -25-4,
29      Ymin => -18-4,
30      Xmax => 25+4,
31      Ymax => 18+4,
32    ],
33    Shapes => [
34     LineStyles => [
35      [ Width => 7,
36        Color => [
37	  Red => 255,
38	  Green => 95,
39	  Blue => 174,
40	  Alpha => 128 ]
41	]
42      ],
43     ShapeRecords => [
44      [ MoveDeltaX => -25, MoveDeltaY => -18, LineStyle => 1 ],
45      [ DeltaX => 50 ],
46      [ DeltaY => 36 ],
47      [ DeltaX => -50 ],
48      [ DeltaY => -36 ],
49     ],
50    ],
51)->pack($swf);
52
53my $sf = SWF::Element::Tag::ShowFrame->new;
54
55# Set the matrix for the rectangle with position (0,200) and 10 times magnification.
56
57my $matrix1 = SWF::Element::MATRIX->new->moveto(0,200)->scale(10);
58
59# Set the another matrix with position (400,200) and 10 times magnification.
60
61my $matrix2 = SWF::Element::MATRIX->new->moveto(400,200)->scale(10);
62
63# place the rectangle to (0,200) of depth 1.
64
65SWF::Element::Tag::PlaceObject2->new(
66    Depth => 1,
67    CharacterID => 1,
68    Matrix => $matrix1,
69)->pack($swf);
70
71# place the another rectangle to (400,200) of depth 2 with color change.
72
73SWF::Element::Tag::PlaceObject2->new(
74    Depth => 2,
75    CharacterID => 1,
76    Matrix => $matrix2,
77    ColorTransform => [
78      RedMultTerm => 0,      # Red = 255*0/255 = 0
79      GreenMultTerm => 255,  # Green = 95*255/255 = 95
80      BlueMultTerm => 0,     # Blue = 174*0/255 = 174
81      AlphaMultTerm => 255,  # Alpha = 128*255/255 = 128
82    ]
83)->pack($swf);
84
85# show frame
86
87$sf->pack($swf);
88
89# Keep PlaceObject2 tags to move.
90
91my $po1 = SWF::Element::Tag::PlaceObject2->new(
92        PlaceFlagMove => 1,
93        Depth => 1,
94        Matrix => $matrix1,
95   );
96my $po2 = SWF::Element::Tag::PlaceObject2->new(
97        PlaceFlagMove => 1,
98        Depth => 2,
99        Matrix => $matrix2,
100   );
101
102
103for($x=0; $x<100; $x++) {
104
105# move, rotate, and reduce the rectangles' matrix.
106    $matrix1->moveto($x*5,200)->rotate(15)->scale(.95);
107    $matrix2->moveto(400-$x*5,200)->rotate(-15)->scale(.95);
108# place the rectangles.
109    $po1->pack($swf);
110    $po2->pack($swf);
111# show frame.
112    $sf->pack($swf);
113}
114
115SWF::Element::Tag::End->new->pack($swf);
116$swf->close('sample.swf');
117