package { import aether.effects.common.CompositeEffect; import aether.effects.texture.TextureEffect; import aether.textures.patterns.GraphicsDataPattern; import aether.textures.patterns.PixelPattern; import flash.display.*; import flash.geom.Matrix; [SWF(width=400, height=400, backgroundColor=0x000000)] /** * Demonstrates the use of GraphicsDataPattern and PixelPattern in aether's * texture effects library. */ public class graphic_flex_image_effects_07_Flex_Patterns extends Sprite { /** * Constructor. Draws two aether textures to bitmap data. */ public function graphic_flex_image_effects_07_Flex_Patterns() { var bitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight); // four lineTo's are saved into path commands var pathCommands:Vector. = new Vector.(); pathCommands.push(GraphicsPathCommand.LINE_TO); pathCommands.push(GraphicsPathCommand.LINE_TO); pathCommands.push(GraphicsPathCommand.LINE_TO); pathCommands.push(GraphicsPathCommand.LINE_TO); // the coordinate data for four lineTo's are saved into path vector var path:Vector. = new Vector.(); path.push(50, 0); path.push(50, 50); path.push(0, 50); path.push(0, 0); // matrix to be used with a gradient fill var matrix:Matrix = new Matrix(); matrix.createGradientBox(50, 50, Math.PI/2); // all the graphics data for a gradient filled rect is added to a data vector var data:Vector. = new Vector.(); data.push(new GraphicsGradientFill(GradientType.LINEAR, [0, 0], [1, 0], [0, 255], matrix)); data.push(new GraphicsPath(pathCommands, path)); data.push(new GraphicsEndFill()); // this composite effect combines both a PixelPattern and a GraphicsDataPattern new CompositeEffect( [ new TextureEffect( // the PixelPattern colors individual pixels as laid out in a two dimensional array, then tiles it new PixelPattern( [ [0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFF000000], [0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFF000000], [0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000, 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFF000000], [0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFFFF0000, 0xFFFF0000, 0xFF000000, 0xFF000000, 0xFFFFFFFF], [0xFF000000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000, 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFF000000], [0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000, 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFF000000], [0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF000000, 0xFF000000, 0xFF000000] ] ) ), new TextureEffect( // the GraphicsDataPattern draws the graphics data passed, then tiles it new GraphicsDataPattern(data) ) ] ).apply(bitmapData); addChild(new Bitmap(bitmapData)); } } }