Other CAAT actors

CAAT.StarActor

This object draws stars of an arbitrary number of arms. It is defined by two values, an external and an internal radius. The method initialize(arms, max_radius, min_radius).

Stars have the first arm at zero degrees, but this can be modified by calling the method setInitialAngle(angle_in_radians.

A star object can be filled and or stroked. The Actor base methods setFillStyle(fill_style) which accepts from plain colors to gradients and setStrokeStyle(style) will do.

The method setCompositeOp(op) which accepts any value of set rendering context's composite operation.

Stars, since are CAAT.Actor objects, accept behaviors, affine transformations, transparency, etc.

This actor only works with a Canvas renderer.

Example

Move the mouse over the black area to randomly see some colored Circle-Shaped or Rectangle-Shaped actors. Upon behavior expiration (ie, elements en moving and fading), the correspondent Actor is marked as expired and discardable, so it will be removed from Scene.

            var _director_8 = new CAAT.Director().initialize(700,300,'_c8').
                    setClear(false);

            var _scene_8 = _director_8.createScene();

            var colors= [ 'blue', 'red', 'yellow', 'white', 'gray' ,'orange' ];
            var color_index=0;

            // create a container, equals in size to the director.
            var root = new CAAT.Foundation.ActorContainer().
                    setBounds(0, 0,
                    _director_8.canvas.width, _director_8.canvas.height).
                    setFillStyle('#000000')
            root.mouseEnter = function(mouseEvent) {
            };
            root.mouseExit = function(mouseEvent) {
            };

            _scene_8.addChild(root);

            // on mouse move over the root Actor
            root.mouseMove = function(mouseEvent) {

                var r = 10 + 15 * Math.random();

                var star;

                star = new CAAT.Foundation.UI.StarActor().
                        initialize( 6, r, 5 ).
                        setInitialAngle( Math.random()*2*Math.PI ).
                        setLocation(mouseEvent.point.x, mouseEvent.point.y).
                        setSize(r, r).
                        enableEvents(false).
                        setCompositeOp('lighter').
                        setFillStyle( colors[(color_index++)%colors.length] );

                root.addChild(star);

                // fade from opacity to total transparency
                var ab = new CAAT.Behavior.AlphaBehavior().
                        setFrameTime(_scene_8.time + 2000, 500 +  500 * Math.random()).
                        setValues(1, 0).
                        addListener(
                    // when the container behavior is expired, expire and discard
                    // the actor.
                            {
                                behaviorExpired : function(behaviour, time, actor) {
                                    actor.
                                            setDiscardable(true).
                                            setExpired(true);
                                }
                            });

                star.addBehavior(ab);
            };

            var span = document.getElementById('_c8_data');

            _scene_8.onRenderEnd= function() {
                span.innerText= 'Actors: '+root.getNumChildren();
            };

            CAAT.loop(20);