Difference between revisions of "Z-order.as"

From Organic Design wiki
m
Line 7: Line 7:
 
// Create some balls each of different colours and put in z-buffer
 
// Create some balls each of different colours and put in z-buffer
 
for ( i = 0; i < balls; i++ ) {
 
for ( i = 0; i < balls; i++ ) {
create.ball( 'ball'+i, i );
 
zbuff[i] = _root['ball'+i];
 
 
j = i + 1;
 
j = i + 1;
r = (j & 1) ? 0xff : 0;
+
colour = (j & 1) ? 0xff0000 : 0;
g = (j & 2) ? 0xff : 0;
+
colour |= (j & 2) ? 0x00ff00 : 0;
b = (j & 4) ? 0xff : 0;
+
colour |= (j & 4) ? 0x0000ff : 0;
//c = new Color( zbuff[i] );
+
zbuff[i] = _root['ball'+i] = create.ball( 'ball' + i, i, colour );
//c.setTransform( { ra:r, ga:g, ba:b } );
 
 
}
 
}
  

Revision as of 20:37, 24 March 2006

  1. include "ball.as"

balls = 6; zbuff = []; angle = 0; arc = 2 * Math.PI / balls;

// Create some balls each of different colours and put in z-buffer for ( i = 0; i < balls; i++ ) { j = i + 1; colour = (j & 1) ? 0xff0000 : 0; colour |= (j & 2) ? 0x00ff00 : 0; colour |= (j & 4) ? 0x0000ff : 0; zbuff[i] = _root['ball'+i] = create.ball( 'ball' + i, i, colour ); }

// Per frame function reduce() {

// Sort the z-buffer by z zbuff.sort( function(a,b) { return a.z > b.z; } );

// Set ball coordinates, scales and depths for this frame angle += 0.01; for ( i = 0; i < balls; i++ ) { obj = _root['ball'+i]; b = angle + arc * i; obj.z = obj._xscale = obj._yscale = 50 + Math.cos(b) * 10; obj._x = width / 2 + Math.sin(b) * width / 3; obj._y = height / 4 + obj.z * 2; zbuff[i].swapDepths(i); }

}