~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to lib/ui/anim/lib/Spotlights.ahx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package ui.anim.lib;
 
7
 
 
8
import mathx.Random;
 
9
 
 
10
DEFACTOR(Spotlights)
 
11
 
 
12
        PARAM(num,T_Int(5))
 
13
        PARAM(color,T_RGB(1,1,1))
 
14
        PARAM(opacity,T_Float(0.5))
 
15
        PARAM(radius,T_RANDF(0.25+-0.2))
 
16
        PARAM(size,T_RANDF(0.25+-0.2))
 
17
        PARAM(speed,T_RANDF(4...6))
 
18
        
 
19
        VAR(lights,Array<Light>,new Array<Light>())
 
20
        ONINIT()
 
21
        {
 
22
                for( i in 0...params.num )
 
23
                {
 
24
                        var l = new Light();
 
25
                        addChild( l.sprite );
 
26
                        lights.push( l );
 
27
                        
 
28
                        //calculate location
 
29
                        l.ctr = Point2.at( 
 
30
                                        Random.s_nextFloat(-0.5, 0.5), 
 
31
                                        Random.s_nextFloat(-0.5, 0.5) 
 
32
                                );
 
33
                        l.r = Point2.at( params.radius.next(), params.radius.next() );
 
34
                        l.ang = Random.s_nextFloat( 0, 2 * Math.PI );
 
35
                        l.speed = params.speed.next();
 
36
                        l.size = params.size.next();
 
37
                        
 
38
                        if( Random.s_nextBool() )
 
39
                                l.speed = -l.speed;     //change the light's direction
 
40
                                
 
41
                        //draw the light
 
42
                        l.sprite.graphics.beginFill( params.color.asInt(), params.opacity );
 
43
                        l.sprite.graphics.drawCircle( -1, -1, 2 );
 
44
                }
 
45
        }
 
46
        
 
47
        TRAIT(Mode,Normal,DEFAULT)
 
48
        { 
 
49
        }
 
50
        
 
51
        SEQUENCE(Circle,DEFAULT)
 
52
        {
 
53
        }
 
54
        ONSTEP()
 
55
        {
 
56
                for( l in lights )
 
57
                        l.ang += elapsed * l.speed;
 
58
                        
 
59
                reposition();
 
60
        }
 
61
        
 
62
        function reposition()
 
63
        {
 
64
                for( l in lights )
 
65
                {
 
66
                        l.sprite.x = (Math.cos( l.ang ) * l.r.x + l.ctr.x ) * actorSize.x;
 
67
                        l.sprite.y = (Math.sin( l.ang ) * l.r.y + l.ctr.y ) * actorSize.y;
 
68
                }               
 
69
        }
 
70
        
 
71
        ONRESIZE()
 
72
        {
 
73
                for( l in lights )
 
74
                {
 
75
                        l.sprite.width = l.size * actorSize.x;
 
76
                        l.sprite.height = l.size * actorSize.y;
 
77
                }
 
78
                reposition();
 
79
        }
 
80
ENDACTOR()
 
81
 
 
82
private class Light
 
83
{
 
84
        public var sprite : flash.display.Sprite;
 
85
        public var ctr : Point2; //center of the circle
 
86
        public var r : Point2;  //radius of the ellipse
 
87
        public var ang : Float; //current angle of the light
 
88
        public var speed : Float;
 
89
        public var size : Float;
 
90
        
 
91
        public function new() 
 
92
        { 
 
93
                sprite = new flash.display.Sprite();
 
94
                sprite.cacheAsBitmap = true;
 
95
        }
 
96
}