> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.flZKwqOydQh/rev.480
 * 
 * authors: 
 *   Claudio Pinho

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// This sketch builds on a prior work created by Claudio Pinho & [unnamed author]
// http://studio.sketchpad.cc/sp/pad/view/FGrt7F3eDY/rev.1440

boolean[][] pixelMap;
String[][]  startChars;
 
int PIXELSIZE = 4;
int NUMCHARS = 17;
int CHARHEIGHT = 7;
int CHARWIDTH = 5;
int NUMOFLINES = 20;
int lastStep;
 
//  copies a character into a pixel map
void  copyChar(boolean[][] c, int xpos) {
     for (int i = 0; i < c.length; ++i) {
         for (int j = 0; j < c[i].length; ++j) {
             pixelMap[xpos + i][j] = c[i][j];
         }
    }
}
 
//  converts a character from the Font's string representation
//  into the pixel boolean array format.
boolean[][]  convertChar(String[] c) {
    boolean[][] out = new  boolean[CHARWIDTH][CHARHEIGHT];

     for (int i = 0; i < c.length; ++i) {                 // i = height
         for (int j = 0; j < c[i].length(); ++j) {        // j = width
            
             // Font format uses first dimension as height and
             // second as width; pixel map does the reverse.
             out[j][i] = c[i].substring(j, j+1).equals(".");
         }
    }
    return out;
}
 
void  setupInitialChars() {
    int offset = NUMCHARS -  startChars.length;
    int offset2 = (offset*CHARWIDTH)/2;
    for (int i = 0; i <  startChars.length; ++i) {
         copyChar(convertChar(startChars[i]), ((i+offset)*CHARWIDTH)-offset2);
    }
}    
 
void  setup() {
     //size(340, 560);
     size(PIXELSIZE*CHARWIDTH*NUMCHARS, PIXELSIZE*CHARHEIGHT*NUMOFLINES);

     //######   where we put the letters to show on screen  ######################
     startChars = new String[][] { L, e, i, t, o, u, r, g, oA, s, exc };
     
     pixelMap = new boolean[NUMCHARS*CHARWIDTH][CHARHEIGHT*NUMOFLINES];
     setupInitialChars();
     lastStep = millis();
     noStroke();
}
 
void draw() {
     background(0);
    boolean anyPixels = false;
     for (int i = 0; i < pixelMap.length; ++i) {
         for (int j = 0; j < pixelMap[i].length; ++j) {
             if (pixelMap[i][j]) {
                anyPixels =  true;
                fill(255, 0, 0);
                ellipse(PIXELSIZE/2 + i*PIXELSIZE, PIXELSIZE/2 + j*PIXELSIZE,
                         PIXELSIZE-1, PIXELSIZE-1);
            }
         }
    }
    if (millis() - lastStep  > 300) {
        for (int i = 0; i < pixelMap.length-1;  ++i) {
          for ( int j = pixelMap[i].length-1; j > 0; --j){
            pixelMap[i][j] = pixelMap[i][j-1];
          }
        }
        
        for(int i = 0; i < pixelMap.length-1; ++i){
          pixelMap[i][0] = false;
        }
        
        lastStep = millis();
    }
    if (! anyPixels) {
      setupInitialChars();
    }
}
 
void  mousePressed() {
    setupInitialChars();
}
 
/*  Font! */
 
String[]  H = new String[] {
".  .",
".  .",
".  .",
"....",
".  .",
".  .",
".  ."};
 
String[] e = new String[] {
"    ",
"    ",
" .. ",
".  .",
"....",
".    ",
" .. "};
 
String[] l = new String[] {
" .. ",
"  . ",
"  . ",
"  . ",
"  . ",
"  . ",
" ..."};
 
String[]  o = new String[] {
"    ",
"    ",
" .. ",
".  .",
".  .",
".  .",
" .. "};

String[] oA = new String[] {
"   .",
"  . ",
" .. ",
".  .",
".  .",
".  .",
" .. "};
 
String[]  exc = new String[] {
" .  ",
" .  ",
" .  ",
" .  ",
" .  ",
"    ",
" .  "};

String[] M = new String[]{
".  .",
"....",
".  .",
".  .",
".  .",
".  .",
".  ."};

String[] a = new String[]{
"    ",
"    ",
" .. ",
"   .",
" ...",
".  .",
" ..."};

String[] g = new String[]{
"    ",
"    ",
" .. ",
".   ",
". ..",
".  .",
" .. "};

String[] s = new String[]{
"    ",
"    ",
" ...",
".   ",
" .. ",
"   .",
"... "};

String[] u = new String[]{
"    ",
"    ",
".  .",
".  .",
".  .",
".  .",
"...."};

String[] L = new String[]{
".   ",
".   ",
".   ",
".   ",
".   ",
".   ",
"...."};

String[] i = new String[]{
"    ",
" .  ",
"    ",
" .  ",
" .  ",
" .  ",
" .  "};

String[] t = new String[]{
"    ",
" .  ",
"... ",
" .  ",
" .  ",
" .  ",
"  . "};

String[] r = new String[]{
"    ",
"    ",
". ..",
"..  ",
".   ",
".   ",
".   "};