/*
* ChangeSize.java
* Cookbook
*
* Copyright (c) 2001-2009 Flagstone Software Ltd. All rights reserved.
*
* This code is distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND Flagstone HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
*/
import com.flagstone.transform.*;
import java.util.*;
/*
* This example shows how to change the size of a shape:
*
* To run this example, type the following on a command line:
*
* java -cp cookbook.jar ChangeSize file-out
*
* where
*
* file-out is the path where the file will be written. If no output file
* is specified then a file named after the example will be written to the
* current directory.
*/
public class ChangeSize
{
public static void main(String[] args)
{
try
{
String out = args.length == 0 ? "ChangeSize.swf" : args[0];
ChangeSize example = new ChangeSize();
FSMovie movie = new FSMovie();
example.createMovie(movie);
movie.encodeToFile(out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
void createMovie(FSMovie movie)
{
int xLower = 0;
int yLower = 0;
int xUpper = 8000;
int yUpper = 8000;
float framesPerSecond = 12.0f;
movie.setFrameRate(framesPerSecond);
movie.setFrameSize(new FSBounds(xLower, yLower, xUpper, yUpper));
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
FSDefineShape rectangle = createRectangle(movie);
movie.add(rectangle);
movie.add(new FSPlaceObject2(rectangle.getIdentifier(), 1, 4000, 4000));
movie.add(FSShowFrame.getInstance());
double scaleX = 1.0;
double scaleY = 1.0;
for (int i=0; i<10; i++)
{
scaleX *= 1.1;
scaleY *= 1.1;
movie.add(new FSPlaceObject2(1, new FSCoordTransform(4000, 4000, scaleX, scaleY)));
movie.add(FSShowFrame.getInstance());
}
for (int i=0; i<10; i++)
{
scaleX *= 0.9;
scaleY *= 0.9;
movie.add(new FSPlaceObject2(1, new FSCoordTransform(4000, 4000, scaleX, scaleY)));
movie.add(FSShowFrame.getInstance());
}
}
private FSDefineShape createRectangle(FSMovie movie)
{
int identifier = movie.newIdentifier();
int width = 2000;
int height = 2000;
FSBounds bounds = new FSBounds(-1000, -1000, 1000, 1000);
ArrayList lineStyles = new ArrayList();
ArrayList fillStyles = new ArrayList();
lineStyles.add(new FSSolidLine(20, FSColorTable.black()));
fillStyles.add(new FSSolidFill(FSColorTable.red()));
/*
* Create the outline of the shape.
*/
ArrayList shapeRecords = new ArrayList();
shapeRecords.add(new FSShapeStyle(1, 1, 0, -width/2, -height/2));
shapeRecords.add(new FSLine(width, 0));
shapeRecords.add(new FSLine(0, height));
shapeRecords.add(new FSLine(-width, 0));
shapeRecords.add(new FSLine(0, -height));
return new FSDefineShape(identifier, bounds, fillStyles, lineStyles, new FSShape(shapeRecords));
}
}