Live update of rgba using clientX/clientY?

The code below works until line 47 is replaced with line 48 (i.e. calculating the fillStyle). For some reason attempting to use clientY to calculate the blue portion of the rgba doesn’t work, whereas calculating the alpha is not a problem.

<!DOCTYPE html>

    <title> My Animation </title>

    <canvas id="myCanvas" height="768" width="1200"></canvas>

    var mainCanvas = document.getElementById("myCanvas");
    var ctx = mainCanvas.getContext('2d');
    var canvasWidth = mainCanvas.width;
    var canvasHeight = mainCanvas.height;
    // the array of squares
    var squares = [];

    var mouseX = 1200;
    var mouseY = 768;
    var putPoint = function (e) {
        // update mouse
        mouseX = e.clientX;
        mouseY = e.clientY;
    mainCanvas.addEventListener("click", putPoint);

    for (i = 0; i 

Source: stackoverflow-javascript