Page 1 of 1

wiggle with probablility

Posted: February 13th, 2007, 8:44 am
by Varangian
I have a simple expression for random wiggle:

seedRandom(13,true);
wiggle(2,7)

I would like to add code that would introduce probability, so if probability = 0 there the expression would yeild no wiggle, and if it were 100 it would wiggle all the time (yeilding the same result as the expression above)

thanks!

Posted: February 13th, 2007, 10:13 am
by lloydalvarez
This should do what you want:

Code: Select all

probability=100;
probability=probability/100;
wiggleAmt=7;
seedRandom(13,true);
wiggle(2,wiggleAmt*probability) 

You can also tie probability to an expression slider so you can animate the probability like this:

Code: Select all

probability=effect("Slider Control")("Slider");
probability=probability/100;
wiggleAmt=7;
seedRandom(13,true);
wiggle(2,wiggleAmt*probability) 
-Lloyd

Posted: February 14th, 2007, 9:55 am
by Varangian
hmmm, this seems to only limit the amount of the wiggle, I want to keep the amount (amplitude) constant, yet, vary the probability of the wiggle.

So sometimes it would wiggle, say 50 pixels at a give frequency, then other times it would not.

any ideas?

Posted: February 14th, 2007, 11:20 am
by lloydalvarez
not sure i follow. Is it's more like an on or off thing?

Posted: February 14th, 2007, 6:03 pm
by Dan Ebberts
Try this one and see if it gets you closer. It should randomly wiggle, then hold its position for a random time, the wiggle again, etc.

Code: Select all

freq = 5; // wiggle frequency
amp = 100; // wiggle amplitude
minOn = .5; // min wiggle time (seconds)
maxOn = 1.5;
minOff = .5; // min hold time
maxOff = 1.5;
 
seedRandom(index,true);
t = -random(maxOn + maxOff); // pre-run
accumOn = 0;
while (t <= time){
  myOn = random(minOn,minOff);
  myOff = random(minOff,maxOff);
  t += myOn + myOff;
  accumOn += myOn
}
if (time < t - myOff){
  wiggle (freq,amp, 1,.5 ,accumOn + time -t + myOff);
}else{
  wiggle (freq,amp,1,.5,accumOn);
}
Dan