let pattTernColor = new Array();

//------------------------------------
//
// Arc en ciel de couleurs
//
let frequence = .2;
let RFrequence = Math.PI / 9;
let VFrequence = Math.PI / 17;
let BFrequence = Math.PI / 4;
for (let i = 0; i < 20; ++i)
{
    let r = Math.round(Math.sin(RFrequence * i) * 70 + 180);
    let g = Math.round(Math.sin(VFrequence * i) * 70 + 180);
    let b = Math.round(Math.sin(BFrequence * i) * 70 + 180);
    let txt = 255;
    if ((r + g + b) > 100) {
        txt = 0;
    }
    pattTernColor[i] = {};
    pattTernColor[i].r = r;
    pattTernColor[i].g = g;
    pattTernColor[i].b = b;
    pattTernColor[i].t = txt;
}


function creePng() {

// g�n�ration de PNG achur�.
    let tailleDiagImg = 10;
    let p;
    let out = '';
    
    for (let numCol = 0; numCol < pattTernColor.length; numCol++) {
        p = new PNGlib(tailleDiagImg, tailleDiagImg, 256);

        for (let x = 0; x < tailleDiagImg; x++) {
            for (let y = 0; y < tailleDiagImg; y++) {
                let textColor = p.color(pattTernColor[numCol].t, pattTernColor[numCol].t, pattTernColor[numCol].t, 255);
                let fillColor = p.color(pattTernColor[numCol].r, pattTernColor[numCol].g, pattTernColor[numCol].b, 200);
                
                switch (numCol % 5) {
                    case 0:
                        if (x === y) { // parttern : \
                            p.buffer[p.index(x, y)] = textColor;
                        } else {
                            p.buffer[p.index(x, y)] = fillColor;
                        }
                        break;
                    case 1 :
                        if ((tailleDiagImg - 1) - x === y) { // parttern : /
                            p.buffer[p.index(x, y)] = textColor;
                        } else {
                            p.buffer[p.index(x, y)] = fillColor;
                        }
                        break;

                    case 2 :
                        if (x === 2 || x === 7) { // parttern : |
                            p.buffer[p.index(x, y)] = textColor;
                        } else {
                            p.buffer[p.index(x, y)] = fillColor;
                        }
                        break;
                    case 3 :
                        if (y === 2 || y === 7) { // parttern : _
                            p.buffer[p.index(x, y)] = textColor;
                        } else {
                            p.buffer[p.index(x, y)] = fillColor;
                        }
                        break;
                    case 4 :
                        if (tailleDiagImg - x === y || x === y) { // parttern : x
                            p.buffer[p.index(x, y)] = textColor;
                        } else {
                            p.buffer[p.index(x, y)] = fillColor;
                        }
                        break;
                }

            }
        }
        out += '<img id="imgColl_' + numCol + '" src="data:image/png;base64,' + p.getBase64() + '">&nbsp;';
    }

    document.getElementById('pngg').innerHTML = out;
}
