HIDIHO!

giving something back to the Flash community

vector field

Tags: , , , , , ,

cover
vector fields rock!howdy!

now this one is an old disco number: the vector field.
It is very basic, I just wanted to try it out so I didn’t really push it .

The stuff (click-drag-start):

the sources:

you should use very few forces in the beginning, like 2 big forces or an attractor + a force.
just to see how it works. The first vectorfield is taken from my avatar, the function is in the .fla and then it generates a beautiful fairies’ rainbow colors 1024 particles field with love and kisses everywhere.
don’t be scared
In fact, there’s that VectorField.init( nb:int ); that fills the vectors array. Up to you to replace it with whatever function. default will create those beautiful fairies’ rainbow colors in a circle shape.

Otherwise, the structure is quite simple :
The VectorField class is instantiated. then you setup a bunch of vectors and finally you create forces that will be applied to the bunch of vectors.
as easy as one two three.
somehow
well, four, press the ‘run’ button…
in fact, you create forces and watch them move for a while before ending up in a nice little entropy or simply looping on a stabilized path.
that’s it.
the more numerous th forces, the greater the chaos (sounds dramatic huh?!)
the example above is not really what I’d use this for, indeed it might prove useful for a physics game or something in the way. as such it’s like a moving field of particles, it’s not extremely interesting(euphemism).

I don’t know really but I feel there’s something to do with it.
I wanted to make custom forces creation easy, don’t know if it worked really, but you can check the Attract and Repell classes, they both extend Force and the only thing they do is overriding the equation method of the force class (plus setting a color for the sprite).
equation recieives a vector as an argument and performs whatever operation on it.
It can really get nice, trust me.

Funily enough, it gives a clue about how the strange attractors work. Like you could setup a clump of attractors and repellers + custom forces and then have it to run for a while, just to check if your theory about how to take over the world was right :)

that was it …enjoy
PS: don’t hate me for the way it’s coded, I’ve still got a lot to learn :/

Tags: , , , , , ,

© 2009 HIDIHO!. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.