Advertisement
durss

Ca devient le bordeeeel

Jan 29th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.aaaa.taimerais.bien.savoir.dequoi.ilsagit.hein {
  2.  
  3.     import com.nurun.utils.math.MathUtils;
  4.     import flash.geom.Point;
  5.     import flash.display.Shape;
  6.  
  7.    
  8.     /**
  9.      * @author ton fessier
  10.      * @date 15 janv. 2012;
  11.      */
  12.     public class Particle extends Shape {
  13.        
  14.         public var next:Particle;
  15.         public var sx:Number;
  16.         public var sy:Number;
  17.         public var friction:Number;
  18.         private var _incX:Number;
  19.         private var _frequency:Number;
  20.         private var _origin:Point;
  21.         private var _amplitude:Number;
  22.         private var _launched:Boolean;
  23.         private var _radius:Number;
  24.         private var _oy:Number;
  25.         private var _incY:Number;
  26.         private var _distort:Number;
  27.         private var _distortMax:Number;
  28.         private var _lockY:Boolean;
  29.         private var _distance:Number;
  30.         private var _offsetAngle:Number;
  31.         private var _center:Point;
  32.         private var _vibration:Number;
  33.         private var _aVib:Number;
  34.         private var _angle:Number;
  35.         private var _distanceRatio:Number;
  36.         private var _angle2:Number;
  37.         private var _endOffsetAngle:Number;
  38.         private var _amplitudeRand:Number;
  39.         private var _incAngle:Number;
  40.         private var _amplitudeEased:Number;
  41.        
  42.        
  43.  
  44.  
  45.         /* *********** *
  46.          * CONSTRUCTOR *
  47.          * *********** */
  48.         /**
  49.          * Creates an instance of <code>Particle</code>.
  50.          */
  51.         public function Particle() {
  52.             friction = Math.random() * .3 + .3;
  53.             _radius = Math.random() * 2.5 + 1;
  54.            
  55.             x = y = -1;
  56.         }
  57.  
  58.        
  59.        
  60.         /* ***************** *
  61.          * GETTERS / SETTERS *
  62.          * ***************** */
  63.  
  64.  
  65.  
  66.         /* ****** *
  67.          * PUBLIC *
  68.          * ****** */
  69.         /**
  70.          * Initializes the particle
  71.          */
  72.         public function init(origin:Point) : void {
  73.             _origin = origin;
  74.             _incX = Math.random() * Math.PI * 2;
  75.             _incY = Math.random() * Math.PI * 2;
  76.             _frequency = (Math.random()-Math.random()) * Math.PI * .01;
  77.             _amplitude = 20+Math.random() * 80;
  78.             y = Math.random() * 2 + origin.y;
  79.             sx = -(origin.x - x)*.25;
  80.             sy = Math.random() * 3 + 3;
  81.             _oy = -1;
  82.             _launched = true;
  83.            
  84. //          graphics.clear();
  85. //          graphics.beginFill(0xffff88, Math.random()*.2+.2);
  86. //          graphics.drawCircle(0, 0, _radius+2);
  87. //          graphics.endFill();
  88.            
  89.             graphics.beginFill(0xC7B40E, 1);
  90.             graphics.drawCircle(0, 0, _radius);
  91.             graphics.endFill();
  92.         }
  93.        
  94.         /**
  95.          * Moves the particle
  96.          */
  97.         public function move(angle:Number):void {
  98.             if(!_launched) return;
  99.            
  100.            
  101.             //Synch with the sky's animation
  102.             if(_lockY) {
  103.                 if(_angle == -1) {
  104.                     _angle = _offsetAngle + angle;
  105.                     _angle2 = angle+Math.PI*.5;
  106.                 }else{
  107.                     _amplitudeEased += (_amplitude - _amplitudeEased) * .02;//Ease the "wave" effect amplitude
  108.                     _angle += (_offsetAngle+angle - _angle) * _distanceRatio;//Ease the global direction of the particles depending on the sky's orientation
  109.                     _angle += Math.sin(_incX)*_amplitudeEased;//Makes particles moves inside the global angle making them "wave"
  110.                     _angle += Math.sin(_incAngle)*_amplitudeRand;//Add randomness to the particles angles to make them "walk" inside the cloud
  111.                     _offsetAngle += (_endOffsetAngle - _offsetAngle) * .01;//shapes the cloud in triangle
  112.                 }
  113.                 _aVib = Math.min(_aVib + .01, 2);//Vibration amplitude
  114.                 _vibration += 2.5;//Vibration frequency
  115.                 _distort += (_distortMax - _distort) * .01;//makes the particles stretch on a bigger surface
  116.                 _angle2 += (angle+Math.PI*.5 - _angle2) * .2;//ease the stretched and the offset position's angles
  117.                
  118.                 x = Math.cos(_angle) * _distance + _center.x + Math.cos(_angle2) * _distort;
  119.                 y = Math.sin(_angle) * _distance + _center.y + Math.sin(_angle2) * _distort;
  120.                 x += Math.cos(angle+Math.PI*.5) * Math.cos(_vibration) * _aVib;
  121.                 y += Math.sin(angle+Math.PI*.5) * Math.cos(_vibration) * _aVib;
  122.                
  123.                 x += Math.abs(Math.cos(_angle2)) * stage.stageWidth*.5;
  124.                 y += Math.abs(Math.cos(_angle2)) * stage.stageHeight*.5;
  125.                
  126.                 scaleY = 1 + _aVib*.05;
  127.                 scaleX = 1 - _aVib*.05;
  128.                 rotation = angle * 57.29577951308232;
  129.                
  130.                 _incX += .1;
  131.                 _incAngle += _frequency;
  132.                 _frequency *= 1.01;
  133.            
  134.             //Simple going up animation
  135.             }else{
  136.                 x = _origin.x + Math.sin(_incX) * _amplitude;
  137.                 y += Math.max(-friction*4, sy);
  138.                
  139.                 if(sy < 0) _incX += _frequency;
  140.                 sy -= sy<0? friction*.25 : friction;
  141.             }
  142.            
  143.             if(y < -5) {
  144.                 _launched = false;
  145.                 parent.removeChild(this);//Diiiiiiiirty tiiiiiiime :D
  146.             }
  147.         }
  148.        
  149.         /**
  150.          * Locks the Y position to keep the particle on the screen
  151.          */
  152.         public function lockY():void {
  153.             if(!_launched) return;
  154.            
  155.             _lockY = true;
  156.             _aVib = 0;
  157.             _incX = 0;
  158.             _incAngle = 0;
  159.             _angle = -1;
  160.             _angle2 = 0;
  161.             _distort = 0;
  162.             _vibration = Math.random() * Math.PI * 2;
  163.             _center = new Point(stage.stageWidth*.5, 0);
  164.             _distance = Math.sqrt( Math.pow(_center.x - x, 2) + Math.pow(_center.y - y, 2));
  165.             _offsetAngle = Math.atan2(y - _center.y, x - _center.x);
  166.             _distortMax = ((y*y*y*y) * .0000000190);
  167.             _distanceRatio = Math.min(1, 1/((_distance*_distance*_distance*_distance*_distance*_distance) * .00000000000001));
  168.             _endOffsetAngle = Math.PI * .5 + (_offsetAngle-Math.PI * .5)*((_distance+_distortMax)/800);
  169.             _amplitude = _distanceRatio*.3;
  170.             _amplitudeEased = 0;
  171.             _amplitudeRand = _distanceRatio*.05;
  172.             _frequency *= 5;
  173.         }
  174.  
  175.  
  176.        
  177.        
  178.         /* ******* *
  179.          * PRIVATE *
  180.          * ******* */
  181.        
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement