In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

グラデーションテクスチャーデモ

dot texture gradation demo
マウスの動きに反応してグラデーションが動くだけ
@author naoto koshikawa
package
{
  import caurina.transitions.Tweener;
  import flash.display.BitmapData;
  import flash.display.BlendMode;
  import flash.display.GradientType;
  import flash.display.Shape;
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.geom.Matrix;
  
  [SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "60")]
  /**
   * dot texture gradation demo
   * マウスの動きに反応してグラデーションが動くだけ
   * @author naoto koshikawa
   */
  public class Demo5 extends Sprite
  {
    private var _dot:Sprite;
    private var _gradation:Shape;
    
    public function Demo5() 
    {
      // ドットテクスチャーを作成
      var dotBitmapData:BitmapData = new BitmapData(2, 2, true, 0);
      dotBitmapData.setPixel32(0, 0, 0xFF000000);
      
      // ドキュメントクラスなのでSpriteで全面を覆い、マウスに反応するようにする
      _dot = new Sprite();
      _dot.graphics.beginBitmapFill(dotBitmapData);
      _dot.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
      addChild(_dot);
      
      // グラデーション作成
      var graMatrix:Matrix = new Matrix();
      graMatrix.createGradientBox(stage.stageWidth * 4, stage.stageHeight * 4, Math.PI/4, 0, 0);
      _gradation = new Shape();
      _gradation.graphics.beginGradientFill(
        GradientType.LINEAR,
        [0xFF0000, 0xFF9900, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF],
        [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
        [0, 51, 102, 153, 204, 255],
        graMatrix
      );
      _gradation.graphics.drawRect(0, 0, stage.stageWidth * 4, stage.stageHeight * 4);
      
      // ブレンドモードをスクリーンにして、黒いところだけ表示
      _gradation.blendMode = BlendMode.SCREEN;
      _gradation.x = -stage.stageWidth;
      _gradation.y = -stage.stageHeight;
      addChild(_gradation);
      
      addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    }
    
    private function mouseMoveHandler(event:MouseEvent):void
    {
      Tweener.removeTweens(_gradation);
      Tweener.addTween(_gradation, 
        {
          x:(mouseX - stage.stageWidth)*2,
          y:(mouseY - stage.stageHeight) * 2,
          delay:0.3,
          time:5, 
          transition:"easeOutExpo"
        }
      );
    }
  }
}