Eclipse with the naked eye

by kawamura
ちょうど曇り空で、裸眼で日食を見られた歓び。
♥2 | Line 213 | Modified 2012-05-21 19:08:42 | MIT License
play

ActionScript3 source code

/**
 * Copyright kawamura ( http://wonderfl.net/user/kawamura )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kulF
 */

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    /**
     * ...
     * @author pc98
     */
    [SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "30")]
    public class Main extends Sprite 
    {
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            var viewManager:View = new View();
            addChild(viewManager);
        }
        
    }
}


import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import net.hires.debug.Stats;

/**
 * ...
 * @author pc98
 */
class View extends Sprite 
{
    private var sky:Sky;
    private var ring:SolarRing;
    private var cloud:Cloud;
    
    //
    public function View() 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    
    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        var g:Graphics;
        sky = new Sky();
        addChild(sky);
        //
        ring = new SolarRing();
        ring.x = stage.stageWidth * 0.5;
        ring.y = stage.stageHeight * 0.5;
        addChild(ring);
        //
        cloud = Cloud.getInstance();
        addChild(cloud);
        //
        var stats:Stats = new Stats();
        addChild(stats);
    }
}


import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BitmapFilterQuality;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
class SolarRing extends Sprite 
{
    private var _cloud:Cloud;
    private var moon:Sprite;
    private var bright:Sprite;
    
    public function SolarRing() 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        var g:Graphics;
        var blur:BlurFilter;
        var glow:GlowFilter;
        //
        var sun:Sprite = new Sprite();
        addChild(sun);
        g = sun.graphics;
        g.beginFill(0xFFFFFF);
        g.drawCircle(0, 0, 20);
        //

        moon = new Sprite();
        g.beginFill(0x000000);
        var radian:Number  = 18;
        g.drawCircle(0, 0, radian);
        addChild(moon);

        //
        bright = new Sprite();
        bright.alpha = 1;
        addChild(bright);
        g = bright.graphics;
        g.beginFill(0xFFFFFF);
        g.drawCircle(0, 0, 20);
        //
        blur = new BlurFilter(4, 4, BitmapFilterQuality.HIGH);
        glow = new GlowFilter(0xFFCC33, 1, 8, 8, 1, 32, false, false);
        bright.filters = [blur, glow];

        var cloud:Cloud = Cloud.getInstance();
        cloud.addEventListener(CloudEvent.CLOUD_ALPHA, enterFrameListener);
    }
    
    
    private function enterFrameListener(event:CloudEvent):void 
    {
        var _alpha:Number;
        var g:Graphics;
        
        //
        _alpha = event.value;
        /*
        g = moon.graphics;
        g.clear();
        g.beginFill(0x000000);
        radian  = 18 * (1 -_alpha);
        g.drawCircle(0, 0, radian);
        */
        moon.alpha = 1 - _alpha;
        //
        this.filters = [];
        var value:Number = 2 + (30 * (_alpha) / 255)
        var blur:BlurFilter = new BlurFilter(value , value, BitmapFilterQuality.HIGH);
        var glow:GlowFilter = new GlowFilter(0xFFDDCC, 1, 2, 2, 1, 32, false, false);
        this.filters = [blur, glow];
        //
        var brightAlpha:Number = _alpha *3;
        
        if (brightAlpha > 1) {
            brightAlpha = 1;
        }
        bright.alpha = brightAlpha
    }
    
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
/**
 * ...
 * @author pc98
 */
class Cloud extends Sprite
{
    private var counter:Number;
    private var bmd:BitmapData;
    private var bm:Bitmap;
    private var randam:Number;
    private var offsetList:Array;
    //
    private static var _instance:Cloud;
    public function Cloud(singletonBlock:SingletonBlock) 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    public static function getInstance():Cloud
    {
        
        if ( _instance == null )
        {
            _instance = new Cloud(new SingletonBlock());
        }
        
        return _instance;
    }
    
    private function init(event:Event = null):void
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        bmd = new BitmapData(465+20*2, 465+20*2,true, 0xFFFFFF);
        bm = new Bitmap(bmd);
        bm.x = -20;
        bm.y = -20;
        /**/
        var blur:BlurFilter = new BlurFilter(16, 16, 1);
        bm.filters = [blur]
        addChild(bm);
        //
        randam = Math.floor(Math.random() * 0xFFFF);
        offsetList = [new Point(0, 0), new Point(0, 0)];
        //
        counter = 0;
        enterFrameListener();
        addEventListener(Event.ENTER_FRAME, enterFrameListener);
    }
    
    
    private function enterFrameListener(event:Event = null):void 
    {
        counter += 0.1;
        offsetList[0].x += 3 + 1 * Math.cos(counter);
        offsetList[1].y += 1;
        bmd.perlinNoise(720 , 120 , 2, 50 , true , false , (8 | 0 | 0 | 0) , true , offsetList);
        //
        var _alpha:Number;
        _alpha = ((bmd.getPixel32(stage.stageWidth * 0.5, stage.stageHeight * 0.5) >> 24) & 0xFF) / 255;
        
        var cloudEvent:CloudEvent = new CloudEvent(CloudEvent.CLOUD_ALPHA);
        cloudEvent.value = _alpha;
        dispatchEvent(cloudEvent);
    }
    
}
class SingletonBlock { }

import flash.events.Event;

/**
 * ...
 * @author pc98
 */
class CloudEvent extends Event 
{
    public var value:Number;
    public static const CLOUD_ALPHA:String = "cloud_alpha";
    public function CloudEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) 
    { 
        super(type, bubbles, cancelable);
        
    } 
    
    public override function clone():Event 
    { 
        return new CloudEvent(type, bubbles, cancelable);
    } 
    
    public override function toString():String 
    { 
        return formatToString("CloudEvent", "type", "bubbles", "cancelable", "eventPhase"); 
    }
}


import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;

/**
 * ...
 * @author pc98
 */
class Sky extends Sprite 
{
    public function Sky() 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    
    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        //
        var g:Graphics;
        //
        g = this.graphics;
        g.beginFill(0x666666);
        g.drawRect(0, 0, 465, 465);
    }
    
}