※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : katapad's な~るほど ザ!ワ… [diff(3)]

FORKED
  1. // forked from midisheep's forked from: な~るほど ザ!ワ…
  2. // forked from katapad's な~るほど ザ!ワ…
  3. // forked from katapad's おまえの母ちゃん…
  4. package  
  5. {
  6.     import caurina.transitions.Tweener;
  7.     import flash.display.*;
  8.     import flash.events.Event;
  9.     import flash.events.MouseEvent;
  10.     import flash.filters.BlurFilter;
  11.     import flash.geom.Matrix;
  12.     import flash.geom.Point;
  13.     import flash.geom.Rectangle;
  14.     import flash.text.TextField;
  15.     import flash.text.TextFieldAutoSize;
  16.     import flash.text.TextFormat;
  17.     
  18.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
  19.     /**
  20.      * ...
  21.      * @author katapad
  22.      * @version 0.2
  23.      * @since 2008/12/23 23:55
  24.      */
  25.     public class LEDSignMainNaruhodo extends Sprite 
  26.     {
  27.         
  28.         //----------------------------------
  29.         //  static var/const
  30.         //----------------------------------
  31.         //public static const DEBUG_MOODE:Boolean = true;
  32.         public static const DEBUG_MOODE:Boolean = false;
  33.         public static const STAGE_WIDTH:uint = 465;
  34.         public static const STAGE_HEIGHT:uint = 465;
  35.         
  36.         public static const LED_CONTAINER_WIDTH:uint = 464;
  37.         public static const LED_CONTAINER_HEIGHT:uint = 464;
  38.         
  39.         public static const LED_MARGIN:uint = 2;
  40.         public static const LED_RADIUS:uint = 3;
  41.         
  42.         public static const ROWS:uint = 15;
  43.         
  44.         public static const ANIMATION_SPEED:Number = 0.02;
  45.         private static const DEFAULT_TEXTFORMAT:TextFormat = new TextFormat("_等幅"12, 0xFFFFFF, false);
  46.         //----------------------------------
  47.         //  instance var 
  48.         //----------------------------------
  49.         private var _ledContainer:Sprite;
  50.         private var _ledList:Array;
  51.         private var _canvas:Sprite;
  52.         private var _canvasDrawBM:BitmapData;
  53.         private var _resetBMRect:Rectangle;
  54.         private var _drawMatrix:Matrix = new Matrix();
  55.         private var _tfList:/*TextField*/Array;
  56.         private var _square:Shape;
  57.         
  58.         private var _words:Array = ["な~る!""ワカメ酒!"];
  59.         
  60.         private var _cols:uint;
  61.         
  62.         public function LEDSignMainNaruhodo() 
  63.         {
  64.             init();
  65.             updateOn();
  66.             animationStart();
  67.         }
  68.         
  69.         private function init():void 
  70.         {
  71.             _cols = Math.floor((LED_CONTAINER_WIDTH - 2 * LED_MARGIN) / (LED_RADIUS * 2 /*+ LED.OFF_GLOW_FILTER.blurX */+ LED_MARGIN))
  72.             _resetBMRect = new Rectangle(00, _cols, ROWS);
  73.             initStage();
  74.             initLEDs();
  75.             initCanvas();
  76.         }
  77.         
  78.         private function initCanvas():void
  79.         {
  80.             _canvas = new Sprite();
  81.             _canvasDrawBM = new BitmapData(_cols, ROWS, true, 0x000000);
  82.             _drawMatrix.translate(0, -2);
  83.             createText();
  84.             createSquare();
  85.             
  86.             _ledContainer.y = stage.stageHeight * 0.5 - _ledContainer.height * 0.5 ;
  87.             //デバッグ確認用
  88.             if (DEBUG_MOODE)
  89.             {
  90.                 addChild(_canvas);
  91.                 _canvas.y = 420;
  92.                 var bm:Bitmap = new Bitmap(_canvasDrawBM);
  93.                 addChild(bm);
  94.                 bm.y = 300;
  95.             }
  96.         }
  97.         
  98.         private function createSquare():void
  99.         {
  100.             _square = new Shape();
  101.             _square.y = 2;
  102.             _canvas.addChild(_square);
  103.             _square.graphics.beginFill(0xFFFFFF, 1.0);
  104.             _square.graphics.drawRect(00, _cols, ROWS);
  105.             _square.graphics.endFill();
  106.             _square.blendMode = BlendMode.INVERT;
  107.         }
  108.         
  109.         private function createText():void
  110.         {
  111.             _tfList = [];
  112.             for (var i:int = 0, n:int = _words.length; i < n; i++) 
  113.             {
  114.                 var tf:TextField = _canvas.addChild(new TextField()) as TextField;
  115.                 tf.defaultTextFormat = DEFAULT_TEXTFORMAT;
  116.                 tf.autoSize = TextFieldAutoSize.LEFT;
  117.                 tf.text = _words[i];
  118.                 tf.y = 2;
  119.                 
  120.                 _tfList[i] = tf;
  121.             }
  122.         }
  123.         
  124.         private function initStage():void
  125.         {
  126.             //stage.align = StageAlign.TOP_LEFT;
  127.             //stage.scaleMode = StageScaleMode.NO_SCALE;
  128.             stage.quality = StageQuality.HIGH;
  129.             var stageBg:Shape = addChild(new Shape()) as Shape;
  130.             stageBg.graphics.lineStyle(1, 0xcccccc);
  131.             stageBg.graphics.drawRect(00, STAGE_WIDTH, STAGE_HEIGHT);
  132.         }
  133.         
  134.         private function initLEDs():void
  135.         {
  136.             _ledList = [];
  137.             _ledContainer = new Sprite();
  138.             addChild(_ledContainer); 
  139.             
  140.             var space:uint = LED_RADIUS * 2/* + LED.OFF_GLOW_FILTER.blurX*/ + LED_MARGIN;
  141.             
  142.             for (var i:int = 0; i < ROWS * _cols; i++) 
  143.             {
  144.                 var led:LED = _ledContainer.addChild(LEDFactory.create(LED_RADIUS)) as LED;
  145.                 led.x = (i % _cols) * space + LED_MARGIN;
  146.                 led.y = Math.floor(i / _cols) * space + space;
  147.                 _ledList[i] = led;
  148.             }
  149.         }
  150.         
  151.         private function updateOn():void
  152.         {
  153.             addEventListener(Event.ENTER_FRAME, update);
  154.         }
  155.         
  156.         private function update(event:Event):void
  157.         {
  158.             render();
  159.         }
  160.         
  161.         private function render():void 
  162.         {
  163.             _canvasDrawBM.fillRect(_resetBMRect, 0);
  164.             _canvasDrawBM.draw(_canvas, _drawMatrix);
  165.             _canvasDrawBM.threshold(_canvasDrawBM, _canvasDrawBM.rect, new Point(), "<", 0x808080, 0);
  166.             
  167.             for (var i:int = 0, n:int = _ledList.length; i < n; i++) 
  168.             {
  169.                 var color:uint = _canvasDrawBM.getPixel((i % _cols), Math.floor(i / _cols));
  170.                 if (color == 0)
  171.                     LED(_ledList[i]).lightOn()
  172.                 else
  173.                     LED(_ledList[i]).lightOff()
  174.             }
  175.         }
  176.         
  177.         /**
  178.          * アニメーション
  179.          */
  180.         private function animationStart():void
  181.         {
  182.             initPos();
  183.             var delayTime:Number = 0;
  184.             var animTime:Number;
  185.             var speed:Number = ANIMATION_SPEED;
  186.             for (var i:int = 0, n:int = _tfList.length; i < n; i++) 
  187.             {
  188.                 var tf:TextField = _tfList[i];
  189.                 animTime = LEDAnimation.getTFAnimTime(tf.x, -tf.textWidth - 1, speed);
  190.                 //フリ
  191.                 if (i != n -1)
  192.                 {
  193.                     delayTime = LEDAnimation.slide(tf, -tf.textWidth - 2, delayTime, animTime);
  194.                 }
  195.                 //オチ
  196.                 else
  197.                 {
  198.                     delayTime -= 0.8;
  199.                     var cx:Number = Math.round((_cols - tf.textWidth) * 0.5);
  200.                     animTime = LEDAnimation.getTFAnimTime(tf.x, -cx - 1, speed);
  201.                     delayTime = LEDAnimation.slide(tf, cx, delayTime, animTime);
  202.                     delayTime += 1.0;
  203.                     for (var j:int = 0; j < 4; j++) 
  204.                     {
  205.                         delayTime = LEDAnimation.blink(_square, delayTime);
  206.                     }
  207.                     delayTime = LEDAnimation.slide(tf, -tf.textWidth - 2, delayTime + 0.5, LEDAnimation.getTFAnimTime(cx, -tf.textWidth - 1, speed));
  208.                 }
  209.             }
  210.             Tweener.addCaller(this, { time: 0.0, delay: delayTime + 2.0, count: 1, onUpdate: animationStart } );
  211.         }
  212.         
  213.         private function initPos():void
  214.         {
  215.             _square.visible = false;
  216.             for (var i:int = 0, n:int = _tfList.length; i < n; i++) 
  217.             {
  218.                 _tfList[i].x = _cols * 1.5;
  219.             }
  220.         }
  221.     }
  222. }
  223. import caurina.transitions.Tweener;
  224. class LEDAnimation
  225. {
  226.     function LEDAnimation()
  227.     {
  228.         
  229.     }
  230.     
  231.     public static function blink(target:DisplayObject, delayTime:Number, blinkTime:Number = 0.2):Number
  232.     {
  233.         Tweener.addTween(target, { visible: true, time: 0.0, delay: delayTime += blinkTime, transition: "linear" } );
  234.         Tweener.addTween(target, { visible: false, time: 0.0, delay: delayTime += blinkTime, transition: "linear" } );
  235.         return delayTime;
  236.     }
  237.     
  238.     public static function slide(target:DisplayObject, destX:Number, delayTime:Number, animTime:Number):Number
  239.     {
  240.         Tweener.addTween(target, { x: destX, time: animTime, delay: delayTime, transition: "linear" } );
  241.         return delayTime + animTime;
  242.     }
  243.     public static function getTFAnimTime(startX:Number, destX:Number, friction:Number = 0.1):Number
  244.     {
  245.         return Math.abs((startX - destX) * friction);
  246.     }
  247.     
  248. }
  249. import flash.display.*;
  250. import flash.filters.BlurFilter;
  251. import flash.filters.GlowFilter;
  252. import flash.geom.ColorTransform;
  253. import flash.geom.Matrix;
  254. class LED extends Bitmap
  255. {
  256.     
  257.     public static const ON_COLOR:uint = 0xE9C20E;
  258.     public static const OFF_COLOR:uint = 0x454221;
  259.     public static const ON_GLOW_FILTER:GlowFilter = new GlowFilter(ON_COLOR, 1.04412);
  260.     public static const ON_INNER_GLOW_FILTER:GlowFilter = new GlowFilter(0xFFFFFF, 0.84412true);
  261.     public static const ON_COLOR_FILTER:ColorTransform = new ColorTransform(0001.0696633);
  262.     public static const OFF_GLOW_FILTER:GlowFilter = new GlowFilter(OFF_COLOR, 1.04412);
  263.     public static const OFF_INNER_GLOW_FILTER:GlowFilter = new GlowFilter(0xFFFFFF, 0.52212true);
  264.     public static const OFF_COLOR_FILTER:ColorTransform = new ColorTransform();
  265.     
  266.     private static var _onBM:BitmapData;
  267.     private static var _offBM:BitmapData;
  268.     
  269.     public function LED()
  270.     {
  271.         init();
  272.     }
  273.     
  274.     private function init():void
  275.     {
  276.         this.bitmapData = LED._offBM;
  277.     }
  278.     
  279.     public function lightOn():void
  280.     {
  281.         this.bitmapData = LED._onBM;
  282.     }
  283.     
  284.     public function lightOff():void
  285.     {
  286.         this.bitmapData = LED._offBM;
  287.     }
  288.     
  289.     public static function set onBM(value:BitmapData):void 
  290.     {
  291.         _onBM = value;
  292.     }
  293.     
  294.     public static function set offBM(value:BitmapData):void 
  295.     {
  296.         _offBM = value;
  297.     }
  298.     
  299. }
  300. class LEDFactory
  301. {
  302.     
  303.     private static var _isCached:Boolean = false;
  304.     public function LEDFactory(){}
  305.     
  306.     public static function create(radius:Number = 5):LED
  307.     {
  308.         if (!_isCached)
  309.         {
  310.             initCache(radius);
  311.         }
  312.         return new LED();
  313.         
  314.     }
  315.     
  316.     private static function initCache(radius:Number):void
  317.     {
  318.         LED.onBM = createBM(radius, LED.ON_COLOR, [LED.ON_GLOW_FILTER, LED.ON_INNER_GLOW_FILTER], LED.ON_COLOR_FILTER);
  319.         LED.offBM =  createBM(radius, LED.OFF_COLOR, [LED.OFF_GLOW_FILTER, LED.OFF_INNER_GLOW_FILTER], LED.OFF_COLOR_FILTER);
  320.         _isCached = true;
  321.     }
  322.     
  323.     private static function createBM(radius:Number, color:uint, filters:Array, colortrans:ColorTransform):BitmapData
  324.     {
  325.         var shape:Shape = new Shape();
  326.         shape.graphics.beginFill(color);
  327.         shape.graphics.drawCircle(radius, radius, radius);
  328.         shape.graphics.endFill();
  329.         shape.filters = filters;
  330.         shape.transform.colorTransform = colortrans;
  331.         
  332.         var result:BitmapData =  new BitmapData(shape.width + 4, shape.height + 4true, 0x000000);
  333.         var mtx:Matrix = new Matrix();
  334.         mtx.translate(22);
  335.         result.draw(shape, mtx);
  336.         return result;
  337.     }
  338. }
noswf
Get Adobe Flash Player