大気中のエネルギーを集めて攻撃!みたいな
マウスでクリック。
重力シミュレータ?
なんかやってく内にエネルギー弾みたいになった
/**
* Copyright coppieee ( http://wonderfl.net/user/coppieee )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/o5TO
*/
//マウスでクリック。
//重力シミュレータ?
//なんかやってく内にエネルギー弾みたいになった
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;
public class Main extends Sprite
{
private static const WIDTH:Number = 462;
private static const HEIGHT:Number = 462;
private static const PARTICLE_CONT:Number = 3000;
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);
}
private function onClick(e:MouseEvent):void
{
var g:Particle = new Particle(stage.mouseX, stage.mouseY);
_gravitys.pop();
_gravitys.push(g);
}
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 / 4 * 0xFF) & 0xFF) << 8) | 0x0000FF;
}
_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;
}
}