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

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

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


forked from : beinteractive's 4. Tween grouping with BetweenAS3 [diff(294)]

FORKED
  1. // forked from onedayitwillmake's forked from: 4. Tween grouping with BetweenAS3
  2. // Click to apply attraction force.
  3. // Please view all steps, to see how i got to this point.
  4. // I did not / do not, know when I'll stop these iterations but they are fun.
  5. // Sort of forked 5. Tween controlling BetweenAS3
  6. // forked from onedayitwillmake's Proximity step 6
  7. // forked from onedayitwillmake's Proximity step 5
  8. // forked from onedayitwillmake's Proximity step 4
  9. // forked from onedayitwillmake's forked from: Proximity step 3
  10. // forked from onedayitwillmake's forked from: Proximity step 2
  11. // forked from onedayitwillmake's forked from: Proximity step 1
  12. /**
  13.  * Proximity field - Step 7
  14.  * @Revision 
  15.  *         -First time using BetweenAS3!
  16.                 -the parameter, "stopOnComplete" = false, brings this spiderweb to life
  17.  * @author Mario Gonzalez
  18.  * @see http://onedayitwillmake.com/ 
  19.  */
  20. package
  21. {
  22.     
  23.     import flash.display.GradientType;
  24.     import flash.display.Graphics;
  25.     import flash.display.Shape;
  26.     import flash.display.SpreadMethod;
  27.     import flash.display.Sprite;
  28.     import flash.display.StageQuality;
  29.     import flash.events.Event;
  30.     import flash.events.MouseEvent;
  31.     import flash.geom.Matrix;
  32.     import flash.geom.Point;
  33.     
  34.     import org.libspark.betweenas3.BetweenAS3;
  35.     import org.libspark.betweenas3.easing.Back;
  36.     import org.libspark.betweenas3.easing.Sine;
  37.     import org.libspark.betweenas3.tweens.ITween;
  38.     [SWF(width="465", height="465", background="#000000")]
  39.     
  40.     public class Proximity extends Sprite
  41.     {
  42.         //Parameters 
  43.                 private var _cCount            :int = 0;
  44.                 private var _cMax            :int = 80;
  45.         //Rendering
  46.         private var _canvas            :Sprite;
  47.         public    var _canvasGraphics    :Graphics
  48.         //Reference 
  49.         public    var _lastCircle        :Circle; 
  50.         //Movement
  51.                 public static var FORCE_DEFAULT     :int = 500;
  52.                 public static var FORCE             :int = FORCE_DEFAULT;
  53.         public var _mousePressed    :Boolean = false;
  54.                 public var _mousePoint          :Point = new Point(00);
  55.         
  56.         public function Proximity()
  57.         {
  58.             stage.quality = StageQuality.LOW
  59.             addChildAt(createBG(), 0);
  60.             addChild(_canvas = new Sprite());
  61.             _canvasGraphics = _canvas.graphics;
  62.                         
  63.                         create();
  64.                                              
  65.             addEventListener(Event.ENTER_FRAME, loop);
  66.             stage.addEventListener(MouseEvent.MOUSE_DOWN, toggleMouseDown);
  67.             stage.addEventListener(MouseEvent.MOUSE_UP, toggleMouseDown);
  68.                            
  69.         }
  70.         
  71.         private function createBG():Sprite
  72.         {
  73.             var matr:Matrix = new Matrix();
  74.             matr.createGradientBox(465465, Math.PI / 200);
  75.             
  76.             var bg:Sprite = new Sprite();
  77.             bg.graphics.beginGradientFill
  78.             (
  79.                 GradientType.LINEAR, 
  80.                 [0x000021, 0x000000], //colors
  81.                 [11], //alphas
  82.                 [0255], //ratios
  83.                 matr, //matrix
  84.                 SpreadMethod.PAD
  85.             );    
  86.             
  87.             bg.graphics.drawRect(00465465);
  88.             bg.graphics.endFill();
  89.             
  90.             return bg;
  91.         }
  92.         
  93.         /**
  94.          * Main program loop
  95.          */ 
  96.         private function loop(e:Event):void
  97.         {
  98.              if(stage.mouseX == _mousePoint.x && stage.mouseY == _mousePoint.y)
  99.                 Proximity.FORCE = 0;
  100.              else
  101.                  Proximity.FORCE = Proximity.FORCE_DEFAULT
  102.                         
  103.             _mousePoint.x = stage.mouseX;
  104.             _mousePoint.y = stage.mouseY;
  105.             
  106.             draw();
  107.         }
  108.         
  109.         /**
  110.          * Creates more circles if we have not reached the maximum count
  111. #  // Time setting: 2.5sec
  112. #             BetweenAS3.tween(box1, {x: 220}, null, 2.5).play();
  113. #             
  114. #             // Easing setting: EaseOutBounce
  115. #             BetweenAS3.tween(box2, {x: 220}, null, 0.5, Bounce.easeOut).play();
  116. #             
  117. #             // Easing with parameter
  118. #             BetweenAS3.tween(box3, {x: 220}, null, 0.5, Back.easeOutWith(1.9)).play();
  119. #             
  120. #             // Delay setting: 1.0sec
  121. #             BetweenAS3.tween(box4, {x: 220}, null, 1.5, null, 1.0).play();
  122.          */ 
  123.         public function create():void
  124.         {
  125.             //if(_cCount >= _cMax) return;
  126.              
  127.             var c:Circle;
  128.                         var columns :int = 8;
  129.                         var rows    :int = 10;
  130.                         for(var ax:int = 0; ax < columns; ax++)
  131.                         {
  132.                             for (var ay:int = 0; ay < rows; ay++)
  133.                             {
  134.                                  c = new Circle(this);
  135.                                  
  136.                                  var startX:int = Math.random() * 465;
  137.                                  var startY:int = Math.random() * 10 - 5 + 15;
  138.                                  var homeX:int = ax * (475 / columns);
  139.                                  var homeY:int = 470
  140.                                  
  141.                                  addChild(c);
  142.                                 
  143.                                  var t:ITween = 
  144.                                  BetweenAS3.tween(c,
  145.                                      {_ix: homeX, x: homeX, y: homeY, _iy: homeY}, /* End values */
  146.                                      {x: startX, _ix: startX, y: startY, _iy: startY}, /* Start at */
  147.                                      Math.random() * 6 + 1/* Tween duration in seconds */
  148.                                      Sine.easeOutIn, /* Easing equation */ 
  149.                                      Math.random() * 3
  150.                                  );
  151.                                       t.stopOnComplete = false;
  152.                                       t.onPlay = c.reset;
  153.                                       t.play();
  154.                                      
  155.                                       
  156.                                  if(_lastCircle) 
  157.                                      c._prev = _lastCircle;    
  158.                                   
  159.                                   _lastCircle = c;
  160.                             }    
  161.                         }
  162.         }
  163.         
  164.         /**
  165.          * Draws the proximity field between the circles
  166.          */ 
  167.         public function draw():void
  168.         {
  169.             _canvas.graphics.clear();
  170.             _canvas.graphics.lineStyle(1, 0xffffff, 0.3);
  171.             
  172.             if(_lastCircle == nullreturn;
  173.             
  174.             _lastCircle.checkForProximity(_lastCircle._prev);
  175.             _lastCircle.move();
  176.         }
  177.         
  178.         public function toggleMouseDown(e:MouseEvent):void
  179.         {
  180.             if(_mousePressed)
  181.                 _mousePressed = false;
  182.             else
  183.                 _mousePressed = true;
  184.         }
  185.     }
  186. }
  187. import flash.display.Shape;
  188. import flash.display.Sprite;
  189. /**
  190.  * Circles that live in the feild
  191.  */
  192. class Circle extends Sprite
  193. {
  194.     private var _radius            :Number = Math.random() * 15 + 5;
  195.     private var _curveModifier    :Number    = Math.random() * 50 - 25;
  196.      public    var _isEnabled        :Boolean = false;
  197.      
  198.      public var _p            :Proximity; //reference
  199.      public var _prev        :Circle;    //Linked list style behavior
  200.     
  201.     //MOVEMENT
  202.     public static var ACC_PARAM:Number = 0.05;
  203.     public static var VELOCITY_PARAM:Number = 0.85
  204.     
  205.     public var _ix:Number;
  206.     public var _iy:Number;
  207.     public var _vx:Number = 0;
  208.     public var _vy:Number = 0;
  209.     public var _ax:Number = 0;
  210.     public var _ay:Number = 0;
  211.     /**
  212.      * Individual Circles know only the Circle created previously to their own
  213.      */
  214.     public function Circle(p:Proximity):void
  215.     {
  216.     
  217.         _p = p;
  218.         //blendMode = "add";
  219. //        graphics.beginFill(Math.random() * 255 * 255 * 255, 0.5)
  220. //        graphics.drawCircle(0, 0, _radius);
  221. //        graphics.endFill();
  222.         graphics.beginFill(0xffffff, 1)
  223.         graphics.drawCircle(001);
  224.         graphics.endFill();
  225.     }
  226.     
  227.         public function reset():void
  228.         {
  229.             _vx = 0;
  230.             _vy = 0;
  231.             _ax = 0;
  232.             _ay = 0;   
  233.         }
  234.     /**
  235.      * Check all previous circles for proximity, and do [something]
  236.      * There is no need for each circle to check the ones ahead, 
  237.      * because they've already checked against this one.
  238.      * 
  239.      * Called recursively for this circle, until the linked list reaches the first circle.
  240.      * Once it does, it calls checkForProximity on its '_prev'
  241.      * The sequence repeats until there are no more previous ones
  242.      * 
  243.      * @param tc:Circle The 'test circle' we will check against.
  244.      */ 
  245.     public function checkForProximity(tc:Circle):void
  246.     {
  247.         if(tc == nullreturn// This is the first circle created (unless error of course!)
  248.         //if(tc._isEnabled == false) { checkForProximity(tc._prev); return;};
  249.         
  250.         var d:Number = Math.sqrt((x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y));
  251.         
  252.         if(d <  90)
  253.         {
  254.             _p._canvasGraphics.moveTo(x, y);
  255.             //_p._canvasGraphics.lineTo(tc.x, tc.y);
  256.             //_p._canvasGraphics.curveTo(tc.x, tc.y);
  257.             _p._canvasGraphics.curveTo((x + tc.x) * 0.5, (y + tc.y) * 0.5 + _curveModifier, tc.x, tc.y);
  258.         }
  259.         
  260.                 //Keep checking backwards for proximity, until you reach the first circle
  261.         if(tc._prev)
  262.             checkForProximity(tc._prev);
  263.         else if(_prev) //Reached first circle. We are the last created circle, so continue the loop until we reach the first
  264.             _prev.checkForProximity(_prev._prev);
  265.     }
  266.     
  267.         /** 
  268.         * Moves the circle, initial position relative to mouse attraction/repelling force
  269.         */
  270.     public function move():void
  271.     {
  272.         //Don't let the force become too strong, by saying the distance will always be X at min
  273.         var dist:Number = Math.max(Math.sqrt((x - stage.mouseX) * (x - stage.mouseX) + (y - stage.mouseY) * (y - stage.mouseY)), 40);
  274.         var dy:Number = stage.mouseY - y;
  275.         var dx:Number = stage.mouseX - x
  276.         var angle:Number = Math.atan2(dy, dx);
  277.         var f:Number = 1 / dist * Proximity.FORCE * ((_p._mousePressed == true) ? 1 : -1);
  278.         
  279.         _ax += Math.cos(angle) * f;
  280.         _ay += Math.sin(angle) * f;
  281.         _ax += (_ix - x) * ACC_PARAM;
  282.         _ay += (_iy - y) * ACC_PARAM;
  283.         _vx = (_vx + _ax) * VELOCITY_PARAM;
  284.         _vy = (_vy + _ay) * VELOCITY_PARAM;
  285.         x += _vx;
  286.         y += _vy;
  287.         _ax = _ay = 0;
  288.         
  289.         if(_prev) //Call move on all circles
  290.             _prev.move();
  291.     }
  292.     
  293.     public function destroy():void
  294.     {
  295. //         _p._firstCircle = this;
  296.     }    
  297.     
  298.     public function enable():void
  299.     {
  300.         x = _ix = Math.random() * 10 - 5 + 15;
  301.     }
  302. }
noswf
  1. // Click to apply attraction force.
  2. // Please view all steps, to see how i got to this point.
  3. // I did not / do not, know when I'll stop these iterations but they are fun.
  4. // Sort of forked 5. Tween controlling BetweenAS3
  5. // forked from onedayitwillmake's Proximity step 6
  6. // forked from onedayitwillmake's Proximity step 5
  7. // forked from onedayitwillmake's Proximity step 4
  8. // forked from onedayitwillmake's forked from: Proximity step 3
  9. // forked from onedayitwillmake's forked from: Proximity step 2
  10. // forked from onedayitwillmake's forked from: Proximity step 1
  11. /**
  12.  * Proximity field - Step 7
  13.  * @Revision 
  14.  *         -First time using BetweenAS3!
  15.                 -the parameter, "stopOnComplete" = false, brings this spiderweb to life
  16.  * @author Mario Gonzalez
  17.  * @see http://onedayitwillmake.com/ 
  18.  */
  19. package
  20. {
  21.     
  22.     import flash.display.GradientType;
  23.     import flash.display.Graphics;
  24.     import flash.display.Shape;
  25.     import flash.display.SpreadMethod;
  26.     import flash.display.Sprite;
  27.     import flash.display.StageQuality;
  28.     import flash.events.Event;
  29.     import flash.events.MouseEvent;
  30.     import flash.geom.Matrix;
  31.     import flash.geom.Point;
  32.     
  33.     import org.libspark.betweenas3.BetweenAS3;
  34.     import org.libspark.betweenas3.easing.Back;
  35.     import org.libspark.betweenas3.easing.Sine;
  36.     import org.libspark.betweenas3.tweens.ITween;
  37.     [SWF(width="465", height="465", background="#000000")]
  38.     
  39.     public class Proximity extends Sprite
  40.     {
  41.         //Parameters 
  42.                 private var _cCount            :int = 0;
  43.                 private var _cMax            :int = 80;
  44.         //Rendering
  45.         private var _canvas            :Sprite;
  46.         public    var _canvasGraphics    :Graphics
  47.         //Reference 
  48.         public    var _lastCircle        :Circle; 
  49.         //Movement
  50.                 public static var FORCE_DEFAULT     :int = 500;
  51.                 public static var FORCE             :int = FORCE_DEFAULT;
  52.         public var _mousePressed    :Boolean = false;
  53.                 public var _mousePoint          :Point = new Point(00);
  54.         
  55.         public function Proximity()
  56.         {
  57.             stage.quality = StageQuality.LOW
  58.             addChildAt(createBG(), 0);
  59.             addChild(_canvas = new Sprite());
  60.             _canvasGraphics = _canvas.graphics;
  61.                         
  62.                         create();
  63.                                              
  64.             addEventListener(Event.ENTER_FRAME, loop);
  65.             stage.addEventListener(MouseEvent.MOUSE_DOWN, toggleMouseDown);
  66.             stage.addEventListener(MouseEvent.MOUSE_UP, toggleMouseDown);
  67.                            
  68.         }
  69.         
  70.         private function createBG():Sprite
  71.         {
  72.             var matr:Matrix = new Matrix();
  73.             matr.createGradientBox(465465, Math.PI / -200);
  74.             
  75.             var bg:Sprite = new Sprite();
  76.             bg.graphics.beginGradientFill
  77.             (
  78.                 GradientType.LINEAR, 
  79.                 [0x000021, 0x000000], //colors
  80.                 [11], //alphas
  81.                 [0255], //ratios
  82.                 matr, //matrix
  83.                 SpreadMethod.PAD
  84.             );    
  85.             
  86.             bg.graphics.drawRect(00465465);
  87.             bg.graphics.endFill();
  88.             
  89.             return bg;
  90.         }
  91.         
  92.         /**
  93.          * Main program loop
  94.          */ 
  95.         private function loop(e:Event):void
  96.         {
  97.              if(stage.mouseX == _mousePoint.x && stage.mouseY == _mousePoint.y)
  98.                 Proximity.FORCE = 0;
  99.              else
  100.                  Proximity.FORCE = Proximity.FORCE_DEFAULT
  101.                         
  102.             _mousePoint.x = stage.mouseX;
  103.             _mousePoint.y = stage.mouseY;
  104.             
  105.             draw();
  106.         }
  107.         
  108.         /**
  109.          * Creates more circles if we have not reached the maximum count
  110. #  // Time setting: 2.5sec
  111. #             BetweenAS3.tween(box1, {x: 220}, null, 2.5).play();
  112. #             
  113. #             // Easing setting: EaseOutBounce
  114. #             BetweenAS3.tween(box2, {x: 220}, null, 0.5, Bounce.easeOut).play();
  115. #             
  116. #             // Easing with parameter
  117. #             BetweenAS3.tween(box3, {x: 220}, null, 0.5, Back.easeOutWith(1.9)).play();
  118. #             
  119. #             // Delay setting: 1.0sec
  120. #             BetweenAS3.tween(box4, {x: 220}, null, 1.5, null, 1.0).play();
  121.          */ 
  122.         public function create():void
  123.         {
  124.             //if(_cCount >= _cMax) return;
  125.              
  126.             var c:Circle;
  127.                         var columns :int = 8;
  128.                         var rows    :int = 10;
  129.                         for(var ax:int = 0; ax < columns; ax++)
  130.                         {
  131.                             for (var ay:int = 0; ay < rows; ay++)
  132.                             {
  133.                                  c = new Circle(this);
  134.                                  
  135.                                  var startX:int = Math.random() * 475 - 5;
  136.                                  var startY:int = Math.random() * 10 - 5 + 75;
  137.                                  var homeX:int = ax * (475 / columns);
  138.                                  var homeY:int = 450
  139.                                  
  140.                                  addChild(c);
  141.                                 
  142.                                  var t:ITween = 
  143.                                  BetweenAS3.tween(c,
  144.                                      {_ix: homeX, x: homeX, y: homeY, _iy: homeY}, /* End values */
  145.                                      {x: startX, _ix: startX, y: startY, _iy: startY}, /* Start at */
  146.                                      Math.random() * 6 + 3/* Tween duration in seconds */
  147.                                      Back.easeInWith(2), /* Easing equation */ 
  148.                                      Math.random() * 3
  149.                                  );
  150.                                       t.stopOnComplete = false;
  151.                                       t.onPlay = c.reset;
  152.                                       t.play();
  153.                                      
  154.                                       
  155.                                  if(_lastCircle) 
  156.                                      c._prev = _lastCircle;    
  157.                                   
  158.                                   _lastCircle = c;
  159.                             }    
  160.                         }
  161.         }
  162.         
  163.         /**
  164.          * Draws the proximity field between the circles
  165.          */ 
  166.         public function draw():void
  167.         {
  168.             _canvas.graphics.clear();
  169.             _canvas.graphics.lineStyle(1, 0xffffff, 0.3);
  170.             
  171.             if(_lastCircle == nullreturn;
  172.             
  173.             _lastCircle.checkForProximity(_lastCircle._prev);
  174.             _lastCircle.move();
  175.         }
  176.         
  177.         public function toggleMouseDown(e:MouseEvent):void
  178.         {
  179.             if(_mousePressed)
  180.                 _mousePressed = false;
  181.             else
  182.                 _mousePressed = true;
  183.         }
  184.     }
  185. }
  186. import flash.display.Shape;
  187. import flash.display.Sprite;
  188. /**
  189.  * Circles that live in the feild
  190.  */
  191. class Circle extends Sprite
  192. {
  193.     private var _radius            :Number = Math.random() * 15 + 5;
  194.     private var _curveModifier    :Number    = Math.random() * 50 - 25;
  195.      public    var _isEnabled        :Boolean = false;
  196.      
  197.      public var _p            :Proximity; //reference
  198.      public var _prev        :Circle;    //Linked list style behavior
  199.     
  200.     //MOVEMENT
  201.     public static var ACC_PARAM:Number = 0.05;
  202.     public static var VELOCITY_PARAM:Number = 0.85
  203.     
  204.     public var _ix:Number;
  205.     public var _iy:Number;
  206.     public var _vx:Number = 0;
  207.     public var _vy:Number = 0;
  208.     public var _ax:Number = 0;
  209.     public var _ay:Number = 0;
  210.     /**
  211.      * Individual Circles know only the Circle created previously to their own
  212.      */
  213.     public function Circle(p:Proximity):void
  214.     {
  215.     
  216.         _p = p;
  217.         //blendMode = "add";
  218. //        graphics.beginFill(Math.random() * 255 * 255 * 255, 0.5)
  219. //        graphics.drawCircle(0, 0, _radius);
  220. //        graphics.endFill();
  221.         graphics.beginFill(0xffffff, 1)
  222.         graphics.drawCircle(001);
  223.         graphics.endFill();
  224.     }
  225.     
  226.         public function reset():void
  227.         {
  228.             _vx = 0;
  229.             _vy = 0;
  230.             _ax = 0;
  231.             _ay = 0;   
  232.         }
  233.     /**
  234.      * Check all previous circles for proximity, and do [something]
  235.      * There is no need for each circle to check the ones ahead, 
  236.      * because they've already checked against this one.
  237.      * 
  238.      * Called recursively for this circle, until the linked list reaches the first circle.
  239.      * Once it does, it calls checkForProximity on its '_prev'
  240.      * The sequence repeats until there are no more previous ones
  241.      * 
  242.      * @param tc:Circle The 'test circle' we will check against.
  243.      */ 
  244.     public function checkForProximity(tc:Circle):void
  245.     {
  246.         if(tc == nullreturn// This is the first circle created (unless error of course!)
  247.         //if(tc._isEnabled == false) { checkForProximity(tc._prev); return;};
  248.         
  249.         var d:Number = Math.sqrt((x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y));
  250.         
  251.         if(d <  110)
  252.         {
  253.             _p._canvasGraphics.moveTo(x, y);
  254.             //_p._canvasGraphics.lineTo(tc.x, tc.y);
  255.             //_p._canvasGraphics.curveTo(tc.x, tc.y);
  256.             _p._canvasGraphics.curveTo((x + tc.x) * 0.5, (y + tc.y) * 0.5 + _curveModifier, tc.x, tc.y);
  257.         }
  258.         
  259.                 //Keep checking backwards for proximity, until you reach the first circle
  260.         if(tc._prev)
  261.             checkForProximity(tc._prev);
  262.         else if(_prev) //Reached first circle. We are the last created circle, so continue the loop until we reach the first
  263.             _prev.checkForProximity(_prev._prev);
  264.     }
  265.     
  266.         /** 
  267.         * Moves the circle, initial position relative to mouse attraction/repelling force
  268.         */
  269.     public function move():void
  270.     {
  271.         //Don't let the force become too strong, by saying the distance will always be X at min
  272.         var dist:Number = Math.max(Math.sqrt((x - stage.mouseX) * (x - stage.mouseX) + (y - stage.mouseY) * (y - stage.mouseY)), 40);
  273.         var dy:Number = stage.mouseY - y;
  274.         var dx:Number = stage.mouseX - x
  275.         var angle:Number = Math.atan2(dy, dx);
  276.         var f:Number = 1 / dist * Proximity.FORCE * ((_p._mousePressed == true) ? 1 : -1);
  277.         
  278.         _ax += Math.cos(angle) * f;
  279.         _ay += Math.sin(angle) * f;
  280.         _ax += (_ix - x) * ACC_PARAM;
  281.         _ay += (_iy - y) * ACC_PARAM;
  282.         _vx = (_vx + _ax) * VELOCITY_PARAM;
  283.         _vy = (_vy + _ay) * VELOCITY_PARAM;
  284.         x += _vx;
  285.         y += _vy;
  286.         _ax = _ay = 0;
  287.         
  288.         if(_prev) //Call move on all circles
  289.             _prev.move();
  290.     }
  291.     
  292.     public function destroy():void
  293.     {
  294. //         _p._firstCircle = this;
  295.     }    
  296.     
  297.     public function enable():void
  298.     {
  299.         x = _ix = Math.random() * 10 - 5 + 15;
  300.     }
  301. }
noswf
Get Adobe Flash Player