'Drawing a colored grid with colors based on a text file

How can a given sequence of N digits (stored simply as a string in some text file "digits.txt", like 3204815627....) be depicted as a PxQ array (where PxQ=N) consisting of squares (of R pixels in width & length), the color of each square being determined by its corresponding position number in the given sequence of N digits.
We assume that each digit corresponds to some specific color (e.g., 0=green, 1=blue, 2=grey etc.) and that the squares are numbered from 1 to N consecutively along the array rows.
So, can the above be achieved using HTML, CSS & JavaScript in a parametric way based on N, P, Q and R?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source