Laboratory output n°66 Connections

Efla 1000 connections
Here you see 1000 particles connecting each other if they travel close enough.

FormsOfConnections
Abstract form of connections.

Connect3dSphereIn2Dimensions
Combine 3D sphere into dimension two by connections.

3DConnections
Connections in 3 dimensions.

Optimizing is everything. More you can optimize more powerful your tools become and you can do more. I never get tired of researching more ways to optimize.

First level of optimization is to get current code to run as efficient as possible by cutting off all unnecessary method calls and maths. Also strict typing and bitwise solutions need to be thought.

Second level is to think about the concept. Like in these demos if all objects check their distance with all objects the cpu will freeze. The solution is to split the scene into grid and push objects into those blocks according their coordinates. With that the distance check can be crop to affect only objects that are near.

Third level is something that I haven’t reached yet so don’t know anything about it yet.. :)

What do you think of this? (6)

Extremely Fast Line Algorithm AS3 Optimized

Time to time a developer has to ask from Self: “is this really the fastest way to do it?”
After some investigation in most cases the result is “no it wasn’t”. Here’s an example:

I have used (a little modified version of) the Andre Michelle’s port from Bresenhams line algorithm and always thought it would be the fastest way to draw a line on BitmapData in Flash.

I was playing with lines and asked my self the previous question. After some Googling I found this Extremely Fast Line Algorithm (EFLA) written by Po-Han Lin. I gave it a try and ported it to as3. By default it was way faster then the Bresenhams version, but after some AS3 specific optimizations it came out TWO times faster and here it is for you:

private function efla(x:int, y:int, x2:int, y2:int, color:uint):void
{
  var shortLen:int = y2-y;
  var longLen:int = x2-x;

  if((shortLen ^ (shortLen >> 31))(shortLen >> 31) > (longLen ^ (longLen >> 31))(longLen >> 31))
  {
  shortLen ^= longLen;
  longLen ^= shortLen;
  shortLen ^= longLen;

  var yLonger:Boolean = true;
  }
  else
 {
  yLonger = false;
 }

  var inc:int = longLen < 0 ? -1 : 1;

  var multDiff:Number = longLen == 0 ? shortLen : shortLen / longLen;

  if (yLonger)
  {
    for (var i:int = 0; i != longLen; i += inc)
    {
      this.bit.setPixel(x + i*multDiff, y+i, color);
    }
  }
  else
  {
    for (i = 0; i != longLen; i += inc)
    {
      this.bit.setPixel(x+i, y+i*multDiff, color);
    }
  }
}

What do you think of this? (21)

Laboratory output n°65 BlackHole

BlackHole

Gravitation

max = 10;
gravity = .006;

dx = -pa.x;
dy = -pa.y;
dz = -pa.z;

//dist = Math.sqrt(dx*dx + dy*dy + dz*dz);
//dsg = dist * dist * gravity;

dsg= (dx*dx + dy*dy + dz*dz) * gravity;

pa.vx += dx / dsg;
pa.vy += dy / dsg;
pa.vz += dz / dsg;

pa.vx = (pa.vx > max) ? max : ( (pa.vx < -max) ? -max : pa.vx );
pa.vy = (pa.vy > max) ? max : ( (pa.vy < -max) ? -max : pa.vy );
pa.vz = (pa.vz > max) ? max : ( (pa.vz < -max) ? -max : pa.vz );

pa.x += pa.vx;
pa.y += pa.vy;
pa.z += pa.vz;

What do you think of this? (3)

Laboratory output n°64 BlueWhale

Blue Whale

I created this math last Spring for one project that didn’t finished then and has taken a new path now so this elegant loop has become available. I cannot think of better way to show it than combine it with the most intriguing being on Earth, the Blue Whale.

Make sure you have a head sets and your volume is set to high since Blue Whale has very low voice. A lot of his song is under our ability to hear. Never the less you can still feel it inside your head and deep in your stomach. That sound can be heard over 1200 kilometers away. These fellows can sing through oceans to each other!

Wikipedia:
“Source level of sounds made by Blue Whales are between 155 and 188 decibels when measured relative to a reference pressure of one micropascal at one metre. All Blue Whale groups make calls at a fundamental frequency of between 10 and 40 Hz, and the lowest frequency sound a human can typically perceive is 20 Hz. Blue Whale calls last between ten and thirty seconds. Blue Whales off the coast of Sri Lanka have been repeatedly recorded making “songs” of four notes duration lasting about two minutes each.”

What do you think of this? (5)

Laboratory output n°63 A Glorious Dawn

A Glorious Dawn

I was inspired by this video and song by John Boswell to watch the Carl Sagan‘s Cosmos series from the seventies. What a pedagogue this man was and still is!

Here‘s my art contribution to honor him.

I think the song is master piece after knowing the raw material Mr. Boswell used. Check out his stuff at colorpulsemusic.com. By the way it’s a whale song.. If you are wondering what Sagan is trying to sing at the beginning.

The visual synchronization is made by using only soundChannel.left- ja rightPeak. You may click on it to activate the explosion.
Ohh and here are the code for creating sphere that has it’s points correctly randomly separated.

var u:Number = Math.random();
var v:Number = Math.random();

z = -1 + 2 * u;
var z2:Number = Math.sqrt(1.0 – z * z);
var phi:Number = (2. * Math.PI) * v;
x = z2 * Math.cos(phi);
y = z2 * Math.sin(phi);

What do you think of this?

Laboratory output n°62 GameOfLife3D

I have wanted to do this right after I did it in 2d almost a year ago. The task wasn’t easy since there is exponentially more of everything and that cost cpu.
Well.. “If you wish to make an apple pie from scratch, you must first create the universe.” – said Carl Sagan and that meant study on optimizing the as3.

Here are the rules:
1. Every dot know their neighbours at up, down, left, right, back and forward.
2. Ones their Boolean ‘active’ is true they scale up and add random value to their property ‘hot’.
3. If random value is greater then their hot value they set their neighbours active to true.
4. All dot’s ‘hot’ and ‘scale’ value drops during time.

Click on them to active one random dot. Realize that what you are seeing are reactions created by change in constant system.

GameOfLife3Da
12x12x12 = 1728 particles

GameOfLife3Db
15x15x15 = 3376 particles

GameOfLife3Dc
20x20x20 = 8000 particles

For you with fast cpu:
GameOfLife3Dd
24x24x24 = 13824 particles

What do you think of this? (5)