Create a snowflake in Flash

Thursday, December 6th 2007

Some readers me have asked as was created the snowflake, so realistic, the Widget natalizio. Who downloaded the source probably already knows ... anyway was really simple. Firstly I selected Tool Pennello in Flash and I designed a point.

SnowflakeSnowflake

Ho transformed this in a symbol me show applied two effects in right sequence: chamfering and blur:

SnowflakeSnowflake

The result was: Snowflake

Here MovieClip (symbol) ho associated a simple class CNeve which creates facto intelligence Jib same:

ActionScript
  1. MovieClip { class CNEVA extands MovieClip (
  2. _interval ; private var _interval;
  3. _maxy : Number ; private var _maxy: Number;
  4. / /
  5. function CNEVA () (
  6. this , "_move" , 25 ) ; _interval = setInterval (this, "_move", 25);
  7. round ( ( 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. Number = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ; var randomNum: Number = Math. floor (Math. random () * (max - min + 1)) + min;
  12. return randomNum;
  13. )
  14. / /
  15. _move ( ) { private function _move () (
  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. )

Method _move() contains intelligence Jib, namely function of fall, extremely simple. Varying the function random, _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, eg inserting a _getRndRange(-550, 50), you may add an effect effect wind, ie the flakes fall with a gradient particular. Specifically you can send i flakes right and left using a code this type:

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

Rotation _rotation += _getRndRange(1, 5); then, confers an further detail to staple same.
When creo a jib (see function creaFiocco() below) ho added also a alpha=90 and one stairs randomly, for have snowflakes of different dimensions.

ActionScript
  1. / / Creates staple
  2. function creaFiocco () (
  3. 20 , 100 ) ; var s = randRange (20, 100);
  4. = randRange ( - 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. = - Math . 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 ( "skiing, 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. , 2 ) ; c_mc = createEmptyMovieClip ( "c_mc", 2);
  11. )
  12. )

That is everything ... ;) Forgot ... Auguri to all and Buone feasts ... ;)

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

7 comments to: "Create a snowflake in Flash"

  1. getAvatar 1.0
    06 dic, 2007 Dieg0:

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

  2. getAvatar 1.0
    06 dic, 2007 Giovambattista Fazioli:

    @ Diego0: Thanks for links ;)
    Sul site of Diego find one script Javascript that simulates also falling of snowflakes. The advantage using Javascript is being able positioning pompons above to our page, thing with Flash - whilst is possibiloe through transparency - ne prevents then facto selecting.

  3. getAvatar 1.0
    09 dic, 2007 Chris:

    Hello It should son came to to pry seeing you in mybloglog on my blogghetto. Are precisely ignorant regarding flash and surroundings, not knew had OOP action script. Who knows when succeed in darci un'occhiata, the thing attracts me :-) Hello hello

  4. getAvatar 1.0
    09 dic, 2007 Giovambattista Fazioli:

    @ Chris: thanks for visiting! Saw that ti're Commentary in programming OO with C + +! Ottima choice. To tackle well concepts OO must surely know well both the C that C + +. Actionscript not so pure "like C + +, although at each version approaches increasingly to true and" narrow "development methodologies OO. Anyway if Can working with Flash, even in Actionscript 2.0, you surely find many things illuminants.

  5. getAvatar 1.0
    October 27 2008 Widget natalizi: snow that falls in Flash | Undolog.com:

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

  6. getAvatar 1.0
    December 24 2008 Claudio:

    «At this MovieClip (symbol) ho associated a simple class CNEVA, which creates facto intelligence of ...»
    Hai started easily and with illustrations clearest, then you skipped a tot information essential for a user "standard": how you creates class CNeve Saw how joins to symbol, but I lack everything else. Mi arrangera differently but é a sin.

  7. getAvatar 1.0
    December 28 2008 Giovambattista Fazioli:

    @ Claudio: What not ti is clear exactly? Sometimes may seem that jump few dettaglio However Whereas an side certain "bases" owe assume otherwise should write a handbook every post and secondly can find many clarifications previous post that always find here following eg the category ActionScript 3.0 or Flash. Anyway class CNeve is associated to a MovieClip vacuum present in libreria via the window property. For details see eg Actionscript 3.0: everything with the operator new. If other doubts scrivimi pure, I will happy to answer so toecap.

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL