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

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

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


FORKED
  1. // forked from miyaoka's RandomHeart
  2. //click to draw a heart shape
  3. package 
  4. {
  5.     import flash.display.Sprite;
  6.     import flash.events.Event;
  7.     import flash.events.MouseEvent;
  8.     import caurina.transitions.Tweener;
  9.     [SWF(width = "465", height = "465", backgroundColor = 0xffffff, frameRate = "60")]
  10.     
  11.     public class HeartDraw extends Sprite 
  12.     {
  13.         public function HeartDraw():void 
  14.         {
  15.             stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void 
  16.             {
  17.                 var h:HeartSprite = new HeartSprite();
  18.                 h.x = mouseX;
  19.                 h.y = mouseY;
  20.                 h.scaleX *= (Math.random() * 0.5 + 0.75);
  21.                 h.scaleY *= (Math.random() * 0.5 + 0.75);
  22.                 h.rotation = (Math.random() - 0.5) * 60,
  23.                 addChild(h);
  24.                 Tweener.addTween(h, {
  25.                     x: h.x + (Math.random() -0.5) * 300,
  26.                     y: h.y + 200 + Math.random()*300,
  27.                     scaleX: h.scaleX * 0.2,
  28.                     scaleY: h.scaleY * 0.2,
  29.                     rotation: h.rotation * (Math.random() * 1.5 + 1.5),
  30.                     time: 2.0 + Math.random()*1.5,
  31.                     transition: "easeInBack",
  32.                     onComplete: function ():void 
  33.                     {
  34.                         removeChild(h);
  35.                     }
  36.                 });
  37.             });
  38.         }
  39.     }
  40. }
  41. import flash.display.Graphics;
  42. import flash.display.Sprite;
  43. import flash.geom.Point;
  44. import caurina.transitions.Tweener;
  45. class HeartSprite
  46. extends Sprite
  47. {
  48.     public var t:Number = 0;
  49.     public static var trans:Array = [
  50.         "easeInOutQuad",
  51.         "linear",
  52.         "easeInCubic",
  53.         "easeOutCubic"
  54.     ];
  55.     public function HeartSprite():void 
  56.     {
  57.         scaleY *= -1;
  58.         if (Math.random() < 0.5) scaleX *= -1;
  59.         var h:HeartSegment = new HeartSegment(Math.random()*50 + 10);
  60.         var g:Graphics = graphics;
  61.         var lastT:Number = 0;
  62.         var step:Number = 1 / 50;
  63.         
  64.         g.lineStyle(Math.random() * 6
  65.         (Math.random() * 0x66 + 0x99) << 16 |
  66.         (Math.random() * 0x66 + 0x99) << 8 |
  67.         (Math.random() * 0x66 + 0x99)
  68.         );
  69.         
  70.         //set startPt to random
  71.         t = (Math.random() < 0.5) ? 0 : 0.5;
  72.         lastT = t;
  73.         var pt:Point = h.getValue(t);
  74.         g.moveTo( pt.x, pt.y);
  75.         
  76.         Tweener.addTween(this, {
  77.             t:t+1,
  78.             time: 0.5 + Math.random()*1.0,
  79.             transition: trans[Math.floor(Math.random()*trans.length)],
  80.             onUpdate: function ():void 
  81.             {
  82.                 while ((lastT += step) < t)
  83.                 {
  84.                     var pt:Point = h.getValue(lastT);
  85.                     g.lineTo( pt.x, pt.y);
  86.                 }
  87.                 pt = h.getValue(t);
  88.                 g.lineTo( pt.x, pt.y);
  89.                 lastT = t;
  90.             }
  91.         });
  92.     }
  93. }
  94. class HeartSegment
  95. {
  96.     private var len:Number;
  97.     private var bss:Array = [];
  98.     public function HeartSegment(len:Number = 30):void 
  99.     {        
  100.         this.len = len;
  101.         
  102.         //--nodes
  103.         
  104.         //bottom
  105.         var n0:Point = new Point(00);        
  106.         //left top
  107.         var n1:Point = Point.polar(len * 2 * (Math.random()* 0.5 +0.75), Math.PI * (7/12 + Math.random() * 1 / 6));
  108.         //top
  109.         var n2:Point = new Point((Math.random()-0.5)*len*0.25, len * Math.sqrt(3));
  110.         //right top
  111.         var n3:Point = Point.polar(len * 2 * (Math.random()* 0.5 +0.75), Math.PI *  (5/12 - Math.random() * 1 / 6));
  112.         
  113.         
  114.         //--controls
  115.         var c10:Number = 0.5 + Math.random() * 1 / 6;
  116.         var c11:Number = 0.5 + Math.random() * 1 / 6;
  117.         
  118.         var c20:Number = 0.5 - Math.random() * 1 / 6;
  119.         var c21:Number = 0.5 - Math.random() * 1 / 6;
  120.         
  121.         var c00:Number = 0.5 + Math.random() * 1 / 6;
  122.         var c01:Number = c10 + 1;
  123.         
  124.         var c30:Number = c21 + 1;
  125.         var c31:Number = 0.5 - Math.random() * 1 / 6;
  126.         
  127.         //bezierSegments
  128.         bss =
  129.         [
  130.             new BezierSegment_(
  131.                 n0,
  132.                 n0.add(Point.polar(len, Math.PI * c00)),
  133.                 n1.add(Point.polar(len, Math.PI * c01)),
  134.                 n1
  135.             ),
  136.             new BezierSegment_(
  137.                 n1,
  138.                 n1.add(Point.polar(len, Math.PI * c10)),
  139.                 n2.add(Point.polar(len, Math.PI * c11)),
  140.                 n2
  141.             ),
  142.             new BezierSegment_(
  143.                 n2,
  144.                 n2.add(Point.polar(len, Math.PI * c20)),
  145.                 n3.add(Point.polar(len, Math.PI * c21)),
  146.                 n3
  147.             ),
  148.             new BezierSegment_(
  149.                 n3,
  150.                 n3.add(Point.polar(len, Math.PI * c30)),
  151.                 n0.add(Point.polar(len, Math.PI * c31)),
  152.                 n0
  153.             )
  154.         ];
  155.     }
  156.     public function getValue(t:Number):Point
  157.     {
  158.         t -= Math.floor(t);
  159.         t *= bss.length;
  160.         var i:int = Math.floor(t);
  161.         return BezierSegment_(bss[i]).getValue(t-i);
  162.     }
  163. }
  164. /**
  165.  * A Bezier segment consists of four Point objects that define a single cubic Bezier curve.
  166.  * The BezierSegment class also contains methods to find coordinate values along the curve.
  167.  * @playerversion Flash 9.0.28.0
  168.  * @langversion 3.0
  169.  * @keyword BezierSegment, Copy Motion as ActionScript
  170.  * @see ../../motionXSD.html Motion XML Elements  
  171.  */
  172. class BezierSegment_
  173. {
  174.     public var a:Point;
  175.     public var b:Point;
  176.     public var c:Point;
  177.     public var d:Point;
  178.     function BezierSegment_(a:Point, b:Point, c:Point, d:Point)
  179.     {
  180.         this.a = a;
  181.         this.b = b;
  182.         this.c = c;
  183.         this.d = d;
  184.     }
  185.     public function getValue(t:Number):Point
  186.     {
  187.         var ax:Number = this.a.x;
  188.         var x:Number = (t*t*(this.d.x-ax) + 3*(1-t)*(t*(this.c.x-ax) + (1-t)*(this.b.x-ax)))*t + ax;
  189.         var ay:Number = this.a.y;
  190.         var y:Number = (t*t*(this.d.y-ay) + 3*(1-t)*(t*(this.c.y-ay) + (1-t)*(this.b.y-ay)))*t + ay;
  191.         return new Point(x, y);    
  192.     }
  193. }
