Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE AFTER EFFECTS:HomeForumBasicsExpressionsTutorialsPodcastsAE TechniquesTrainingCreative Cloud DebateFAQ

Variable speed oscillator

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Perry KrollVariable speed oscillator
by on May 10, 2012 at 7:56:37 pm

Me again!

I have this delightful oscillation script I picked up somewhere and modified:

freq = thisComp.layer("H BPM #").effect("value")("Slider")/60; //oscillations per second
intensity = 5; // intensity
i = intensity*(1 + Math.sin(freq*time*Math.PI*2))/2;
[95+i,95+i]


I'm applying it to the scale on a heart icon, and controlling it based on another expression controller which is animated for beats per minute.

it works perfectly when I don't animate the BPM/frequency value. As soon as I animate that, some weird stuff starts happening. Speeds will go up and down in between keyframes. If the keyframes aren't the first and last frames of the comp, the results will be reversed or just entirely wrong.

I suspect it has something to do with sine and how it works with time, but I am stuck...

Any ideas?


Return to posts index
Reply   Like  

Dan EbbertsRe: Variable speed oscillator
by on May 10, 2012 at 11:19:01 pm

Short answer: expect unpredictable results if you animate speed or frequency.

You can probably fix it by integrating (as in area under the curve) your BPM slider and using that result to feed degrees or radians into Math.sin() (instead of an animated frequency value). What's the nature of the slider animation? That will determine how hard/easy it will be to perform the integration.

Dan



Return to posts index
Reply   Like  

Perry KrollRe: Variable speed oscillator
by on May 11, 2012 at 2:50:23 pm

Well, the slider animation will never be too complex. It just needs to be able to be adjusted gradually (over, at the shortest, like 5-10 seconds, or maybe over long periods of time like 20-30 seconds.) It would need to go from perhaps 70 bpm to around 120 or 150.

Technically it doesn't even need a nice sine wave to the scale. It could be a straight up linear scale up and down if that is easier.

I am very curious to hear what the potential solution you were thinking of is...

Thanks so much!


Return to posts index
Reply   Like  


Dan EbbertsRe: Variable speed oscillator
by on May 11, 2012 at 5:44:20 pm

If you can live with linear keyframes on your BPM slider, I believe this will give you what you want:


p = thisComp.layer("H BPM #").effect("value")("Slider");

v1 = p.value;
t1 = time;
accum = 0;
n = 0;
if (p.numKeys > 0){
n = p.nearestKey(time).index;
if (p.key(n).time > time){
n--;
}
}
if (n > 0){
t0 = p.key(n).time;
v0 = p.key(n).value;
accum += ((v0 + v1)/2)*(t1-t0);
t1 = t0;
v1 = v0;
while (n > 1){
t0 = p.key(n-1).time;
v0 = p.key(n-1).value;
accum += ((v0 + v1)/2)*(t1-t0);
t1 = t0;
v1 = v0;
n--
}
}
accum += ((p.valueAtTime(0) + v1)/2)*t1;
intensity = 5; // intensity
i = intensity*(1 + Math.sin((accum/60)*Math.PI*2))/2;
[95+i,95+i]


Dan



Return to posts index
Reply   Like  

Perry KrollRe: Variable speed oscillator
by on May 11, 2012 at 10:51:14 pm

Dan, thank you so much! You are like some kind of wizard. This works perfectly.

Hey google - send people here when they want to oscillate something in After Effects and animate it to change or vary the speed of oscillation.


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2013 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]