Butterfly Wing Flapping

So I dug up an old scan of a butterfly I found dead by the side of the road one day.. Here’s my attempt to bring it back to life. I made a class called ButterflyWing, imported the .png of the wing into it, and animated it using Tweener. It’s the first time I’ve used Tweener, and I found it fairly easy to use. I created two methods in my class – flapUp and flapDown, each of which does a tween of the wing’s rotationY property to the ‘up’ (90degrees) and ‘down’ (0 degrees) position respectively. When one of the tweens completes, it calls the other one, forming a continuous flapping movement. Next time, I’ll put two of these together to make a butterfly…

Da Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package  {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import caurina.transitions.*;

    public class ButterflyWing extends Sprite {

      [Embed(source="butterfly_wing.png")]
      private var WingBmp:Class;
      private var min_y_rotate:Number = 0;
      private var max_y_rotate:Number = 90;
      private var flapTime:Number = 0.5;
        private var butterfly_wing:Bitmap;

        public function ButterflyWing() {
            butterfly_wing = new WingBmp();
            addChild(butterfly_wing);
            flapUp();
        }
        public function flapUp():void {
            //rotate around y-axis to perpendicular position
            caurina.transitions.Tweener.addTween(butterfly_wing, {
                rotationY:max_y_rotate,
                time:flapTime,
                onComplete:flapDown,
                transition: "easeInCubic"
                });
        }
        public function flapDown():void {
            //rotate around y-axis to flat position
            caurina.transitions.Tweener.addTween(butterfly_wing, {
                rotationY:0,
                time:flapTime,
                onComplete:flapUp,
                transition: "easeOutCubic"
                });
        }
    }
}

// Copyright (c) 2008 David Wilhelm
// MIT license: http://www.opensource.org/licenses/mit-license.php

Leave a Reply