7.4 Variable effects
The value of an effect’s parameter can vary over the effect’s interval by specifying explicit or computed animations. Beyond that, you can control how the various instances of an effect specification differ from each other. This variation technique is indispensable if you want to sustain the interest of your viewers.
Here are a few ways in which you can infuse such variety in your productions.
7.4.1 Using computed parameter values
Any expression you use to specify the value of an effect’s parameter is computed once per effect instance. This gives you an opportunity to vary the value of a parameter between the instances. The simplest such variation is to set the value of a parameter to a random number in a given range. You can, for example, set a random translation value for the Translate effect’s x parameter as follows -
(effect "Translate" (A) (param "x" (rand 0.3 0.5)))
If the above effect is used as a muvee-segment-effect, you’ll find each segment of the muvee space shifted by a different amount.
You can use any expression that will evaluate to different values every time it is evaluated in order to generate variations in the value of a parameter.
7.4.2 Using sequences
(looping-sequence e1 e2 ....)
(random-sequence e1 e2 ....)
(shuffled-sequence e1 e2 ....)
(define beat (looping-sequence 1 2 3 4)) (beat) ; will give you 1 (beat) ; will give you 2 (beat) ; will give you 3 (beat) ; will give you 4 (beat) ; will give you 1 (beat) ; will give you 2 ; .... and so on.
The random-sequence form yields a function that might return any one of the values when it is invoked, with equal probability. The shuffled-sequence is similar, but ensures that each item is used once before repeating them.
(define left-to-right (looping-sequence -0.4 -0.1 0.2 0.5)) (define muvee-segment-effect (effect "Translate" (A) (param "x" (left-to-right))))
7.4.3 Using effect-selector
(define muvee-segment-effect (effect-selector (random-sequence (effect "Translate" (A) (param "x" 0.2)) (effect "Rotate" (A) (param "degrees" 30.0)) (effect "Scale" (A) (param "x" 1.5)))))
Yes, you can really put anything into a looping/random/shuffled-sequence, including effect specifications.
7.4.4 Responding to music descriptors
You can animate effect parameters based on what is happening in the music. The (loudness t) function, for example, tells you how loud the music is at the given time t, as a number in the range 0.0 to 1.0.
(effect "Scale" (A) (param "y" 1.0 (fn (p) (+ 1.0 (loudness (progress p)))) 2))
See Computed animation curves for explanation.
A more advanced technique is to select effects based on descriptor values, i.e. you pick from a different set of effects depending on the mood of the music. You can therefore choose to use one set for soft parts of the music and another for the more energetic parts.
(define picker (step-tc 0.0 effect1 0.3 effect2 0.6 effect3))
Now we can use the loudness function to select one of the three effects via the picker function as follows - (picker (loudness t)). We still need to turn it into an effect since we don’t know what t is. We’ll know that only at the time the effect gets instantiated.
(effect-selector (with-descriptor loudness (step-tc 0.0 effect1 0.3 effect2 0.6 effect3)))
7.4.5 Using special conditionals
(if-image image-effect video-effect) : Behaves like image-effect if it is applied to an image and like video-effect if it is applied to video.
(if-video video-effect image-effect) : The inverse of if-image.
(if-portrait-image portrait-effect other-effect) : Special treatment for portrait images.
(if-landscape-image landscape-effect other-effect) : Special treatment for landscape images.
(if-portrait-image special (if-image generic-image for-video))
(effect-stack (if-portrait-image portfx1 (if-video vfx2 blank)) grainy-gray)
7.4.6 Controlling effects with style parameters
(effect-selector (with-descriptor (fn (time) (math PARTY_WILDNESS * (time / muvee-duration-secs))) party-effects))