forked from: mask test - rouge
こうですか?
* 違ってたらごめんなさい
// forked from rsakane's mask test - rouge
/*
* こうですか?
* 違ってたらごめんなさい
*/
package
{
/*
星と星が重なったときに色が変わる現象を何とかしたい
*/
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.geom.Matrix;
import flash.system.Security;
import flash.system.LoaderContext;
[SWF(width="465", height="465", frameRate="60", backgroundColor="0x0")]
public class Main extends Sprite
{
private var masks:Vector.<Star> = new Vector.<Star>();
public function Main()
{
Wonderfl.capture_delay(10);
Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, init);
loader.load(new URLRequest("http://farm3.static.flickr.com/2396/2208743887_41266caf64.jpg"), new LoaderContext(true));
}
private function init(event:Event):void
{
var loader:Loader = event.currentTarget.loader;
var matrix:Matrix = new Matrix();
matrix.scale(465 / loader.width, 465 / loader.height);
var bd:BitmapData = new BitmapData(465, 465, false);
bd.draw(loader, matrix);
var bitmap:Bitmap = new Bitmap(bd);
addChild(bitmap);
var maskcontainer:Sprite = new Sprite();
maskcontainer = new Sprite();
addChild(maskcontainer);
for (var i:int = 0; i < 10; i++)
{
var mask:Star = new Star();
masks.push(mask);
maskcontainer.addChild(masks[i]);
}
bitmap.mask = maskcontainer;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
for (var i:int = 0; i < masks.length; i++)
{
masks[i].move();
}
}
}
}
import flash.display.Graphics;
import flash.display.Shape;
// とりあえず負荷軽減のためにShape派生に
class Star extends Shape
{
private var speed:int;
public function Star()
{
// 一気に星を書いちゃいます
const pi:Number = 0.017453; // Math.PI / 180
var flg:Boolean = false;
var r1:int, r2:int;
r1 = 50;
r2 = 22.85;
var g:Graphics = this.graphics;
g.beginFill( 0 );
g.moveTo( Math.cos( 0*pi ) * r1 , Math.sin(0*pi) * r1);
for(var i:int = 36; i<=360; i+=36){
if(flg){
flg = false;
g.lineTo( Math.cos( i*pi ) * r1 , Math.sin(i*pi) * r1);
}else{
flg = true;
g.lineTo( Math.cos( i*pi ) * r2 , Math.sin(i*pi) * r2);
}
}
g.endFill();
this.scaleX = this.scaleY = 0.8;
init();
}
public function init():void
{
speed = Math.random() * 2 + 1;
this.x = Math.random() * 145 + 280;
this.y = 465 + Math.random() * 200;
}
public function move():void
{
this.y -= speed;
this.rotation += speed;
if (this.y <= -10) init();
}
}