Create a snowflake in Flash

Thursday, December 6, 2007

Some readers have asked me how it was created snowflake, so realistic, the Widget Christmas. Those who have downloaded the source probably already knows ... however, was very simple. First of all I selected the Brush tool in Flash and I have designed a point.

SnowflakeSnowflake

I've turned this into a symbol and I have two effects applied in the right sequence: bevel and blur:

SnowflakeSnowflake

The result was: Snowflake

In this MovieClip (symbol) I have associated a simple class CNeve which creates de facto intelligence staple of himself:

Actionscript:
  1. { CNEVA class extends MovieClip (
  2. _interval; var private _interval;
  3. _maxy: Number ; var private _maxy: Number;
  4. / /
  5. CNEVA function () (
  6. this , "_move" , 25 ) ; _interval = setInterval (this, "_Move", 25);
  7. ( ( Stage . height + 256 ) / 2 ) +_getRndRange ( - 20 , - 7 ) ; _maxy = Math. round ((Stage. height + 256) / 2) + _getRndRange (- 20 - 7);
  8. )
  9. / /
  10. _getRndRange ( min : Number , max : Number ) : Number { private function _getRndRange (min: Number, max: Number): Number (
  11. = Math . floor ( Math . random ( ) * ( max- min + 1 ) ) + min ; var randomNum: Number = Math. floor (Math. random () * (max-min + 1)) + min;
  12. randomNum return;
  13. )
  14. / /
  15. _move ( ) { _Move private function () (
  16. 1 , 5 ) ; _y + _getRndRange = (1, 5);
  17. _getRndRange ( - 50 , 50 ) ) > 0 ) ? 1 : - 1 ; _X + = ((_getRndRange (- 50, 50))> 0)? 1 - 1;
  18. 1 , 5 ) ; _rotation + _getRndRange = (1, 5);
  19. _y>_maxy ) { if (_y> _maxy) (
  20. _interval ) ; clearInterval (_interval);
  21. )
  22. ; updateAfterEvent ();
  23. )
  24. )

The method _move() contains the intelligence of the staple, or the fall, very simple. By changing the random _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, example by including a _getRndRange(-550, 50), you can add a wind effect, namely the flakes fall with a particular slope. In particular, the flakes can send to either side using a code like this:

Actionscript:
  1. _getRndRange ( _getRndRange ( - 350 , - 50 ) , _getRndRange ( 50 , 350 ) ) ) > 0 ) ? 1 : - 1 ; _X + = ((_getRndRange (_getRndRange (- 350, - 50), _getRndRange (50, 350)))> 0)? 1 - 1;

The rotation _rotation += _getRndRange(1, 5); then, gives further details to staple himself.
When I create a staple (see function creaFiocco() below) I also added an alpha=90 a scale random, to have snowflakes of various sizes.

Actionscript:
  1. / / Create staple
  2. creaFiocco function () (
  3. 20 , 100 ) ; var s = randRange (20, 100);
  4. - Math . floor ( ( Stage . width - 320 ) / 2 ) , Math . round ( ( Stage . width + 320 ) / 2 ) ) ; var x = randRange (- Math. floor ((Stage. width - 320) / 2), Math. round ((Stage. width + 320) / 2));
  5. . floor ( ( ( Stage . height - 256 ) / 2 ) ) - 10 ; var y = - Math. floor (((Stage. height - 256) / 2)) - 10;
  6. "neve" , "neve_" + index , index , { _x :x, _y :y, _xscale :s, _yscale :s, _alpha : 90 } ) ; c_mc. attachMovie ( "snow", "neve_" + index, index, (_X: x, _y: y, _xscale: s, _yscale: s, _alpha: 90));
  7. index + +;
  8. index> 1000 ) { if (index> 1000) (
  9. ; index = 1;
  10. "c_mc" , 2 ) ; c_mc = createEmptyMovieClip ( "c_mc", 2);
  11. )
  12. )

And that's all ... ;) Forgot ... Greetings to all and Happy holidays ... ;)

Related Post

5 comments to: "Create a snowflake in Flash"

  1. getAvatar 1.0 Thursday, 06 December, 2007 at 14:48
    Dieg0 said:

    Check my site: http://www.Dieg0.com.ar
    Regards,
    Diego

    Answer Quote
  2. getAvatar 1.0 Thursday, 06 December, 2007 at 15:17
    Giovambattista Fazioli said:

    @ Diego0: Thanks for links ;)
    On the site of Diego Javascript is a script that simulates also falling flakes of snow. The advantage of using Javascript is to place the flakes on our page, which with Flash - while possibiloe is through transparency - prevents then made the selection.

    Answer Quote
  3. getAvatar 1.0 Sunday, December 09, 2007 at 19:26
    Chris said:

    It hello son came to browse in vedendoti MyBlogLog on my blogghetto. It is ignorant about flash and the surrounding area, I did not know was OOP action script. Who knows when it will give us a look, what attracts me :-) Hello hello

    Answer Quote
  4. getAvatar 1.0 Sunday, December 09, 2007 at 19:36
    Giovambattista Fazioli said:

    @ Chris: Thanks for visiting! I saw that you're comentar in OO programming with C + +! Excellent choice. To deal well OO concepts must surely know that the C C + +. Actionscript is not as "pure" like C + +, although each version is closer and closer to the actual "close" OO development methodologies. However if you can work with Flash, including Actionscript 2.0, you can surely find many things enlightening.

    Answer Quote
  5. getAvatar 1.0 Monday, October 27, 2008 at 14:52
    Widget Christmas: snow falling in Flash | Undolog.com said:

    [...] Update: service unavailable - See Create a snowflake in Flash [...]

Leave a comment

TAG XHTML <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <a <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Use <pre> to enclose code