Making a butterfly.

Moderators: Disciple, zlovatt

Post Reply
InvisibleRabbit
Posts: 3
Joined: August 25th, 2007, 9:56 pm
Location: Los Angeles

I've posted this on the AE forum over at Adobe, but I'd love to see what you guys can come up with (though many of us are regulars over there already).

This one suddenly got a lot more difficult than I thought. I'm animating a butterfly's wings. So, I used a cosine function to drive the flapping, and attached it to two expression controls to keyframe both amplitude and frequency.

(Math.cos(time*comp("Comp 1").layer("B_Controls").effect("Flap_Freq")("Slider")*6)*comp("Comp 1").layer("B_Controls").effect("Flap_Amount")("Slider")/2

Actually, this is part of a more complicated expression which has two additional controls to allow me to ease out of the pre-programed flapping and begin controlling the wings directly with the master Fold_Wings slider. However, the second portion works fine.

(Math.cos(time*comp("Comp 1").layer("B_Controls").effect("Flap_Freq")("Slider")*6)*comp("Comp 1").layer("B_Controls").effect("Flap_Amount")("Slider")/2+comp("Comp 1").layer("B_Controls").effect("Flap_Amount")("Slider")/2)*comp("Comp 1").layer("B_Controls").effect("Flap Permit")("Slider")+18+comp("Comp 1").layer("B_Controls").effect("Fold_Wings")("Slider")+random(.5)

Unfortunately, the first portion was never meant to be so easy. Changing the frequency does indeed make the wings move faster or slower, but because it's picking a value for the position of the wings based on a completely new sine curve, the period where the frequency value is changing is an incomprehensible blur of wings.

If anyone can help me modify the original expression, I would be extremely grateful.
InvisibleRabbit
Posts: 3
Joined: August 25th, 2007, 9:56 pm
Location: Los Angeles

Here's a new version of the expression which is a little less incomprehensible, and a new version of the question, in case the best solution is to start again from scratch:

Frequency=comp("Comp 1").layer("B_Controls").effect("Flap_Freq")("Slider")*6;
Amplitude=comp("Comp 1").layer("B_Controls").effect("Flap_Amount")("Slider")/2;

(Math.cos(time*Frequency)*Amplitude+Amplitude)

Question: "How could one make an expression which returns the angle of flapping wings on the basis of controls for amplitude and frequency?"
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

This is one of those cases where to avoid discontinuities, you have to integrate the area under the frequency control curve to get the correct angle for Math.cos(). Here's a little test expression I set up, with slider controls for frequency and amplitude applied to the layer being rotated. The greater you set samplesPerFrame, the better the accuracy and potential motion blur, but it gets really slow in a hurry.

Code: Select all

freq = effect("freq")("Slider");
amp = effect("amp")("Slider");

samplesPerFrame = 2;
frameDur = thisComp.frameDuration;
numSamples = Math.round(time / (frameDur / samplesPerFrame));
sampleDur = frameDur/samplesPerFrame; 

accum = 0;
for (i = numSamples; i > 0; i--){
  accum += freq.valueAtTime(i * sampleDur) * sampleDur;
}

amp*Math.cos(accum * Math.PI *2)
Hopefully this will help.

Dan
InvisibleRabbit
Posts: 3
Joined: August 25th, 2007, 9:56 pm
Location: Los Angeles

Much as I hate to make this expression more complicated, I've been observing butterfly motion, and I've realized that it differs from what's generated in the expression in one key way. The wings don't move in a sine wave pattern. Rather they "pop," that is, they move down and up rather quickly, then pause, then pop again.

So I'd like to figure out how to make the expression more accurately approximate that motion. Perhaps the simplest solution would be two have two controllable values: a "flap duration" which controls the length of the pop (which I assume could be controlled by a sine wave), and a "pause duration." Together the two would be a single period.

I would tremendously appreciate any help making this addition.

All the Best,
Ari
Post Reply