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

AS3版Liquid Particles

元ネタ:http://www.chromeexperiments.com/detail/liquid-particles/
Get Adobe Flash player
by termat 28 May 2010
/**
 * Copyright termat ( http://wonderfl.net/user/termat )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ofYX
 */

/*
 元ネタ:http://www.chromeexperiments.com/detail/liquid-particles/
*/
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	[SWF(width = "480", height = "480", backgroundColor = "0x000000", fps = "30")] 
	public class Practice72 extends Sprite{
		private var num:int = 500;
		private var circles:Array;
		private var bmp:BitmapData;
		private var pmx:Number=0, pmy:Number=0;
		private var isDown:Boolean = false;
		
		public function Practice72() {
			bmp = new BitmapData(480, 480, false, 0x000000);
			addChild(new Bitmap(bmp));
			circles = new Array();
			for (var i:int = 0; i < num; i++) {
				var c:Circle = new Circle();
				c.x  = Math.random() * 480;
				c.y  = Math.random() * 480;
				c.vx = Math.cos(i) * Math.random() * 25;
				c.vy = Math.sin(i) * Math.random() * 25;
				c.color = Math.random()*0xffffff;
				circles.push(c);
				addEventListener(Event.ENTER_FRAME, update);
				stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void { isDown = true } );
				stage.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void { isDown = false } );
			}
		}
		
		private function update(e:Event):void {
			bmp.fillRect(bmp.rect, 0x000000);
			for each(var c:Circle in circles) {
				c.move(mouseX, mouseY, pmx, pmy, isDown);
				c.draw(bmp);
			}
			pmx = mouseX;
			pmy = mouseY;
		}
	}

}
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.BlendMode;

class Circle {
	public var color:uint;
	public var x:Number=0;
	public var y:Number=0;
	public var vx:Number=0;
	public var vy:Number=0;
	public var size:Number = 0;
	private var obj:MovieClip;
	public static var friction:Number = 0.96;
	private static var width:Number = 480;
	private static var height:Number = 480;
	private static var toDist:Number = width / 1.15;
	private static var stirDist:Number= width / 8;
	private static var blowDist:Number = width / 2;
	
	public function Circle():void {
		obj = new MovieClip();
	}
	
	public function move(mx:Number, my:Number,dmx:Number, dmy:Number,mb:Boolean):void {
		var dx:Number = x - mx;
		var dy:Number = y - my; 
		var d:Number = Math.sqrt(dx * dx + dy * dy);
		var a:Number = Math.atan2(dy, dx);
		var cosA:Number = Math.cos(a);
		var sinA:Number = Math.sin(a);
		if (mb){
			if(d<blowDist){
				var blowAcc:Number = ( 1 - ( d / blowDist ) ) * 14;
				vx += cosA * blowAcc + .5 - Math.random();
				vy += sinA * blowAcc + .5 - Math.random();
			}
		}
		if (d < toDist ) {
			var toAcc:Number = (1 - (d / toDist)) * width * .0014;
			vx -= cosA * toAcc;
			vy -= sinA * toAcc;
		}
		if(d<stirDist){
			var mAcc:Number = (1 - (d / stirDist)) * width * .00022;
			vx += dmx * mAcc;
			vy += dmy * mAcc;			
		}
		vx *= friction;
		vy *= friction;
		var avgVX:Number = Math.abs(vx);
		var avgVY:Number = Math.abs(vy);
		var avgV:Number = (avgVX + avgVY) * 0.5;
		if( avgVX < 0.1 ) vx *= Math.random() * 3;
		if ( avgVY < 0.1 ) vy *= Math.random() * 3;
		var sc:Number = avgV * .45;
		sc = Math.max( Math.min( sc , 3.5 ) , .4 );
		var nextX:Number = x + vx;
		var nextY:Number = y + vy;
		if( nextX > width ){
			nextX = width;	vx *= -1;
		}else if( nextX < 0 ){
			nextX = 0;	vx *= -1;
		}
		if( nextY > height){
			nextY = height;	vy *= -1;
		}else if( nextY < 0 ){
			nextY = 0;	vy *= -1;
		}
		x  = nextX;
		y  = nextY;		
		size = Math.max(Math.min(avgV * 0.45, 3.5), 0.4 );
	}
	
	public function draw(bmp:BitmapData):void {
		obj.graphics.clear();
		obj.graphics.beginFill(color);
		obj.graphics.drawCircle(x, y, size);
		obj.graphics.endFill();
		bmp.draw(obj, null, null, BlendMode.ADD, null, false);
	}
}