Tuesday, March 30, 2010

Swarms

Swarms really fascinate me. You see pigeons forming patterns. Fish schools swim in cohesive patterns. There are some types of birds, in massive numbers, that appear like swirling smoke from a distance. Each one of these spectacles is an amazing sight.
The underpinning of the behavior is surprisingly simple.
One of the models is depicted in this boids. It uses three simple rules to create a more wholistic interesting behavior. The rules, in brief, are: Seperation, Cohesion, Alignment.

However this is not the only way swarms can be created. In my model, based on basic particle physics (nothing fancy), I have Attraction, Seperation, Rotation.


The area of effect for attraction is the greatest one, however its maximum amplitude is much less than that of the seperation effect. This creates an interesting interaction pattern that includes soft collision.
The area of effect for rotation has been tweaked (and I have been very lucky with the results) and is in practice half way between the seperation and attraction.

Each of these effects act in a pair wise manner. The end result is that the particles group into clusters and rotate approximately around each center of a cluster that are rotating counter-clockwise. On occasion, the clusters will exchange particles, creating a channel. In other cases, a big cluster will seperate into two clusters while a channel thins down.

Sunday, March 14, 2010

Raymarching - Part 0

raymarching minimum distance - part 0 - wonderfl build flash online


I have been contemplating on the idea of a ray tracing application created within actionscript. My first experiment in this field can be found here.
The first time I have been exposed to such graphics algorithm was about 2 years ago through a post about a GPU technique used in raymarching, geometry representation, and shading a scene - a high performance demo scene entry, if I recall correctly. Needless to say, their results were much more impressive than mine.

The first image to come out of the application is really disturbing as I can't really wrap my head around what is being generated - I can create a simple sphere and totally know what's happening, but put in a few coordinate wrapping transformations and everything goes out of hand.
The camera is animated so that the true 3D nature of the algorithm can be appreciated.
Normal light calculations are next to come.

In the upcoming posts about this technique I will be trying to control the geometry to match the vision I have in my head, and I will explain more about this raymarching if it is the case I am doing something out of the normal.

Thursday, March 11, 2010

Flash Clock

So today was a very bad migraine day yet somehow I managed to fork out my old circular menu and create a nifty little clock that I wish I could be hanging on my wall.



There's nothing really technical about the change from the one code to the other, other than copy-pasting a block of code and changing it two times to cater for minutes and seconds. Then I added the time driven code, and that was it.

Who says cool has to be tiresome!

Tuesday, March 9, 2010

Circular Menu

So part of my actionscript continuous practice routine, this little mind child is born.
The basic idea behind it is that the selected button will take up the space of two items, and get centered in the middle of it. The other items will leave that space and get squeezed against each other.
Inside the code, you'll see a lot of the modulus (%) operators. This is ordinary of code handling such cyclic objects.
As for seeing the magic trick, you should move your pointer in a cyclic manner on the buttons. You'll see the whole circle moving, but in effect after a full cycle, it's still in its place.
You have to see the bigger picture so that it can be explained. It lies in the fact that the average of all rotations will stay constant no matter how you move the mouse.
I posted the code and the flash here again.
Till the next brief blog entry.

Monday, March 8, 2010

Mechanical Gears

As a mechanical engineer, I must have some fetish for gears. And I do.
I wrote up a simple example on how simplistic gears can be drawn in actionscript code and posted it on wonderfl. You can check it out here.
The basic idea is to iterate in a loop around the points in a polar manner and provide values for the distance from the center. Coupled with some array data storing for a single gear tooth, and some sin/cos mapping from polar coordinates into cartesian ones, we drew a gear.



Draw two gears, give them compliant tooth to radius ratios and we simply get two meshing gears (if placed at the correct distance).
This example shows the reason why the gears are shaped a little beveled into the inside; The ones I drew are not beveled and if you look closely, they do have an intersection area that would generate a lot of wear, tear, and clicking (if not roaring) noises in a real life situation. Granted there are many standards into creating gears; none of which I'll explore in this blog.