scroll() test
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ivuo
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageQuality;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.BitmapFilter;
import flash.filters.BlurFilter;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.Timer;
[SWF(frameRate="120", width="465", height="465", backgroundColor="#000000")]
public class Scroller extends Sprite
{
private var _view :Sprite;
private var _canvas :BitmapData ;
private var _canvasClone:BitmapData ;
public function Scroller():void
{
stage.quality = StageQuality.BEST;
_canvas = new BitmapData(465,465, true, 0x00000000);
_canvasClone = new BitmapData(465,465, true, 0x00CCCCCC);
_view = new Sprite();
addChild(_view);
addChild(new Bitmap(_canvas));
addChild(new Bitmap(_canvasClone));
for(var i:int = 0; i < 1; i++)
{
_view.addChild(new Velocity());
}
createBG()
addEventListener(Event.ENTER_FRAME, draw);
}
private function createBG():void
{
var matr:Matrix = new Matrix();
matr.createGradientBox(465, 465, Math.PI / 2, 0, 0);
var bg:Sprite = new Sprite();
bg.graphics.beginGradientFill
(
GradientType.LINEAR,
[0x002B5E, 0x000000], //colors
[1, 1], //alphas
[0, 255], //ratios
matr, //matrix
SpreadMethod.PAD
);
bg.graphics.drawRect(0, 0, 465, 465);
bg.graphics.endFill();
/*
bg.graphics.beginFill(0xffffff, 0.3);
for(var i:int = 0; i<150; i++)
bg.graphics.drawCircle(Math.random() * 465, Math.random() * 232, Math.random() * 1.5);
bg.graphics.endFill();
*/
addChildAt(bg, 1);
}
private var blur:BitmapFilter = new BlurFilter( 40, 40, 3);
private var op :Point = new Point(0,0);
private var op2:Point = new Point(0,0);
private function draw(e:Event):void
{
_canvas.draw(_view);
_canvas.applyFilter( _canvas, _canvas.rect, op, blur );
// _canvas.copyPixels( _canvas, _canvas.rect, op2 );
// _canvas.scroll( 20, 20 );
// _canvas.scroll( -20, -20 );
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.BlendMode;
class Velocity extends Sprite
{
private var _sprite :Sprite;
private var _easing :Number= 1;
private var _vx :Number = 0//Math.random() * 20;
private var _vy :Number = 0;
private var _k :Number= 0.40;
private var _damp :Number= 0.0;
private var _timer :Timer;
public function Velocity()
{
_sprite=new Sprite();
var chance:Number = 0.0;
// var chance:Number = Math.random();
(Math.random() < 0.15) ? _sprite.blendMode = BlendMode.ADD : _sprite.blendMode = BlendMode.ADD;
_sprite.graphics.beginFill(0xFFFFFF, 0.8);
// _sprite.graphics.beginFill(255 * 255 * 255, 0.8 + 0.1);
_sprite.graphics.drawCircle(0,0, 20);
_sprite.graphics.endFill();
_sprite.x= 0;
_sprite.y= 0;
addChild(_sprite);
_timer = new Timer(10);
_timer.addEventListener("timer",onTimer);
_timer.start();
}
public function onTimer(event:TimerEvent):void
{
var mx:Number, my:Number
//Random area in the middle, if the user hasn't used their mouse yet
if(mouseX == 0 || mouseY == 0)
{
mx = 232;
my = 232;
}
else
{
mx = mouseX
my = mouseY
}
var ax:Number = (mx - _sprite.x)*_k;
var ay:Number = (my - _sprite.y)*_k;
_vx += ax * _easing;
_vy += ay * _easing;
_sprite.x += _vx;
_sprite.y += _vy;
_vx *= _damp;
_vy *= _damp;
if(Math.random() > 0.8)
parent.setChildIndex(this, int(Math.random() * parent.numChildren));
}
}