noswf
  1. //press to draw heart shapes
  2. package 
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.events.Event;
  6.     import flash.events.MouseEvent;
  7.     import caurina.transitions.Tweener;
  8.     import flash.display.BlendMode;
  9.     [SWF(width = "465", height = "465", backgroundColor = 0x0, frameRate = "60")]
  10.     
  11.     public class HeartDraw extends Sprite 
  12.     {
  13.         public function HeartDraw():void 
  14.         {
  15.             graphics.beginFill(0);
  16.             graphics.drawRect(00, stage.stageWidth, stage.stageHeight);
  17.             
  18.             var isPress:Boolean = false;
  19.             stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void 
  20.             {
  21.                 isPress = true;
  22.             });
  23.             stage.addEventListener(MouseEvent.MOUSE_UP, function ():void 
  24.             {
  25.                 isPress = false;
  26.             });
  27.             
  28.             addEventListener(Event.ENTER_FRAME, function ():void 
  29.             {
  30.                 if(!isPress) return;
  31.                 
  32.                 var h:HeartSprite = new HeartSprite();
  33.                 h.blendMode = BlendMode.ADD;
  34.                 h.x = mouseX;
  35.                 h.y = mouseY;
  36.                 h.scaleX *= (Math.random() * 0.5 + 0.75);
  37.                 h.scaleY *= (Math.random() * 0.5 + 0.75);
  38.                 h.rotation = (Math.random() - 0.5) * 60,
  39.                 addChild(h);
  40.                 Tweener.addTween(h, {
  41.                     x: h.x + (Math.random() -0.5) * 300,
  42.                     y: h.y + 200 + Math.random()*300,
  43.                     scaleX: h.scaleX * 0.2,
  44.                     scaleY: h.scaleY * 0.2,
  45.                     rotation: h.rotation * (Math.random() * 1.5 + 1.5),
  46.                     time: 2.0 + Math.random()*1.5,
  47.                     transition: "easeInBack",
  48.                     onComplete: function ():void 
  49.                     {
  50.                         removeChild(h);
  51.                     }
  52.                 });
  53.             });
  54.         }
  55.     }
  56. }
  57. import flash.display.Graphics;
  58. import flash.display.Sprite;
  59. import flash.display.Shape;
  60. import flash.geom.Point;
  61. import caurina.transitions.Tweener;
  62. import flash.filters.BlurFilter;
  63. class HeartSprite
  64. extends Sprite
  65. {
  66.     public var t:Number = 0;
  67.     public static var trans:Array = [
  68.         "easeInOutQuad",
  69.         "linear",
  70.         "easeInCubic"//,
  71. //        "easeOutCubic"
  72.     ];
  73.     private var fillShape:Shape = new Shape();
  74.     public function HeartSprite():void 
  75.     {
  76.         
  77.         scaleY *= -1;
  78.         if (Math.random() < 0.5) scaleX *= -1;
  79.         var h:HeartSegment = new HeartSegment(Math.random()*50 + 10);
  80.         var g:Graphics = graphics;
  81.         var g2:Graphics = fillShape.graphics;
  82.         var lastT:Number = 0;
  83.         var step:Number = 1 / 50;
  84.         
  85.         g.lineStyle(Math.random() * 6 + 2
  86.         (Math.random() * 0x66 + 0x99) << 16 |
  87.         (Math.random() * 0x66 + 0x99) << 8 |
  88.         (Math.random() * 0x66 + 0x99)
  89.         );
  90.         
  91.         //set startPt to random
  92. //        t = (Math.random() < 0.5) ? 0 : 0.5;
  93. //        lastT = t;
  94. //        var pt:Point = h.getValue(t);
  95. //        g.moveTo( pt.x, pt.y);
  96. //        g2.moveTo(pt.x, pt.y);
  97.         g2.beginFill(
  98.             (Math.random() * 0x3f + 0xc0) << 16 |
  99.             (Math.random() * 0x99) << 8 |
  100.             (Math.random() * 0x99)
  101.             );
  102.         
  103.                 filters = [
  104.                 new BlurFilter()
  105.                 ];
  106.         
  107.         Tweener.addTween(this, {
  108.             t:t+1,
  109.             time: 0.5 + Math.random()*1.0,
  110.             transition: trans[Math.floor(Math.random()*trans.length)],
  111.             onUpdate: function ():void 
  112.             {
  113.                 while ((lastT += step) < t)
  114.                 {
  115.                     var pt:Point = h.getValue(lastT);
  116.                     g.lineTo( pt.x, pt.y);
  117.                     g2.lineTo( pt.x, pt.y);
  118.                     
  119.                 }
  120.                 pt = h.getValue(t);
  121.                 g.lineTo( pt.x, pt.y);
  122.                 g2.lineTo( pt.x, pt.y);
  123.                 lastT = t;
  124.             },
  125.             onComplete: function ():void 
  126.             {
  127.                 g.clear();
  128.                 addChild(fillShape);
  129.                 fillShape.alpha = 0;
  130.                 Tweener.addTween(fillShape, {
  131.                     alpha:1.0,
  132.                     scaleX: 1.2,
  133.                     scaleY: 1.2,
  134.                     time:0.5,
  135.                     transition: "easeOutQuint"
  136.                 });
  137.             }
  138.         });
  139.     }
  140. }
  141. class HeartSegment
  142. {
  143.     private var len:Number;
  144.     private var bss:Array = [];
  145.     public function HeartSegment(len:Number = 30):void 
  146.     {        
  147.         this.len = len;
  148.         
  149.         //--nodes
  150.         
  151.         //bottom
  152.         var n0:Point = new Point(00);        
  153.         //left top
  154.         var n1:Point = Point.polar(len * 2 * (Math.random()* 0.5 +1), Math.PI * (7/12 + Math.random() * 1 / 6));
  155.         //top
  156.         var n2:Point = new Point((Math.random()-0.5)*len*0.25, len * Math.sqrt(3));
  157.         //right top
  158.         var n3:Point = Point.polar(len * 2 * (Math.random()* 0.5 +1), Math.PI *  (5/12 - Math.random() * 1 / 6));
  159.         
  160.         
  161.         //--controls
  162.         var c10:Number = 0.5 + Math.random() * 1 / 6;
  163.         var c11:Number = 0.5 + Math.random() * 1 / 12;
  164.         
  165.         var c20:Number = 0.5 - Math.random() * 1 / 12;
  166.         var c21:Number = 0.5 - Math.random() * 1 / 6;
  167.         
  168.         var c00:Number = 0.5 + Math.random() * 1 / 6;
  169.         var c01:Number = c10 + 1;
  170.         
  171.         var c30:Number = c21 + 1;
  172.         var c31:Number = 0.5 - Math.random() * 1 / 6;
  173.         
  174.         //bezierSegments
  175.         bss =
  176.         [
  177.             new BezierSegment_(
  178.                 n0,
  179.                 n0.add(Point.polar(len, Math.PI * c00)),
  180.                 n1.add(Point.polar(len, Math.PI * c01)),
  181.                 n1
  182.             ),
  183.             new BezierSegment_(
  184.                 n1,
  185.                 n1.add(Point.polar(len, Math.PI * c10)),
  186.                 n2.add(Point.polar(len, Math.PI * c11)),
  187.                 n2
  188.             ),
  189.             new BezierSegment_(
  190.                 n2,
  191.                 n2.add(Point.polar(len, Math.PI * c20)),
  192.                 n3.add(Point.polar(len, Math.PI * c21)),
  193.                 n3
  194.             ),
  195.             new BezierSegment_(
  196.                 n3,
  197.                 n3.add(Point.polar(len, Math.PI * c30)),
  198.                 n0.add(Point.polar(len, Math.PI * c31)),
  199.                 n0
  200.             )
  201.         ];
  202.     }
  203.     public function getValue(t:Number):Point
  204.     {
  205.         t -= Math.floor(t);
  206.         t *= bss.length;
  207.         var i:int = Math.floor(t);
  208.         return BezierSegment_(bss[i]).getValue(t-i);
  209.     }
  210. }
  211. /**
  212.  * A Bezier segment consists of four Point objects that define a single cubic Bezier curve.
  213.  * The BezierSegment class also contains methods to find coordinate values along the curve.
  214.  * @playerversion Flash 9.0.28.0
  215.  * @langversion 3.0
  216.  * @keyword BezierSegment, Copy Motion as ActionScript
  217.  * @see ../../motionXSD.html Motion XML Elements  
  218.  */
  219. class BezierSegment_
  220. {
  221.     public var a:Point;
  222.     public var b:Point;
  223.     public var c:Point;
  224.     public var d:Point;
  225.     function BezierSegment_(a:Point, b:Point, c:Point, d:Point)
  226.     {
  227.         this.a = a;
  228.         this.b = b;
  229.         this.c = c;
  230.         this.d = d;
  231.     }
  232.     public function getValue(t:Number):Point
  233.     {
  234.         var ax:Number = this.a.x;
  235.         var x:Number = (t*t*(this.d.x-ax) + 3*(1-t)*(t*(this.c.x-ax) + (1-t)*(this.b.x-ax)))*t + ax;
  236.         var ay:Number = this.a.y;
  237.         var y:Number = (t*t*(this.d.y-ay) + 3*(1-t)*(t*(this.c.y-ay) + (1-t)*(this.b.y-ay)))*t + ay;
  238.         return new Point(x, y);    
  239.     }
  240. }
noswf
Get Adobe Flash Player