particle test
CPU testing
2009.09.30 1個のサイズを大きくした。数調整
♥0 |
Line 117 |
Modified 2009-09-30 12:06:02 |
MIT License
archived:2017-03-20 09:26:26
ActionScript3 source code
/**
* Copyright iong ( http://wonderfl.net/user/iong )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5kdV
*/
package
{
/* CPU testing */
/* 2009.09.30 1個のサイズを大きくした。数調整 */
import flash.display.Sprite;
[SWF(width="465", height="465", backgroundColor="#000000", frameRate="30")]
public class Ptest extends Sprite
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
var iPCnt:uint = 50;
var aryP:Array = new Array();
var spR:Sprite;
var cv:BitmapData;
public function Ptest():void
{
stage.quality = StageQuality.LOW;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init();
addEventListener(Event.ENTER_FRAME, moveAll);
}
private function init():void
{
cv = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x0);
spR = new Sprite();
spR.cacheAsBitmap= true;
var tBD:BitmapData;
for(var i:int=0; i<iPCnt; i++){
tBD = new BitmapData(1,1);
tBD.setPixel(0,0, retC(100));
var tB:Sprite = new BPPiece(retC(50));
tB.x = retRandom(stage.stageWidth);
tB.y = retRandom(stage.stageHeight);
var fX:Boolean= (retRandom(1)==0) ? true: false;
var fY:Boolean= (retRandom(1)==0) ? true: false;
var aX:uint = retRandom(3);
var aY:uint = retRandom(3);
var aR:uint = retRandom(5);
tB.scaleX = tB.scaleY = 1+ retRandom(100)/100;
tB.alpha = 0.8;
spR.addChild(tB);
aryP.push(new Array(tB, fX, fY, aX, aY, aR));
}
addChild(new Bitmap(cv));
addChild(spR);
}
private function moveAll(e:Event):void
{
for(var i:int=0; i<aryP.length; i++){
var target:Sprite= aryP[i][0];
target.x += (aryP[i][1]) ? aryP[i][3]: -(aryP[i][3]);
target.y += (aryP[i][2]) ? aryP[i][4]: -(aryP[i][4]);
if(target.x<0 || target.x>stage.stageWidth) aryP[i][1] = !aryP[i][1];
if(target.y<0 || target.y>stage.stageHeight) aryP[i][2] = !aryP[i][2];
target.rotation += aryP[i][5]
}
cv.draw(spR, null, null, BlendMode.LIGHTEN);
cv.applyFilter(cv, cv.rect, new Point(), new BlurFilter(16,16));
}
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));
}
private function retRandom(n:int):uint
{
return Math.round(Math.random()*n);
}
}
}
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
class BPPiece extends Sprite
{
function BPPiece(iC:int):void
{
var ary:Array = retAry();
var tBD:BitmapData= new BitmapData(ary[0].length, ary.length, true, 0);
for(var bpi:int=0; bpi<ary.length; bpi++){
for(var bpm:int=0; bpm<ary[bpi].length; bpm++){
if(ary[bpi].charAt(bpm)=="1") tBD.setPixel32(bpm, bpi, iC);
}
}
var tB:Bitmap= new Bitmap(tBD);
tB.x -= tB.width/2;
tB.y -= tB.height/2;
addChild(tB);
}
function retAry():Array
{
var retVal:String= "";
retVal= '00011111111000'+"\n"
+ '00111111111100'+"\n"
+ '01101100110110'+"\n"
+ '11001100110011'+"\n"
+ '11110011001111'+"\n"
+ '11110011001111'+"\n"
+ '11001111110011'+"\n"
+ '11001111110011'+"\n"
+ '11110011001111'+"\n"
+ '11110011001111'+"\n"
+ '11001100110011'+"\n"
+ '01101100110110'+"\n"
+ '00111111111100'+"\n"
+ '00011111111000';
return retVal.split("\n");
}
}