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

forked from: [セルフフォーク]ひだまりスケッチ ほしみっつ の星 噴水バージョン

visible = false
ちょっとははやくなったかしら
各回転をBitmapData化するのが一番てっとりばやそうだけど
// forked from Hiiragi's [セルフフォーク]ひだまりスケッチ ほしみっつ の星 噴水バージョン
// visible = false
// ちょっとははやくなったかしら
// 各回転をBitmapData化するのが一番てっとりばやそうだけど
package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Matrix;
	import flash.net.FileReference;
	import flash.utils.Timer;
	
	import net.hires.debug.*;
	
	//import com.bit101.components.PushButton;
	
	/**
	 * ひだまりスケッチ ほしみっつ の星 を飛び散るようにしてみた 噴水バージョン
	 * @author Hiiragi
	 * 
	 * セルフフォーク その2
	 * 
	 * その1と同じように、「オブジェクトプール」を試してみた感じです。
	 * 
	 * 最初に720個の星と初期設定をしてるので、最初若干重いです。
	 * 
	 * rotationさせたら一気に重くなったので、
	 * 星の一番外側の白枠を消すことで、一応少しパフォーマンスアップ。
	 */
	
	[SWF(width = 465, height = 465, frameRate = 60, backgroundColor = 0xFFFFFF)]
	public class Main2 extends Sprite 
	{
		
		public function Main2():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addChild(new Stats());
			start();
		}
		
		private function start():void 
		{
			
			var mtx:Matrix = new Matrix();
			mtx.createGradientBox(this.stage.stageWidth, this.stage.stageHeight, Math.PI / 2);
			var g:Graphics = this.graphics;
			g.beginGradientFill(GradientType.LINEAR, [0xFFEEEE, 0xFFFFFF], [1, 1], [0, 255], mtx);
			g.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
			g.endFill();
			mouseChildren = mouseEnabled = false;
			var fountain:HidamariStarFountain = new HidamariStarFountain(this.stage.stageWidth, this.stage.stageHeight);
			this.addChild(fountain);
		}
	}
	
}



import adobe.utils.ProductManager;
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.Matrix;
import flash.geom.Point;

class HidamariStarFountain extends Sprite
{
	private const STAR_MAX:uint = 50;
	private const BURST_NUM:int = 60;
	
	private var _sw:int;
	private var _sh:int;
	
	private var _starPool:Array;
	private var _activeStars:Array;
	
	private var _gravity:Number = 0.98;
	private var _fountainX: Number;
	private var _fountainY: Number;
	private var count: int;
	
	public function HidamariStarFountain(stageWidth:int, stageHeight:int)
	{
		_sw = stageWidth;
		_sh = stageHeight;
		
		_fountainX = _sw / 2
		_fountainY = _sh + 100;
		
		_starPool = [];
		_activeStars = [];
		
		var star:HidamariStarExtend;
		var absX:Number;
		var absY:Number;
		
		for (var i:int = 0; i < STAR_MAX; i++) 
		{
			star = new HidamariStarExtend(Math.random() * 40 + 10);
			
			star.visible = false;
			
			this.addChild(star);
			_starPool[i] = star;
		}
		
		this.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
	}
	
	private function onEnterFrameHandler(e:Event):void 
	{
		var star: HidamariStarExtend;
		if (_starPool.length > 0)
		{
			star = _starPool.pop();
			star.x = _fountainX;
			star.y = _fountainY;
			star.vx = Math.random() * 30 - 15;
			star.vy = -35;
			star.visible = true;
			if (!star.isActive) 
			{
				star.isActive = true;
				_activeStars.push(star);
			}
		}
		
		
		var n: int = _activeStars.length;
		while(n --)
		{
			star = _activeStars[n];
			if (star.visible)
			{
				star.vy += _gravity;
				star.x += star.vx;
				star.y += star.vy;
				star.rotation += 10;
				if (
					star.x < - 25 || star.x > _sw + 25 ||
					star.y < - 25 || star.y > _sh + 125
				)
				{
					//_activeStars.splice(n, 1);
					_starPool.push(star);
					star.visible = false;
				}
			}
		}
	}
}

class HidamariStar extends Sprite
{
	private var _cx:Number;
	private var _cy:Number;
	private var _radius:Number;
	private var _insideRatio:Number;
	
