Identify the last number on canvas

I have a canvas that shows digits, rising ,until its green color changes to red and stop numbering.
i want to warn me just on time its color changes to red or any time in this period before getting red.please guide me

<canvas id="qrlsa" width="575" height="359" style="width: 575px; height: 359px;"></canvas>

Please see the sample movie on youtube:

My code:

function getAverageRGB(imgEl) {
    
    var blockSize = 5, // only visit every 5 pixels
        defaultRGB = {r:0,g:0,b:0}, // for non-supporting envs
        canvas = document.createElement('canvas'),
        context = canvas.getContext && canvas.getContext('2d'),
        data, width, height,
        i = -4,
        length,
        rgb = {r:0,g:0,b:0},
        count = 0;
        
    if (!context) {
        return defaultRGB;
    }
    
    height = canvas.height = imgEl.naturalHeight || imgEl.offsetHeight || imgEl.height;
    width = canvas.width = imgEl.naturalWidth || imgEl.offsetWidth || imgEl.width;
    
    context.drawImage(imgEl, 0, 0);
    
    try {
        data = context.getImageData(0, 0, width, height);
    } catch(e) {
        /* security error, img on diff domain */alert('x');
        return defaultRGB;
    }
    
    length = data.data.length;
    
    while ( (i += blockSize * 4) < length ) {
        ++count;
        rgb.r += data.data[i];
        rgb.g += data.data[i+1];
        rgb.b += data.data[i+2];
    }
    
    // ~~ used to floor values
    rgb.r = ~~(rgb.r/count);
    rgb.g = ~~(rgb.g/count);
    rgb.b = ~~(rgb.b/count);
    
    return rgb;
    
}
setInterval(function() {
    var rgb = getAverageRGB(document.getElementById('qrlsa'));
    document.body.style.backgroundColor = 'rgb('+rgb.r+','+rgb.g+','+rgb.b+')';
    //if (rgb.r>10) {
        //alert(rgb.r+','+rgb.g+','+rgb.b);
    //}
}, 1);

You’d do better sniffing the javascript being used to write/rewrite the canvas than trying to read the canvas itself…

Please help me more…

There’s not much more i can say with the information provided.

How is the number on the canvas being generated? You must have other code that is doing it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.