topical media & game development

talk show tell print

#graphic-flex-image-effects-07-Flex-Patterns.ax

#graphic-flex-image-effects-07-Flex-Patterns.ax [swf] [flash] flex


  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 @ax-graphic-flex-image-effects-07-Flex-Patterns extends Sprite {
  
                  
Constructor. Draws two aether textures to bitmap data.

  
                  public function @ax-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.<int> = new Vector.<int>();
                          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.<Number> = new Vector.<Number>();
                          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.<IGraphicsData> = new Vector.<IGraphicsData>();
                          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));
                  }
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.