	private var _secondStar:Shape;
	private var _centerStar:Shape;
	
	private var _secondStarBevelFilter:BevelFilter;
	private var _centerStarBevelFilter:BevelFilter;
	private var _bmp: Bitmap;
	private var _bmd: BitmapData;
	
	public function HidamariStar(radius:Number,
								 cx:Number = 0, 
								 cy:Number = 0, 
								 insideRatio:Number = 0.5) 
	{
		_radius = radius;
		_cx = cx;
		_cy = cy;
		_insideRatio = insideRatio;
		
		_secondStar = new Shape();
		_centerStar = new Shape();
		addChild(_bmp = new Bitmap());
		_secondStarBevelFilter = new BevelFilter(2, -45, 0x996666, 1, 0, .3, 2, 2, 1, 2, BitmapFilterType.OUTER, false);
		_centerStarBevelFilter = new BevelFilter(2, -45, 0x996666, 1, 0, .5, 2, 2, 1, 2, BitmapFilterType.OUTER, false);
		_secondStar.filters = [_secondStarBevelFilter];
		_centerStar.filters = [_centerStarBevelFilter];
		
		draw();
	}
	
	public function draw():void 
	{
		var mtx:Matrix = new Matrix();
		
		var g:Graphics = this.graphics;
		//g.clear();
		
		//g.beginFill(0xFFFFFF);
		//g.lineStyle(10, 0xFFFFFF);
		//drawStar(g, _radius);
		//g.endFill();
		
		g = _secondStar.graphics;
		g.clear();
		mtx.createGradientBox(_radius * 2, _radius * 2, -Math.PI / 4, -_cx -_radius, -_cy - _radius);
		g.beginGradientFill(GradientType.LINEAR, [0xf0ac96, 0x780100], [1, 1], [0, 255], mtx);
		drawStar(g, _radius * .95);
		g.endFill();
		
		g = _centerStar.graphics;
		g.clear();
		mtx.createGradientBox(_radius * 2, _radius * 2, -Math.PI / 4, -_cx -_radius, -_cy - _radius);
		g.beginGradientFill(GradientType.LINEAR, [0xfdf9fa, 0xfdae10], [1, 1], [0, 255], mtx);
		drawStar(g, _radius * 0.8);
		g.endFill();
		if (_bmd) _bmd.dispose();
		this.addChild(_secondStar);
		this.addChild(_centerStar);
		_bmd = new BitmapData(this.width, this.height, true, 0);
		_bmd.draw(this, new Matrix(1, 0, 0, 1, this.width / 2, this.height / 2), null, null, null, true);
		_bmp.bitmapData = _bmd;
		_bmp.smoothing  = true;
		this.removeChild(_secondStar);
		this.removeChild(_centerStar);
		_bmp.x = - _bmp.width / 2;
		_bmp.y = - _bmp.height / 2;
	}
	
	private function drawStar(g:Graphics, radius:Number):void
	{
		g.moveTo(_cx, _cy - radius);
		
		var diffRad:Number = Math.PI * 2 / 10;
		var rad:Number = -Math.PI / 2;
		var tempRadius:Number;
		
		for (var i:int = 1; i <= 10; i++)
		{
			rad += diffRad;
			tempRadius = (i % 2 == 1) ? tempRadius = radius * _insideRatio : tempRadius = radius;
			g.lineTo(Math.cos(rad) * tempRadius + _cx, Math.sin(rad) * tempRadius + _cy);
		}
	}
	
	public function get radius():Number { return _radius; }
	
	public function set radius(value:Number):void 
	{
		_radius = value;
		draw();
	}
	
	public function get insideRatio():Number { return _insideRatio; }
	
	public function set insideRatio(value:Number):void 
	{
		_insideRatio = value;
		draw();
	}
	
}


class HidamariStarExtend extends HidamariStar
{
	public var vx:Number;
	public var vy: Number;
	public var isActive: Boolean = false;
	
	public function HidamariStarExtend(radius:Number,
								 cx:Number = 0, 
								 cy:Number = 0, 
								 insideRatio:Number = 0.5) 
	{
		super(radius, cx, cy, insideRatio);
	}
}