Simple particles 3 (100k)
forked from Simple particles 2 (100k) (diff: 9)
ActionScript3 source code
/**
* Copyright Thy ( http://wonderfl.net/user/Thy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dcJv
*/
package {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Rectangle;
//
public class Main extends Sprite
{
// number of particles and the Vector for them
private var num:uint = 100000
private var parts:Vector.<Part> = new Vector.<Part>(num)
// Bitmap and it's Data
private var B:Bitmap
private var D:BitmapData
// temp Part
private var p:Part
// var used for fill the Data
private var R:Rectangle
public function Main()
{
// init the Bitmap and it's Data
D = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0)
B = new Bitmap(D, "auto", true)
R = D.rect
stage.addChild(B)
// init particles
initPart()
// enterFrame listener
stage.addEventListener(Event.ENTER_FRAME, ef)
}
private function initPart():void
{
// temp uint (count)
var i:uint = 0
// create the first particle
p = new Part()
parts[0] = p
// temp var stage width, stage height
var w:Number = stage.stageWidth, h:Number = stage.stageHeight
// create others particles
while(++i < num)
{
p = new Part(Math.random()*w,Math.random()*h)
parts[i] = p
// assign some reference, for the looping process
parts[i-1].next = p
}
}
// temp Number for position storeage
private var X:Number, Y:Number;
private function ef(e:Event = null):void
{
// lock, for performace
D.lock()
// clear the Data
D.fillRect(R, 0)
// process for the first particle
p = parts[0]
D.setPixel((X = p.x += (mouseX - p.x)), Y = p.y += (mouseY - p.y), 0xFFFFFF)
// process for others particles
while( (p = p.next) != null)
{
D.setPixel(X = p.x += (1.1*X - p.x)*.9, Y = p.y += (1.1*Y - p.y)*.9, 0xFFFFFF)
if(p.x < 0) p.x += 465 else if(p.x > 465) p.x /= 465;
if(p.y < 0) p.y += 465 else if(p.y > 465) p.y /= 465;
}
// finally unlock
D.unlock()
}
}
}
class Part
{
public var x:Number, y:Number
public var next:Part
public function Part(x:Number = 0, y:Number = 0)
{
this.x = x
this.y = y
}
}