📄 transforms.java
字号:
/*
* Transforms.java
* Examples
*
* Created by Stuart MacKay on Fri Jul 25 2003.
* Copyright (c) 2001-2006 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.
*/
package com.flagstone.transform.examples;
import com.flagstone.transform.*;
import java.util.*;
/*
* The Transforms class illustrates the different coordinate and colour transforms
* that can be applied to an object to change its appearance without changing the
* original definition.
*
* To run this example, type the following on a command line:
*
* java Transforms [--resultDir path]
*
* where
*
* resultDir is the directory where the Flash file generated by the example is
* written to.
*
*/
public class Transforms extends Example
{
public static void main(String[] args)
{
new Transforms(args);
}
public Transforms(String[] args)
{
super(args);
createMovie();
writeFile("Transforms.swf");
}
void createMovie()
{
int width = 3200;
int height = 2400;
movie.setFrameRate(2.0f);
movie.setFrameSize(new FSBounds(0, 0, 16000, 8000));
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
/*
* Define the objects used to create the rectangle.
*/
int identifier = movie.newIdentifier();
FSBounds bounds = new FSBounds(-width/2, -height/2, width/2, height/2);
ArrayList lineStyles = new ArrayList();
ArrayList fillStyles = new ArrayList();
lineStyles.add(new FSSolidLine(1, FSColorTable.black()));
fillStyles.add(new FSSolidFill(FSColorTable.red()));
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));
FSDefineShape rectangle = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, new FSShape(shapeRecords));
movie.add(rectangle);
// Define variables for the different transforms that will be applied to the shape.
FSCoordTransform transform = null;
FSColorTransform colourTransform = null;
/*
* Both the FSPlaceObject and FSPlaceObject2 can be used to add an object
* to the display list and apply either a coordinate, color transform or
* both.
*
* The first example applies a simple translation transform to set the
* location of the object on the Flash Player's screen. Both classes
* provide constructors where the x and y coordinates are provided as
* arguments avoiding the need to explicitly create an FSCoordTransform
* object.
*/
transform = new FSCoordTransform(2000, 2000);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 1, transform));
movie.add(new FSShowFrame());
/*
* Scale the rectangle in both the x and y directions. The order of compositing the
* transforms is important. If the scale transform was the first argument then the
* coordinates would also be scaled.
*/
transform = new FSCoordTransform(5600, 2000);
transform.scale(0.6, 1.1);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 2, transform));
movie.add(new FSShowFrame());
/*
* Rotate the rectangle clockwise by the specified number of degrees.
*/
transform = new FSCoordTransform(9200, 2000);
transform.rotate(45.0);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 3, transform));
movie.add(new FSShowFrame());
/*
* Apply a shearing transform to both the x and y directions.
*/
transform = new FSCoordTransform(13600, 2000);
transform.shear(0.1, 0.2);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 4, transform));
movie.add(new FSShowFrame());
/*
* Change the colour of the rectangle. Here the terms are added to the
* colour defined for the solid fill style of the rectangle. A value
* for the alpha channel can also be specified - here it is omitted.
*/
transform = new FSCoordTransform(2000, 6000);
colourTransform = new FSColorTransform(-3100, 2560, 0);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 5, transform, colourTransform));
movie.add(new FSShowFrame());
/*
* Change the colour of the rectangle by changing the saturation of the colours
* by specifiying a multiplier for each channel. The alpha channel is omitted
* as the FSDefineShape class does not support transparent shapes.
*/
transform = new FSCoordTransform(6000, 6000);
colourTransform = new FSColorTransform(0.7f, 1.0f, 1.0f);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 6, transform, colourTransform));
movie.add(new FSShowFrame());
/*
* Both the add and mulriply transforms can be performed in a single step.
*/
transform = new FSCoordTransform(10000, 6000);
colourTransform = new FSColorTransform(0.9f, 1.0f, 1.0f, 0, 128, 128);
movie.add(new FSPlaceObject(rectangle.getIdentifier(), 7, transform, colourTransform));
movie.add(new FSShowFrame());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -