Difference between revisions of "Bar-graph.as"

From Organic Design wiki
(Main guts of the bar-graph symbol :-))
 
m
Line 1: Line 1:
this.barWidth;
+
this.barColour = 0x00ff00;
this.barSpacing;
+
this.barWidth = 5;
this.bars;
+
this.barSpacing = 10;
 +
this.bars = 50;
  
 
this.curBuf = 0;
 
this.curBuf = 0;
Line 8: Line 9:
 
// Make two bar-graph buffers of n-bars
 
// Make two bar-graph buffers of n-bars
 
for ( var i = 0; i < 1; i++ ) {
 
for ( var i = 0; i < 1; i++ ) {
 +
 
this.createEmptyMovieClip( 'buf' + i, i );
 
this.createEmptyMovieClip( 'buf' + i, i );
 
var buf = this[ 'buf' + i ];
 
var buf = this[ 'buf' + i ];
Line 14: Line 16:
 
buf._x = i * width;
 
buf._x = i * width;
 
buf._y = 0;
 
buf._y = 0;
 +
 +
// Create bars in this buffer
 
for ( j = 0; j < this.bars; j++ ) {
 
for ( j = 0; j < this.bars; j++ ) {
 
buf.createEmptyMovieClip( 'bar' + j, j );
 
buf.createEmptyMovieClip( 'bar' + j, j );
 
var bar = buf[ 'bar' + j ];
 
var bar = buf[ 'bar' + j ];
 +
bar.lineStyle( 0, 0, 0 );
 +
bar.beginFill( this.barColour, 100 );
 +
bar.moveTo( 0, 0 );
 +
bar.lineTo( 0, 1 );
 +
bar.lineTo( 1, 1 );
 +
bar.lineTo( 1, 0 );
 +
bar.lineTo( 0, 0 );
 +
bar.endFill();
 
bar._x = j * this.bar
 
bar._x = j * this.bar
 
bar._y = _root.height;
 
bar._y = _root.height;
 
bar._width = this.barWidth;
 
bar._width = this.barWidth;
 +
bar._height = _root.height / 2;
 
}
 
}
 
}
 
}

Revision as of 07:34, 25 March 2006

this.barColour = 0x00ff00; this.barWidth = 5; this.barSpacing = 10; this.bars = 50;

this.curBuf = 0; this.curBar = 0;

// Make two bar-graph buffers of n-bars for ( var i = 0; i < 1; i++ ) {

this.createEmptyMovieClip( 'buf' + i, i ); var buf = this[ 'buf' + i ]; buf._width = width; buf._height = height; buf._x = i * width; buf._y = 0;

// Create bars in this buffer for ( j = 0; j < this.bars; j++ ) { buf.createEmptyMovieClip( 'bar' + j, j ); var bar = buf[ 'bar' + j ]; bar.lineStyle( 0, 0, 0 ); bar.beginFill( this.barColour, 100 ); bar.moveTo( 0, 0 ); bar.lineTo( 0, 1 ); bar.lineTo( 1, 1 ); bar.lineTo( 1, 0 ); bar.lineTo( 0, 0 ); bar.endFill(); bar._x = j * this.bar bar._y = _root.height; bar._width = this.barWidth; bar._height = _root.height / 2; } }

// Method to scroll the graph and insert a value this.rotate = function( val ) {

// Scroll both buffers for ( var i = 0; i < 1; i++ ) { var buf = this[ 'buf' + i ]; buf._x -= this.barSpacing; if ( buf._x < -this._width ) buf._x += 2 * this._width; }

// Update the current bar and buffer pointers if ( ( ++this.curBar % this.bars ) == 0 ) this.curBuf ^= 1;

// Update the height value at the current bar this[ 'buf' + this.curBuf ][ 'bar' + this.curBar ]._height = value;

}