forked from: forked from: [Stardust] Rain
雨を降らせてみた。
@author paq89
/**
* Copyright die ( http://wonderfl.net/user/die )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1Z8B
*/
// forked from Rodlaiz's forked from: [Stardust] Rain
// forked from paq's [Stardust] Rain
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.getTimer;
import flash.utils.Timer;
import idv.cjcat.stardust.common.clocks.SteadyClock;
import idv.cjcat.stardust.common.emitters.Emitter;
import idv.cjcat.stardust.twoD.renderers.DisplayObjectRenderer;
import flash.geom.Rectangle;
import flash.ui.Mouse;
import flash.utils.Timer;
/**
* 雨を降らせてみた。
* @author paq89
*/
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 60)]
public class Main extends Sprite
{
private var _clock:Timer;
private var _lastPosition:Point;
private static const ZERO_POINT:Point = new Point(0, 0);
private var bmpd:BitmapData = new BitmapData(465, 465, true, 0);
private var bmp:Bitmap = new Bitmap(bmpd);
private var container:Sprite = new Sprite();
private var obstacle:Obstacle = new Obstacle();
private var emitter:Emitter = new RainEmitter(new SteadyClock(1), obstacle);
private var blur:BlurFilter = new BlurFilter(1.5, 1.5, 1);
private var color:ColorMatrixFilter = new ColorMatrixFilter([
1, 0, 0, 0, -55,
0, 1, 0, 0, -55,
0, 0, 1, 0, -5,
0, 0, 0, 1, 0
]);
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var background:Sprite = new Sprite();
var g:Graphics = background.graphics;
g.beginFill(0x000000);
g.drawRect(0, 0, 465, 465);
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer(container);
renderer.addEmitter(emitter);;
//addChild(background);
//bmp.cacheAsBitmap = true;
//bmp.opaqueBackground = 0xffffff;
addChild(bmp);
addChild(obstacle)
stage.addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
//w
_lastPosition = new Point(mouseX, mouseY);
_clock = new Timer(60);
_clock.addEventListener(TimerEvent.TIMER, Evt_frame);
_clock.start();
}
private function _particle():void {
var pX:int = mouseX;
var pY:int = mouseY;
var x0:int = _lastPosition.x;
var y0:int = _lastPosition.y;
var x1:int = pX;
var y1:int = pY;
// Tracé de la ligne (Bresenham)
var error: int;
var dx: int = x1 - x0;
var dy: int = y1 - y0;
var yi: int = 1;
if( dx < dy ){
x0 ^= x1; x1 ^= x0; x0 ^= x1;
y0 ^= y1; y1 ^= y0; y0 ^= y1;
}
if( dx < 0 ){
dx = -dx; yi = -yi;
}
if( dy < 0 ){
dy = -dy; yi = -yi;
}
if( dy > dx ){
error = -( dy >> 1 );
for ( ; y1 < y0 ; y1++ ) {
bmp.bitmapData.fillRect(new Rectangle(x1 - 4, y1 - 4, 8, 8), 0x990000);
error += dx;
if( error > 0 ){
x1 += yi;
error -= dy;
}
}
}else{
error = -( dx >> 1 );
for ( ; x0 < x1 ; x0++ ) {
bmp.bitmapData.fillRect(new Rectangle(x0 - 4, y0 - 4, 8, 8), 0x990000);
error += dy;
if( error > 0 ){
y0 += yi;
error -= dx;
}
}
}
_lastPosition.x = pX;
_lastPosition.y = pY;
}
private function Evt_frame(evt:TimerEvent):void {
bmp.bitmapData.applyFilter(bmp.bitmapData,new Rectangle(0, 0, bmp.bitmapData.width, bmp.bitmapData.height), new Point(), new (4, 4, 2));
}
private function loop(e:Event):void
{
emitter.step();
bmpd.applyFilter(bmpd, bmpd.rect, ZERO_POINT, color);
bmpd.applyFilter(bmpd, bmpd.rect, ZERO_POINT, blur);
bmpd.draw(container);
}
private function onMouseMove(e:MouseEvent):void
{
_particle();
obstacle.x = stage.mouseX;
obstacle.y = stage.mouseY;
obstacle.circleDeflector.x = obstacle.x;
obstacle.circleDeflector.y = obstacle.y;
RainEmitter(emitter).circleZone.x = obstacle.x;
RainEmitter(emitter).circleZone.y = obstacle.y;
if (e) e.updateAfterEvent();
}
}
}
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import frocessing.color.ColorHSV;
import idv.cjcat.stardust.common.actions.CompositeAction;
import idv.cjcat.stardust.common.actions.triggers.DeathTrigger;
import idv.cjcat.stardust.common.clocks.Clock;
import idv.cjcat.stardust.common.initializers.CollisionRadius;
import idv.cjcat.stardust.common.initializers.Mask;
import idv.cjcat.stardust.common.initializers.Mass;
import idv.cjcat.stardust.common.initializers.Scale;
import idv.cjcat.stardust.common.math.UniformRandom;
import idv.cjcat.stardust.twoD.actions.DeathZone;
import idv.cjcat.stardust.twoD.actions.Deflect;
import idv.cjcat.stardust.twoD.actions.Gravity;
import idv.cjcat.stardust.twoD.actions.Move;
import idv.cjcat.stardust.twoD.actions.Oriented;
import idv.cjcat.stardust.twoD.actions.Spawn;
import idv.cjcat.stardust.twoD.actions.SpeedLimit;
import idv.cjcat.stardust.twoD.deflectors.CircleDeflector;
import idv.cjcat.stardust.twoD.emitters.Emitter2D;
import idv.cjcat.stardust.twoD.fields.BitmapField;
import idv.cjcat.stardust.twoD.fields.UniformField;
import idv.cjcat.stardust.twoD.initializers.DisplayObjectClass;
import idv.cjcat.stardust.twoD.initializers.Position;
import idv.cjcat.stardust.twoD.initializers.Velocity;
import idv.cjcat.stardust.twoD.zones.CircleZone;
import idv.cjcat.stardust.twoD.zones.LazySectorZone;
import idv.cjcat.stardust.twoD.zones.Line;
import idv.cjcat.stardust.twoD.zones.RectZone;
import idv.cjcat.stardust.twoD.zones.SinglePoint;
class RainEmitter extends Emitter2D
{
private var _circleZone:CircleZone = new CircleZone(0,0,50);
public function RainEmitter(clock:Clock, obstacle:Obstacle)
{
super(clock);
var spawn:Spawn = new Spawn(new UniformRandom(3, 1));
var lazySector:LazySectorZone = new LazySectorZone(2.5, 1.5);
lazySector.direction.set(0, 1);
lazySector.directionVar = 70;
spawn.addInitializer(new Velocity(lazySector));
spawn.addInitializer(new Position(new SinglePoint(0, -10)));
spawn.addInitializer(new Mask(2));
spawn.addInitializer(new DisplayObjectClass(Rain));
spawn.addInitializer(new Scale(new UniformRandom(0.2, 0.8)));
addInitializer(new Mask(1));
addInitializer(new DisplayObjectClass(Rain));
addInitializer(new Position(new Line(0, 0, 465, 0)));
addInitializer(new Scale(new UniformRandom(0.2, 1)));
var gravity:Gravity = new Gravity();
gravity.addField(new UniformField(0, 0.2));
var deflect:Deflect = new Deflect();
deflect.addDeflector(obstacle.circleDeflector);
var commonActions:CompositeAction = new CompositeAction();
commonActions.mask = 1 | 2;
commonActions.addAction(gravity);
commonActions.addAction(deflect);
commonActions.addAction(new Move());
commonActions.addAction(new Oriented());
commonActions.addAction(new DeathZone(new RectZone(0, 0, 465, 465), true));
commonActions.addAction(new DeathZone(_circleZone, false));
addAction(commonActions);
var deathTrigger:DeathTrigger = new DeathTrigger();
deathTrigger.addAction(spawn);
var dripActions:CompositeAction = new CompositeAction();
dripActions.mask = 1;
dripActions.addAction(deathTrigger);
addAction(dripActions);
}
public function get circleZone():CircleZone {
return _circleZone;
}
public function set circleZone(value:CircleZone):void
{
_circleZone = value;
}
}
class Obstacle extends Sprite {
public var circleDeflector:CircleDeflector
public function Obstacle() {
x = 465 / 2;
y = 465 / 2;
graphics.lineStyle(1, 0xffffff, 0.5);
//graphics.beginFill(0xffffff, 0.5);
graphics.drawCircle(0, 0, 50);
circleDeflector = new CircleDeflector(x, y, 50);
circleDeflector.bounce = 0;
}
}
class Rain extends Sprite
{
static private var col:int = 180;
public function Rain():void
{
var color:ColorHSV = new ColorHSV(col+Math.random()*60>>0, 0.7);
graphics.beginFill(color.value);
graphics.drawRect(0, 0, 2, 10);
}
}