In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Raster shade effect, high res

Simple raster shade effect
@author Martin Jonasson (m@grapefrukt.com)
Get Adobe Flash player
by grapefrukt 12 Jan 2011
/**
 * Copyright grapefrukt ( http://wonderfl.net/user/grapefrukt )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kIHP
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    import net.hires.debug.Stats;
    import flash.display.StageQuality;
    
    /**
     * Simple raster shade effect
     * @author Martin Jonasson (m@grapefrukt.com)
     */
    
    public class Main extends Sprite {
        
        private var _points    :Vector.<Point>;
        
        private static const P_COUNT_X:int = 90;
        private static const P_COUNT_Y:int = 90;
        private static const P_COUNT:int = P_COUNT_X * P_COUNT_Y;
        private static const P_SPACING:int = 5;
        
        public function Main():void {            
            _points = new Vector.<Point>(P_COUNT_X * P_COUNT_Y, true);
            
            for (var i:int = 0; i < P_COUNT; i++) {
                _points[i] = new Point((i % P_COUNT_X) * P_SPACING, int(i / P_COUNT_Y) * P_SPACING);
                if ((i % P_COUNT_Y) % 2) _points[i].y += P_SPACING * .5;
            }
            
            addChild(new Stats);
            
            stage.quality = StageQuality.HIGH;
            
            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }
        
        private function handleEnterFrame(e:Event):void {
            graphics.clear();
            graphics.beginFill(0x000000);
            
            var i:int;
            var d:Number;
            
            for (i = 0; i < P_COUNT; i++) {                
                d = (_points[i].x - mouseX) * (_points[i].x - mouseX) + (_points[i].y - mouseY) * (_points[i].y - mouseY);
                if (d < 125000) {
                    d = (1 - d / 125000);
                    d = d * d * d;
                    
                    graphics.drawCircle(_points[i].x, _points[i].y, 2 * d);
                }
                
            }
        }
        
    }
    
}