Oops, just realized that when running my code in Flash 8 nothing shows up -
because the drawing is just outside the bounds of the stage.

After line 52 or so
                canvas._x = i;
just add
                canvas._y = canvas._height;

Find the corrected code below.

hth
--------------
Andreas Weber
motiondraw.com


temperatureValues = new Array();

// create some random temperature data
for(var i= 0; i<400; i++){
        lastVal = i ? temperatureValues[i-1] : 50;
        if(lastVal > 100){
                c = -1;
        }else if(lastVal < 0){
                c = 1;
        }else{
                c = Math.random() > 0.5 ? 1 : -1;
        }
        temperatureValues[i] = lastVal + c;
}

neutralColor = 0x006666;
coldColor = 0x66FFFF;// temperature = 0
hotColor =  0xFF0000;// temperature = 100

hotColdRange =  colorRange(coldColor, hotColor, 100);

drawGraph();

function drawGraph(){
        for(var i=0, len=temperatureValues.length; i<len; i++){
                canvas = 
this.createEmptyMovieClip('canvas'+i,this.getNextHighestDepth());

                // highest temperature:  v = 255
                // lowest temperature: v = 0
                // for this sample we use a temperature range from 0 to 100
                temperatureRange = 100;
                v = temperatureValues[i] * (255 / temperatureRange);
                ratios = [0, v, 255];
                colors = [neutralColor,
hotColdRange[Math.floor(temperatureValues[i])],neutralColor];
                alphas = [100, 100, 100];

                // more graph, less 'borealis'
                //ratios = [0, v-30, v, v+30, 255];
                //colors = [neutralColor,
neutralColor,hotColdRange[Math.floor(temperatureValues[i])], neutralColor,
neutralColor];
                //alphas = [100, 100, 100, 100, 100];

                matrix = {a:100, b:0, c:0, d:0, e:100, f:0, g:100, h:100, i:1};
                matrix = {matrixType:"box", x:0, y:0, w:100, h:100, r:0};

                canvas.beginGradientFill("linear", colors, alphas, ratios, 
matrix);
                canvas.lineTo(100, 0);
                canvas.lineTo(100, 1);
                canvas.lineTo(0, 1);
                canvas.lineTo(0, 0);
                canvas.endFill();
                canvas._rotation = -90;
                canvas._x = i;
                canvas._y = canvas._height;

        }
}

function colorRange(c1, c2, n) {
                var c1 = {r:(c1 & 0xFF0000) >> 16, g:(c1 & 0x00FF00) >> 8, b:c1 
&
0x0000FF};
                var c2 = {r:(c2 & 0xFF0000) >> 16, g:(c2 & 0x00FF00) >> 8, b:c2 
&
0x0000FF};

                var r = (c2.r-c1.r)/(n-1);
                var g = (c2.g-c1.g)/(n-1);
                var b = (c2.b-c1.b)/(n-1);

                var color_arr = new Array();
                for(var i=0, len=n; i<len; i++){
                        color_arr[i] = ((c1.r+i*r) << 16) + ((c1.g+i*g) << 8) + 
(c1.b+i*b);
                }
                return color_arr;
}



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to