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

forked from: 大気中のエネルギーを集めて攻撃!みたいな

マウスでクリック。
重力シミュレータ?
なんかやってく内にエネルギー弾みたいになった
Dan0 added keyboard event
/**
 * Copyright Dan0 ( http://wonderfl.net/user/Dan0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zWM5
 */

// forked from coppieee's 大気中のエネルギーを集めて攻撃!みたいな
//マウスでクリック。
//重力シミュレータ?
//なんかやってく内にエネルギー弾みたいになった
//Dan0 added keyboard event
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	import net.hires.debug.Stats;
import flash.events.KeyboardEvent;
	
	public class Main extends Sprite
	{
		private static const WIDTH:Number = 462;
		private static const HEIGHT:Number = 462;
		private static const PARTICLE_CONT:Number = 10000;
		private var _canvas:BitmapData;
		private var _particles:Vector.<Particle>;
		public function Main():void 
		{
			Wonderfl.capture_delay(5);
			_canvas = new BitmapData(WIDTH, HEIGHT,false,0x000000);
			var bitmap:Bitmap = new Bitmap(_canvas);
			addChild(bitmap);
			
			_particles = new Vector.<Particle>(PARTICLE_CONT, true);
			for (var i:uint = 0; i < PARTICLE_CONT; i++) 
			{
				var p:Particle = new Particle(Math.random() * WIDTH, Math.random() * HEIGHT, 
				Math.random() * 0xFFFFFF);
				var radian:Number = Math.random() * Math.PI * 2;
				var speed:Number = Math.random();
				p.vx = Math.cos(radian)*speed;
				p.vy = Math.sin(radian)*speed;
				_particles[i] = p;
			}
			addEventListener(Event.ENTER_FRAME, update);
			
			addChild(new Stats());
			
			_gravitys = new Vector.<Particle>();
			stage.addEventListener(MouseEvent.CLICK, onClick);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboard);
		}
		private function onClick(e:MouseEvent):void 
		{
			var g:Particle = new Particle(stage.mouseX, stage.mouseY);
			//_gravitys.pop();
			_gravitys.push(g);
		}
private function onKeyboard(e:KeyboardEvent):void 
		{
			_gravitys.shift();
			 
		}
		private var _gravitys:Vector.<Particle>;
		private function update(e:Event):void
		{
			_canvas.lock();
			_canvas.colorTransform(new Rectangle(0, 0, WIDTH, HEIGHT), new ColorTransform (0.9, 0.9, 0.9));
			//var mouseX:Number = stage.mouseX;
			//var mouseY:Number = stage.mouseY;
			for each(var og:Particle in   _gravitys)
			{
				//og.x = stage.mouseX;
				//og.x ++;
				//og.y = stage.mouseY;
				
			}
			for each(var p:Particle in _particles)
			{
				for each(var gp:Particle in _gravitys)
				{
					var dx:Number = gp.x - p.x;
					var dy:Number = gp.y - p.y;
					var g:Number = 70;
					if(true){
						var rr:Number = dx * dx+ dy * dy;
						if (rr > 0 && rr < 5000/g) { rr = 5000/g; }
						else if (rr < 0 && rr > -5000 / g) { rr = -5000/g; }
						var theta:Number = Math.atan2(dy, dx);
						p.vx += Math.cos(theta) * 1 / rr * g;
						p.vy += Math.sin(theta) * 1 / rr * g;
						
					}
				}
				p.vx *= 0.99;
				p.vy *= 0.99;
				p.x += p.vx;
				p.y += p.vy;
				if (p.x < 0) { p.x = WIDTH; }
				else if (p.x > WIDTH) { p.x = 0; }
				if (p.y < 0) { p.y = HEIGHT; }
				else if (p.y > HEIGHT) { p.y = 0; }
				var speed:Number = p.vx * p.vx + p.vy * p.vy;
				var color:uint;
				if (speed > 4)
				{
					color = 0x00FFFF;
				}
				else
				{
					color = (((speed / 20 * 0xFF) & 0xFF) << 8) | 0x000099;
				}
				_canvas.setPixel(p.x, p.y, color);
			}
			_canvas.unlock();
		}
	}
}
class Particle
{
	public var x:Number;
	public var y:Number;
	public var color:uint;
	public var vx:Number = 0;
	public var vy:Number = 0;
	public function Particle(x:Number = 0, y:Number = 0,color:uint = 0xFFFFFF) 
	{
		this.x = x;
		this.y = y;
		this.color = color;
	}
}