float cross
2009.09.29 effect追加
2009.09.29 Bitmap化で動作軽くなった?
/**
* Copyright iong ( http://wonderfl.net/user/iong )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iYM7
*/
package
{
/* 2009.09.29 effect追加 */
/* 2009.09.29 Bitmap化で動作軽くなった? */
import flash.display.Sprite;
[SWF(width="465", height="465", backgroundColor="0x003366", frameRate="30")]
public class Rad extends Sprite
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.BlendMode;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.display.StageQuality;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
var Sp:Bitmap;
var SpR:Sprite;
var cv:BitmapData;
var arySp:Array = new Array();
var iP1:uint = 2;
var iP2:uint = 1;
public function Rad():void
{
stage.quality = StageQuality.LOW;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
cv = new BitmapData(465, 465, true, 0x000000);
addChild(new Bitmap(cv));
SpR = new Sprite();
addChild(SpR);
addEventListener(Event.ENTER_FRAME, makeAll);
Sp = SPPiece(iP1, iP2);
}
private function makeAll(e:Event):void
{
Sp = SPPiece(iP1, iP2);
SpR.addChild(Sp);
arySp.push(Sp);
Sp.name = "p"+arySp.length;
Sp.scaleX = Math.round(Math.random()*1500)/100;
Sp.scaleY = Sp.scaleX;
Sp.alpha = 0.6;
Sp.x = Math.round(Math.random()*stage.stageWidth);
Sp.y = stage.stageHeight + 50;
moveAll();
cv.draw(SpR, null, null, BlendMode.OVERLAY);
cv.applyFilter(cv, cv.rect, new Point(), new BlurFilter(16,16));
}
private function moveAll():void
{
var m:int;
for(m=0; m<arySp.length; m++){
var target:Bitmap = arySp[m];
movePiece(target);
}
}
private function movePiece(p:Bitmap):void
{
p.rotation+=5;
// p.x += 4 * Math.cos(Math.PI/180*p.rotation) + (mouseX-stage.stageWidth/2)/20;
p.x += (mouseX-stage.stageWidth/2)/20;
p.y -= 2 + p.scaleX/2;
if(p.x>=stage.stageWidth+p.width) p.x -= stage.stageWidth + 100;
if(p.x<=0-p.width) p.x += stage.stageWidth + 100;
if(p.y<=-(p.height+80)*p.scaleX){
var iP:uint = int(p.name.substr(1));
SpR.removeChildAt(iP);
arySp.splice(iP,1);
}
}
public function SPPiece(n1:uint, n2:uint):Bitmap
{
var tBD:BitmapData = new BitmapData(n1*2, n1*2, true, 0);
var iC:int = retC(100);
for(var i:int=0; i<n1*2; i++){
for(var k:int=0; k<n1*2; k++){
if( (i<n2 && k<n2) || (i<n2 && k>=n1*2-n2) || (i>=n1*2-n2 && k<n2) || (i>=n1*2-n2 && k>=n1*2-n2)){
//tBD.setPixel(i, k, 0x000000);
}else tBD.setPixel32(i, k, iC);
}
}
var _mat:Matrix = new Matrix();
tBD.draw(tBD, _mat);
return new Bitmap(tBD);
}
// ランダムカラーをreturn
private function retC(n:uint):int
{
var ofR:int = n+Math.round(Math.random()*(255-n));
var ofG:int = n+Math.round(Math.random()*(255-n));
var ofB:int = n+Math.round(Math.random()*(255-n));
return parseInt("0xff"+ ofR.toString(16)+ ofG.toString(16) + ofB.toString(16));
}
}
}