Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //2017 - http://lifesine.eu
- import flash.display.*;
- import flash.filters.BlurFilter;
- var w = stage.stageWidth;
- var h = stage.stageHeight;
- var hw = w * .5;
- var hh = h * .5;
- var dsqr = hw*hw + hh*hh;
- var np = 1000;
- var p = [];
- for(var i = 0 ; i < np; i++){
- var d = 3 + Math.random() * 3;
- p[i] = addChild(new MovieClip()) as MovieClip;
- p[i].graphics.beginFill(0xFFFFFF);
- //p[i].graphics.drawEllipse(-d * .5,-d * .5, d , d);
- p[i].graphics.drawRect(-d * .5,-d * .5, d , d);
- p[i].graphics.endFill();
- p[i].filters = [new BlurFilter()];
- resetParticle(p[i]);
- }
- function resetParticle(particle:MovieClip):void{
- var s = 3.0;
- particle.vx = Math.random() * 2 * s - s;
- particle.vy = Math.random() * 2 * s - s;
- particle.x = hw;
- particle.y = hh;
- }
- function updateParticle(particle:MovieClip):void{
- if((particle.x < 0 || particle.x > w) ||
- (particle.y < 0 || particle.y > w)){
- resetParticle(particle);
- }
- var a = flash.utils.getTimer() * 0.001;
- var r = 0.01;
- particle.vx += Math.cos(a) * r;
- particle.vy += Math.sin(a) * r;
- particle.x += particle.vx;
- particle.y += particle.vy;
- var dx = hw - particle.x;
- var dy = hh - particle.y;
- var d = (dx*dx + dy*dy);
- var s = map(d,0,dsqr,1.0,10.0);
- particle.scaleX = particle.scaleY = s;
- var dmx = particle.x - stage.mouseX;
- var dmy = particle.y - stage.mouseY;
- var dmsqr = (dmx*dmx + dmy * dmy);
- var t = s * 25.5;
- var ct = particle.transform.colorTransform;
- ct.redOffset = ct.greenOffset = ct.blueOffset = (-t);
- ct.redMultiplier = map(dmsqr,0,dsqr * .25,0,255);
- ct.greenMultiplier = map(dmsqr,0,dsqr,0,255);
- //ct.blueMultiplier = map(dmsqr,0,dsqr * 2,-255,255);
- ct.alphaMultiplier = map(dmsqr,0,dsqr * .25,0.0,1.0);
- particle.transform.colorTransform = ct;
- particle.rotation += particle.vx+particle.vy;
- /*
- var blur = particle.filters[0];
- blur.blurX = blur.blurY = map(dmsqr,0,dsqr * .25,0.0,2.0);
- particle.filters = [blur];
- //*/
- }
- function update(event:Event):void{
- for(var i = 0 ; i < np; i++){
- updateParticle(p[i]);
- }
- }
- this.addEventListener(Event.ENTER_FRAME,update,false,0,true);
- function map(value:Number,
- start1:Number, stop1:Number,
- start2:Number, stop2:Number) {
- var outgoing =
- start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
- var badness:String = null;
- if (outgoing != outgoing) {
- badness = "NaN (not a number)";
- } else if (outgoing == Number.NEGATIVE_INFINITY ||
- outgoing == Number.POSITIVE_INFINITY) {
- badness = "infinity";
- }
- if (badness != null) {
- trace("map(%s, %s, %s, %s, %s) called, which returns %s",
- value, start1, stop1,
- start2, stop2, badness);
- }
- return outgoing;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement