[FMX] the falling snow tutorial

i would really appreciate it if someone could give me a more in depth explanation of how this tutoiral works:
http://www.kirupa.com/developer/mx2004/snow.htm

i understand the ideas behind the script and what you are asking flash to do. the thing is my maths isnt that great. if someone could explain how some of the equations work, that would be excellent :smiley:

examples:

this._alpha = 20+Math.random()*50; [color=#ff0000]ok, randomising alpha. got it. but where do these numbers come from? how did you reach them?[/color]
or
// horizontal movement
rad += (k/180)*Math.PI;
xmovement = _root._xmouse;
this._x -= Math.cos(rad)+(xmovement-(width/2))/50;
[color=red]understand what this is trying to do here. but… man… the maths goes right over the top of my head… and explanation??[/color]

[color=black]thanks very much in advance!! ;)[/color]

-hazza

For the first part, the numbers 20 and 50 are arbitrary, meaning you can change them and get different ranges of alpha values for your snowflakes.

The second part first updates a radian variable, which is used to randomize horizontal movement of the snowflake. That’s what Math.cos(rad) does. Then you add to it where your mouse is on the screen, so it can move based on that as well. I’d suggest toying around with the numbers and seeing what happens.

[QUOTE=coolname]For the first part, the numbers 20 and 50 are arbitrary, meaning you can change them and get different ranges of alpha values for your snowflakes.

[QUOTE]

i understand that these numbers are used to randomise the alpha, but how does: 20+Math.random()*50; work? what numbers will it be randomly choosing from is i guess what im trying to ask. becuase i could just be wacking in any old numbers in those gaps.

thanks for the reply :slight_smile:

-hazza

the number you get from 20+Math.random()*50; will be between 20 and 70 I think.
the random function returns a number between 0 and 1 and is multiplied with 50, therefor the number you get is between 0 and 50. this number is then added to 20 -> 20-70

thanks =)