Snow Fall – Realistic Flash Falling Snow

January 1, 2010

How To

Open a Flash document size of 300×400, dark blue background (# 000022) and draw a small white ball. I did a 10 with 10px and I gave gradient outwards so as to lose the background. Convert it to Symbol, Movie Clip

Right click the newly created Movie Clip in the Library and select “Linkage”, and select Export for ActionScript and enter the words “snow” (with all the quotes) in the textfield
In line 1 to enter the root timeline’s 29 lines of code:

width = 400; // pixeli

height = 300; // pixeli

max_snowsize = 6; // pixeli

snowflakes = 75; // cantitatea

for (i=0;i<snowflakes;i++) {

t = attachMovie(“snow”,”snow”+i,i);

t._alpha = 20+Math.random()*60;

t._x = -(width/2)+Math.random()*(1.5*width);

t._y = -(height/2)+Math.random()*(1.5*height);

t._xscale = t._yscale = 50+Math.random()*(max_snowsize*10);

t.k = 1+Math.random()*2;

t.wind = -1.5+Math.random()*(1.4*3);

t.onEnterFrame = mover;

}

function mover() {

this._y += this.k;

this._x += this.wind;

if (this._y > height+10) {

this._y = -20;

}

if (this._x > width+20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;

} else if (this._x < -20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;

}

}

Test animation. I think it came out right.
A little detail lines to code in order to understand how this effect
The first 4 lines are simple

width = 400; // pixeli

height = 300; // pixels

max_snowsize = 6; // pixeli

snowflakes = 75; // cantitatea

These settings set the limits of animation

Let’s see which rows are responsible for producing snow.

for (i=0;i<snowflakes;i++) {

t = attachMovie(“snow”,”snow”+i,i);

t._alpha = 20+Math.random()*60;

t._x = -(width/2)+Math.random()*(1.5*width);

t._y = -(height/2)+Math.random()*(1.5*height);

t._xscale = t._yscale = 50+Math.random()*(max_snowsize*10);

t.k = 1+Math.random()*2;

t.wind = -1.5+Math.random()*(1.4*3);

t.onEnterFrame = mover;

}

Loop creates a temp variable called ‘t’ which attach to a snowflake created. This opacity varabila distributed between 20 and 80 percent of each flake. The next two lines snowflake positions in a random position (random). Position x make little snowflake on each side so that it falls in one direction is the wind. Then the size of lightning. Notice the line: t._xscale = t._yscale That means snowflake shape is a perfect circle. These two variables: K is for speed is falling snowflake. Loopurile who say spit mover to perform the function in each frame. This loop is repeated depending on how many flakes were set. In this example 75

function mover() {

this._y += this.k;

this._x += this.wind;

if (this._y > height+10) {

this._y = -20;

}

if (this._x > width+20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;

} else if (this._x < -20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;

}

}

This is the last piece of code and make our snowflakes fall

this._y += this.k;

this._x += this.wind;

This piece and apply wind speed fall on the x axis and y:

if (this._y > height+10) { this._y = -20;

}

if (this._x > width+20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;} else if (this._x < -20) {

this._x = -(width/2)+Math.random()*(1.5*width);

this._y = -20;

}

These 3 loopuri replace snow if they have completed the journey or not behaved properly on their way. The first loop checks if snowflake came down and you need to replace it with another that fall again. The other two, an if .. else change to snow from top of the screen if a new position x snowflake out of animation

, ,

Subscribe

Subscribe to our e-mail newsletter to receive updates.

One Response to “Snow Fall – Realistic Flash Falling Snow”

  1. Ben Says:

    Thanks for sharing this.

    I’m wondering, I need to position the snow in a particular area of my flash stage, and hopefully mask it somehow. How would i go about achieving these 2 things?

    Cheers

Leave a Reply