Page 1 of 1

The Source Code To Wiggle?

Posted: December 9th, 2008, 2:24 pm
by Atomic
Can anyone explain the source code to wiggle?

I am trying to write a python equivalent of the wiggle function and wonder where to start?

Does anyone know what is "under the hood" of this built-in AE function?

Re: The Source Code To Wiggle?

Posted: December 10th, 2008, 4:35 pm
by kobyg
Atomic,
I don't know exactly what they are doing, but from the behaviour I think it should be similar to a Fractal Noise, known also as Perlin Noise.
Check out this website for a good explanation and mathematics of the Perlin Noise:
http://freespace.virgin.net/hugo.elias/ ... perlin.htm

Koby.

Re: The Source Code To Wiggle?

Posted: December 11th, 2008, 6:37 am
by Atomic
Thanks for the link. I am loking for a way to invent wiggle for Blender. The noise routines on the link you provided are a good start, but at a glance, none of them take into account time, which is what wiggleis great at. My guess is that it is some kind of SIN wave that is randomized.

Just thought I'd ask here in case someone knew off the top of their head how it was done.

Re: The Source Code To Wiggle?

Posted: December 11th, 2008, 9:38 am
by kobyg
From my experience with random functions, Perlin Noise is the mathematical model of the wiggle expression.
The Perlin noise adds few noise levels (random sequences) at doublly increasing frequency on each level.
Lower frequency noise is generated by larger interpolation.
Adding those with decreasing weights gets the natural look of wiggle.

To help you find the connection between the two,
here are the equivalent parameters between wiggle and Perlin noise:
wiggle comes with 3 parameters: wiggle(F, A, N), which at the Perlin Noise model are:
F - the frequency of the lowest frequency noise
(this is the time factor you were looking for)
A - is the amplitude of the lowest frequency noise (which is the strongest of all noises)
N - is equivalent to the Persistence of the Perlin noise (but on a different scale: larger N is equivalent to persistence closer to 1,
which makes the higher frequencies stronger => rougher behaviour even for lower frequency F)
(I think the connection between them should be something like: persistence = 1 - exp(-N/4) )

I hope that's helpful.
I could come up with other ideas for random models to create something similar to the wiggle, but it won't be the same...
Perlin noise is what you need, if you are looking for the natural behaviour of wiggle.

Koby.

p.s.: When you say Blender, you mean the 3d app ?

Re: The Source Code To Wiggle?

Posted: December 12th, 2008, 6:32 am
by Atomic
Thanks for the clarification, Koby.

Yes, the 3D application. It looks like Blender does have some noise features, I guess I have to figure out how to hook them up to my frameChange event.

http://www.blender.org/documentation/24 ... odule.html

Re: The Source Code To Wiggle?

Posted: December 12th, 2008, 12:28 pm
by Atomic
I came up with something like this...

Code: Select all

def wiggle(passedFrequency, passedAmplitude):
	#Get a random number between 0 and 1.
	r = Noise.random()
	# Cut it in half to get a range of -0.5 to 0.5.
	r = 0.5 - r
	# Multiply by 2 to get it into the range of -1.0 to 1.0.
	r = r * 2.0
	#Multiply this number by the amplitude.
	r =r * passedAmplitude
	# Calculate a COS value based upo the passedFrequency.
	localTime = Blender.Get('curtime')
	r = (math.cos(localTime*passedFrequency) * amplitude) + r
	return r

Re: The Source Code To Wiggle?

Posted: December 12th, 2008, 4:56 pm
by kobyg
The expression you wrote would not create the smooth but random wiggle motion.
What you wrote would look more like of a looping motion with sudden small jumps.

I don't know Blender, but from the brief explanation of the Blender functions you've sent,
I think those 2 might do something similar to what you are looking for:
- ridgedMFractal(xyz, H, lacunarity, octaves, offset, gain, basis)
- turbulence(xyz, octaves, hard, basis, ampscale, freqscale)
But without more in depth explanation about those functions, I could not know more to help you.

Re: The Source Code To Wiggle?

Posted: December 13th, 2008, 7:25 am
by Atomic
Koby,

You are right, when I applied it to my animation objects, they were out of control. What I ended up doing was removing the random modification to the COS wave. So I ended up with a simple COS wave as my wiggle function. This will do for now, for my present needs. I am still thinking about how to add randomness to the COS wave. I will probably have to add another parameter to the function and pass it in on the fly.

Thanks again for the feedback!

Re: The Source Code To Wiggle?

Posted: December 13th, 2008, 3:40 pm
by kobyg
Atomic,
If the COS works for you, you could try adding another one or two COS to the expression,
that would give a more interesting and "random" like movement.

You could try something like this:

Code: Select all

r = (math.cos(localTime*passedFrequency) * amplitude) 
    + (math.cos(localTime*passedFrequency*2.8) * amplitude * 0.8) 
If I'll have time, I will try to write some "real" random expression.
I might need your help for that bcause I've never used Blender... (I even don't have it installed on my computer)

Re: The Source Code To Wiggle?

Posted: December 14th, 2008, 11:38 am
by Atomic
I think I get it, offset the phase a little and multiply that version of the COS by a different amplitude and add that into the final result.

Re: The Source Code To Wiggle?

Posted: December 14th, 2008, 2:40 pm
by kobyg
Tha't actualy changes the frequency of the COS wave.
Let me know if it works better for you...

Re: The Source Code To Wiggle?

Posted: February 1st, 2012, 2:02 am
by pecijackson
i dont really get it, what for this script for. anyone?