 &#x3D; halfPi - aspect;
      } else if (aspect &gt; halfPi) {
        aspect &#x3D; twoPi - aspect + halfPi;
      } else {
        aspect &#x3D; halfPi - aspect;
      }

      cosIncidence &#x3D; sinSunEl * Math.cos(slope) +
          cosSunEl * Math.sin(slope) * Math.cos(sunAz - aspect);

      offset &#x3D; (pixelY * width + pixelX) * 4;
      scaled &#x3D; 255 * cosIncidence;
      shadeData[offset] &#x3D; scaled;
      shadeData[offset + 1] &#x3D; scaled;
      shadeData[offset + 2] &#x3D; scaled;
 