10 Replies Latest reply on Mar 9, 2007 2:58 PM by Rothrock

    Exponential Particle Decay

    scatterbrain73
      I'm working on an animation that illustrates the concept of half-life (not the video game). I already have the equation that correctly simulates exponential decay. The idea is to start out with 1,024 particles spread out randomly in a square area (about 320 x 320 pixels) and have them disappear at the correct rate, following this equation:

      http://www.petersenart.com/exponentialDecay.jpg

      Ideally, the particles would be generated at random at the beginning and stay in the same spot throughout the animation.

      Does anyone know how to translate this into ActionScript? I'm a complete noob when it comes to scripting. Thank you very much...
        • 1. Re: Exponential Particle Decay
          kglad Adobe Community Professional & MVP
          1. create a particle and give it a linkage id
          2. excute a 1024 iteration for-loop that attached your particle at random locations within your region and store particle references in an array.
          2.3. initialize the arrays index and current number
          3. start a loop (onEnterFrame or setInterval() ) that iterates each time t and calculates the number of paritcles to remove (the difference between previous and current) and use a for-loop to remove those movieclips.
          4. increment the start array index
          5. update the current number
          6. repeat
          • 2. Re: Exponential Particle Decay
            Rothrock Level 5
            How do you deal with fractional particles? The equation gives fractional answers, but, to the best of my knowledge, .4378 of a particle cannot have decayed.

            • 3. Re: Exponential Particle Decay
              kglad Adobe Community Professional & MVP
              round-off. that number is the result of a probability distribution anyway, not an exact number.
              • 4. Re: Exponential Particle Decay
                Rothrock Level 5
                Yeah, I was wondering if there is any benefit to round, floor, or ceil?
                • 5. Re: Exponential Particle Decay
                  kglad Adobe Community Professional & MVP
                  doesn't matter until the end when you'll need floor or round.
                  • 6. Re: Exponential Particle Decay
                    scatterbrain73 Level 1
                    Wow. Okay, now I just need to learn ActionScript and I'll be able to do this. I have no idea what a linkage ID or an array is. Thanks anyway...
                    • 7. Re: Exponential Particle Decay
                      Rothrock Level 5
                      When you create a MovieClip symbol, you will see a box (you might need to click the Advanced button) to Export for Actionscript. Then you can give the exported symbol a name. Don't include spaces or special characters in the name.

                      If you already have a clip created and didn't give it a name, you can right click on its icon in the library panel and select linkage from the contextual menu.

                      Remember that even if you don't use the clip in your code it will be included in your swf – making the size and download time larger. So if you later decide not to use a certain clip you should go in and uncheck that box.

                      Also, I don't think and array is really needed here. You should learn about them, but I don't think for this you need to do it.

                      I've attached my solution. I made a movieclip with a little round semi-transparent circle on frame one and a stop() on the frame actionscript. Then starting on frame 2 I made a tween of a smaller black dot racing away and fading out. On the final frame of the movieclip I put a stop().

                      Remember the above is its own movieclip, not on the main timeline. Check its linkage and name it atom.

                      Then put the code I've attached on Frame 1 of your main timeline.

                      Try it out and then pick it apart. Let me know what you think.
                      • 8. Re: Exponential Particle Decay
                        Level 7
                        >>The equation gives fractional answers, but, to the best of my knowledge,
                        >>.4378 of a particle cannot have decayed.

                        Why not use alpha, or a color to show decay... that way you can visualize
                        the decay better anyway.

                        --
                        Dave -
                        Head Developer
                        www.blurredistinction.com
                        Adobe Community Expert
                        http://www.adobe.com/communities/experts/


                        • 9. Re: Exponential Particle Decay
                          scatterbrain73 Level 1
                          Rothrock, you are a god. Thank you so much! I've gotten it to work so far, but now I just need to constrain the particles between discrete x and y coordinates, since I want two sets of different particles decaying side-by-side. I'll let you know how it works.

                          Also, is there a way to reset this?
                          • 10. Re: Exponential Particle Decay
                            Rothrock Level 5
                            Carefully check out the attachMovie method and its arguments. That is where you will see how to constrain the particles.

                            There is always a way to reset things, but not as it is written – that will be left as an exercise for the reader. :) If you have problems, post back with what you try.