The Source Code To Wiggle?

Moderators: Disciple, zlovatt

Post Reply
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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?
"Up And Atom

No...No

Up And At Them!"
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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.
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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.
"Up And Atom

No...No

Up And At Them!"
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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 ?
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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
"Up And Atom

No...No

Up And At Them!"
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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
"Up And Atom

No...No

Up And At Them!"
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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.
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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!
"Up And Atom

No...No

Up And At Them!"
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

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)
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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.
"Up And Atom

No...No

Up And At Them!"
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

Tha't actualy changes the frequency of the COS wave.
Let me know if it works better for you...
pecijackson
Posts: 8
Joined: January 31st, 2012, 12:23 am

i dont really get it, what for this script for. anyone?
Post Reply