2 Replies Latest reply on Aug 6, 2009 12:06 AM by dalcde

    Need help with Random Blur

    onisamagolf

      I'm using a custom BlurTween class, but that isn't the problem.  I've got the following AS targeting a clip with the insstance name of photo:

      // All time in milliseconds. (1000 = 1 second)
      
      import com.rubenbristian.tween.BlurTween;;
      
      maxTB = 5000; // Maximum time between blur
      minTB = 2000; // Minimum time between blur
      maxBD = 5000; // Maximum blur duration
      minBD = 2000;  // Minimum blur duration 
      
      // Get a random start time.
      blurTime = getNewTime();
      blurDuration = getNewDuration();
      
      // Every frame execute the following code.
      this.onEnterFrame = function(){
      
           // Get current time in milliseconds.
           curTime = getTimer();
      
           // Check if current time is past the time to blur.
           if(curTime >= blurTime){
                // blurring already.
                // Check if blur has lasted the duration specified.
                   if(curTime <= blurTime + blurDuration){
                     // Create the blur.
                     var blur_amt_x = 20;
                     var blur_amt_y = 5;
                     new BlurTween(photo, "out", blur_amt_x, blur_amt_y, 1, .7, "Strong", "out");
                                              
                } else {
                     // Clear blur filter
                     var blur_amt_x = 20;
                     var blur_amt_y = 5;
                     new BlurTween(photo, "in", blur_amt_x, blur_amt_y, 1, .7, "Strong", "out");
                
                     blurTime = getNewTime();
                }
           }
      }
      
      // Create a random time between maxTB and minTB specified.
      function getNewTime(){
           return getTimer() + (Math.random() * (maxTB-minTB))+minTB;
      }
      
      // Create a random duration between maxBD and minBD
      function getNewDuration () {
           return (Math.random() * (maxBD-minBD)) + minBD;
      }
      

       

      Everything is working OK, except the duration of the blur doesn't seem to be working.  The clip blurs and then is "immediately" sharp agian.  I want the clip to stay blurred for a random duration which I'm setting with the variable blurDuration.  I just can't figure out why it isn't staying blurred.  I modified the AS from a random flicker tutorial I found.

       

      Thanks,

      Shannon

        • 1. Re: Need help with Random Blur
          onisamagolf Level 1

          I had a combination of things going wrong, here is what I ended up doing:

          // All time in milliseconds. (1000 = 1 second)
          
          import com.rubenbristian.tween.BlurTween;;
          
          maxTB = 5000; // Maximum time between blur
          minTB = 100; // Minimum time between blur
          maxBD = 1000; // Maximum blur duration
          minBD = 50;  // Minimum blur duration 
          
          // Get a random start time.
          blurTime = getNewTime();
          blurDuration = getNewDuration();
          blurCount = 0;
          trace(blurCount + "a");
          
          // Every frame execute the following code.
          this.onEnterFrame = function(){
          
               // Get current time in milliseconds.
               curTime = getTimer();
               trace(blurCount + "b");
               trace(curTime);
               trace(blurTime);
               trace(blurTime + blurDuration);
               
               // Check if current time is past the time to blur.
               if((curTime >= blurTime) && (blurCount == 0)){
                    // Create the blur.
                    var blur_amt_x = 20;
                    var blur_amt_y = 5;
                    new BlurTween(photo, "out", blur_amt_x, blur_amt_y, 1, 1, "Strong", "out");
                    ++blurCount;
                    trace(blurCount + "c");
               } 
               else if (curTime >= blurTime + blurDuration) {
                    // Clear blur filter
                    var blur_amt_x = 20;
                    var blur_amt_y = 5;
                    new BlurTween(photo, "in", blur_amt_x, blur_amt_y, 1, 1, "Strong", "in");
                    trace(blurCount + "d");
                    blurCount = 0;     
                    trace(blurCount + "e");
                    blurTime = getNewTime();
               }
          }
          
          // Create a random time between maxTB and minTB specified.
          function getNewTime(){
               return getTimer() + (Math.random() * (maxTB-minTB))+ minTB;
          }
          
          // Create a random duration between maxBD and minBD
          function getNewDuration () {
               return (Math.random() * (maxBD-minBD)) + minBD;
          }
          
          • 2. Re: Need help with Random Blur
            dalcde Level 1

            I don't really understand much of your code, but the minimum blur duration: 0.05 seconds, and maximum blur duration: 1 second. So I don't expect it to last long. Try multiplying it by 100.