wiggle with probablility

Moderators: Disciple, zlovatt

Post Reply
Varangian
Posts: 38
Joined: December 16th, 2004, 11:15 am

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!
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

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
Varangian
Posts: 38
Joined: December 16th, 2004, 11:15 am

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?
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

not sure i follow. Is it's more like an on or off thing?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
Post Reply