Difference between revisions of "Bar-graph.as"

From Organic Design wiki
m
m ({{as}})
 
(74 intermediate revisions by 2 users not shown)
Line 1: Line 1:
this.barColour = 0x00ff00;
+
// Bar graph example{{as}}
this.barWidth = 5;
+
create.barGraph = function( name, layer ) {
this.barSpacing = 10;
 
this.bars = 50;
 
  
this.curBuf = 0;
+
// Create main symbol with a graph and mask symbol within
this.curBar = 0;
+
this.createEmptyMovieClip( name, layer );
 +
var sym = this[name];
 +
sym.attachMovie( 'square', 'mask', 0 );
 +
sym.createEmptyMovieClip( 'graph', 1 );
 +
var graph = sym; // should be set to sym.graph but masking not working
  
// Make two bar-graph buffers of n-bars
+
// These should be sent in create, but that's not supported yet
for ( var i = 0; i < 1; i++ ) {
+
graph.barColour = 0x00ff00;
 +
graph.barWidth = 5;
 +
graph.barSpacing = 10;
 +
graph.bars = 50;
  
this.createEmptyMovieClip( 'buf' + i, i );
+
// Define current buffer and position in buffer
var buf = this[ 'buf' + i ];
+
graph.curBuf = 0;
buf._width = this.barSpacing * this.bars;
+
graph.curBar = graph.bars - 1;
buf._height = height;
 
buf._x = i * width;
 
buf._y = 0;
 
  
// Create bars in this buffer
+
// Set mask to display size
for ( j = 0; j < this.bars; j++ ) {
+
//sym.mask._x = sym.mask._y = 0;
buf.createEmptyMovieClip( 'bar' + j, j );
+
//sym.mask._width = graph.barSpacing * graph.bars;
var bar = buf[ 'bar' + j ];
+
//sym.mask._height = _root.height;
bar.lineStyle( 0, 0, 0 );
+
//graph.setMask( sym.mask );
bar.beginFill( this.barColour, 100 );
+
 
bar.moveTo( 0, 0 );
+
// Make two bar-graph buffers of n-bars
bar.lineTo( 0, 1 );
+
for ( var i = 0; i < 2; i++ ) {
bar.lineTo( 1, 1 );
+
 
bar.lineTo( 1, 0 );
+
graph.createEmptyMovieClip( 'buf' + i, i );
bar.lineTo( 0, 0 );
+
var buf = graph[ 'buf' + i ];
bar.endFill();
+
buf._x = i * graph.barSpacing * graph.bars;
bar._x = j * this.bar
+
buf._y = 0;
bar._y = _root.height;
+
 
bar._width = this.barWidth;
+
// Create bars in this buffer
bar._height = _root.height / 2;
+
for ( var j = 0; j < graph.bars; j++ ) {
 +
buf.createEmptyMovieClip( 'bar' + j, j );
 +
var bar = buf[ 'bar' + j ];
 +
bar.lineStyle( 0, 0, 0 );
 +
bar.beginFill( graph.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 * graph.barSpacing;
 +
bar._y = _root.height;
 +
bar._width = graph.barWidth;
 +
bar._height = 0;
 +
}
 
}
 
}
}
 
  
// Method to scroll the graph and insert a value
+
// Method to scroll the graph and insert a value
this.rotate = function( value ) {
+
graph.rotate = function( value ) {
  
// Scroll both buffers
+
// Scroll both buffers
for ( var i = 0; i < 1; i++ ) {
+
// - and switch to right when it scrolls off left
var buf = this[ 'buf' + i ];
+
var size = graph.barSpacing * graph.bars;
buf._x -= this.barSpacing;
+
graph.buf0._x -= graph.barSpacing;
if ( buf._x < -this._width ) buf._x += 2 * this._width;
+
if ( graph.buf0._x < -size ) graph.buf0._x += 2 * size;
}
+
graph.buf1._x -= graph.barSpacing;
 +
if ( graph.buf1._x < -size ) graph.buf1._x += 2 * size;
 +
 
 +
// Update the current bar and buffer pointers
 +
if ( 0 == graph.curBar = ++graph.curBar % graph.bars ) graph.curBuf ^= 1;
  
// Update the current bar and buffer pointers
+
// Update the height value at the current bar
if ( ( ++this.curBar % this.bars ) == 0 ) this.curBuf ^= 1;
+
var bar = graph[ 'buf' + graph.curBuf ][ 'bar' + graph.curBar ];
 +
bar._height = value;
  
// Update the height value at the current bar
+
};
this[ 'buf' + this.curBuf ][ 'bar' + this.curBar ]._height = value;
 
  
}
+
return sym;
 +
};

Latest revision as of 09:43, 14 March 2009

// Bar graph exampleTemplate:As create.barGraph = function( name, layer ) {

// Create main symbol with a graph and mask symbol within this.createEmptyMovieClip( name, layer ); var sym = this[name]; sym.attachMovie( 'square', 'mask', 0 ); sym.createEmptyMovieClip( 'graph', 1 ); var graph = sym; // should be set to sym.graph but masking not working

// These should be sent in create, but that's not supported yet graph.barColour = 0x00ff00; graph.barWidth = 5; graph.barSpacing = 10; graph.bars = 50;

// Define current buffer and position in buffer graph.curBuf = 0; graph.curBar = graph.bars - 1;

// Set mask to display size //sym.mask._x = sym.mask._y = 0; //sym.mask._width = graph.barSpacing * graph.bars; //sym.mask._height = _root.height; //graph.setMask( sym.mask );

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

graph.createEmptyMovieClip( 'buf' + i, i ); var buf = graph[ 'buf' + i ]; buf._x = i * graph.barSpacing * graph.bars; buf._y = 0;

// Create bars in this buffer for ( var j = 0; j < graph.bars; j++ ) { buf.createEmptyMovieClip( 'bar' + j, j ); var bar = buf[ 'bar' + j ]; bar.lineStyle( 0, 0, 0 ); bar.beginFill( graph.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 * graph.barSpacing; bar._y = _root.height; bar._width = graph.barWidth; bar._height = 0; } }

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

// Scroll both buffers // - and switch to right when it scrolls off left var size = graph.barSpacing * graph.bars; graph.buf0._x -= graph.barSpacing; if ( graph.buf0._x < -size ) graph.buf0._x += 2 * size; graph.buf1._x -= graph.barSpacing; if ( graph.buf1._x < -size ) graph.buf1._x += 2 * size;

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

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

};

return sym; };