
www.flashandmath.com.
import com.flashandmath.dg.objects.*;
import com.flashandmath.dg.display.*;
var origin:Point;
var waitCount:int;
var count:int;
var display:RainDisplay;
var blur:BlurFilter;
var darken:ColorTransform;
var bitmapData:BitmapData;
var bitmap:Bitmap;
var timer:Timer;
var frame:Shape;
var dropStartMargin:Number;
var variance:Number;
var dropsToAddEachFrame:int;
var t:Number;
///////////////////////
init();
function init():void {
//This is how long to wait (in Timer ticks) before adding more drops to the stage:
waitCount = 12;
count = waitCount-1;
dropsToAddEachFrame = 1;
//This BlurFilter is not used, but see below in the onEnter function for a
//suggestion on how it can be used.
blur = new BlurFilter(2,2);
origin = new Point(0,0); //to be used with the blur filter.
//This ColorTransform is used to fade out the pictures drawn in the
//animation (instead of erasing them out completely). You can experiment
//with different parameters in this ColorTransform.
darken = new ColorTransform(1,1,1,0.8);
display = new RainDisplay(550,300,false);
display.x = 10;
display.y = 10;
display.defaultDropColor = 0x666666;
display.randomizeColor = true;
//For this example, we use raindrops with completely random coloring:
display.colorMethod = "random";
display.defaultDropThickness = 2;
display.splashThickness = 2;
display.defaultDropAlpha = 1;
display.splashAlpha = 1;
display.gravity = 0.15;
//In this example, we want the raindrops to drip from the top,
//so we set the initial velocity to zero:
display.defaultInitialVelocity = new Point(0,0);
display.initialVelocityVariancePercent = 0;
display.initialVelocityVarianceX=0;
display.initialVelocityVarianceY=0;
display.dropLength = "long";
display.splashMaxVelX = 1;
display.splashMinVelX = -1;
display.splashMinVelY = 1;
display.splashMaxVelY = 2;
display.minSplashDrops = 5;
display.maxSplashDrops = 12;
display.removeDropsOutsideXRange = false;
//The parameters below create drops which "stick" to the
//top of the display for a short time before breaking free
//and falling to the ground.
display.globalBreakawayTime = 100;
display.breakawayTimeVariance = 0.5;
dropStartMargin = 100;
//The RainDisplay is actually not displayed on the stage. Instead, it is drawn to
//a bitmap. This method allows for a filter-based fading effect to be used.
bitmapData = new BitmapData(display.displayWidth, display.displayHeight, true, 0x00000000);
bitmap = new Bitmap(bitmapData);
bitmap.x = display.x;
bitmap.y = display.y;
frame = new Shape();
frame.graphics.lineStyle(1,0x444444);
frame.graphics.drawRect(-1,-1,display.displayWidth+1, display.displayHeight+1);
frame.x = display.x;
frame.y = display.y;
stage.addChild(frame);
stage.addChild(bitmap);
display.wind = new Point(0,0);
timer = new Timer(10,0);
timer.start();
timer.addEventListener(TimerEvent.TIMER, onEnter);
}
function onEnter(evt:Event):void {
//add more raindrops
count++
if (count >= waitCount) {
count =0;
for (var i:int = 0; i <= dropsToAddEachFrame-1; i++) {
var thisDrop = display.addDrop(Math.random()*display.displayWidth,Math.random());
thisDrop.radiusWhenStill = 1+1*Math.random();
}
}
//update drops
display.update();
//We now draw the rain display to the main bitmap, after applying a ColorTransform
//which causes the previously drawn pictures to fade out.
//You can also try using the BlurFilter commented out below, to achieve a
//different effect. This can be used on its own or in combination with the
//darken ColorTransform:
//bitmapData.applyFilter(bitmapData,bitmapData.rect,origin,blur);
bitmapData.colorTransform(bitmapData.rect, darken);
bitmapData.draw(display);
}
No comments:
Post a Comment