forked from: flash on 2012-6-27
StarryNight
ver. 0.1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Author: matt carpenter
http://orangesplotch.com
License: This code is released under the
Creative Commons Attribution-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-sa/2.5/
Twinkle, twinkle, hundreds of little stars.
import everything you need (and more)
/**
* Copyright smck87 ( http://wonderfl.net/user/smck87 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/t0e3
*/
// forked from dwoldo's flash on 2012-6-27
/*
StarryNight
ver. 0.1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Author: matt carpenter
http://orangesplotch.com
License: This code is released under the
Creative Commons Attribution-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-sa/2.5/
Twinkle, twinkle, hundreds of little stars.
*/
package {
// import everything you need (and more)
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.geom.Rectangle;
[SWF(width="800", height="600", frameRate="60", backgroundColor="#11FFFF")]
public class StarryNight extends Sprite
{
private var bg:Sprite;
private var stars:Array;
public function StarryNight()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
// set up the background (black)
bg = new Sprite();
bg.graphics.beginFill(0);
bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
addChild(bg);
// make the stars
for (var i:Number = 0; i<100; ++i) {
var star:Sprite = new Sprite();
star.graphics.beginFill(0xFFFFFF);
star.graphics.drawCircle(0, 0, ((Math.random() * 1.25) + 14.25));
star.x = Math.random() * stage.stageWidth;
star.y = Math.random() * stage.stageHeight;
star.addEventListener(Event.ENTER_FRAME, Twinkle);
addChild(star);
}
}
public function Twinkle(event:Event):void {
// get the current star to tweak
var _self:Sprite = Sprite(event.currentTarget);
// change the alpha and size of the star
_self.alpha += Math.random() * 0.02 - 0.01;
_self.scaleX = _self.alpha * 0.5 + 0.5;
_self.scaleY = _self.alpha * 0.5 + 0.5;
// do some bounds checking
if (_self.alpha < 0.5) _self.alpha = 0.5;
if (_self.alpha > 1) _self.alpha = 1;
}
} // end StarryNight class
} // end package