1 /*
    2 
    3 prototype visualization for "four letter words" sculpture,
    4 to be installed in an actual outdoor 4-digit 7-segment clock
    5 
    6 data/7segment.svg is a layered illustrator svg file containing a 7-segment character
    7 data/nocolon.svg is an svg file containing just the colon
    8 data/fourletters.txt contains 1 four letter word per line, the contents of the patriot act 2
    9 
   10 2007 rob duarte <rahji@rahji.com>
   11   http://www.robduarte.com
   12   http://www.rahji.com
   13 
   14 */
   15 
   16 import processing.candy.*;
   17 import processing.xml.*;
   18 import processing.video.*;
   19 
   20 /*
   21 
   22 any commented lines mentioning 'mm', including the keyPressed() function
   23 are used to capture the sequence to a Quicktime movie.
   24 the speed of the movie can be increased by shortening the delay at the 
   25 start of each frame (in the draw() function)
   26 the Quicktime movie will always be at the correct speed of 1 fps
   27 because it is defined in the MovieMaker constructor
   28 
   29 */
   30 // MovieMaker mm;
   31 
   32 boolean debug = false; // print debugging info as we go
   33 
   34 SVG svgletter, nocolon;
   35 SVG[] leg  = new SVG[7];
   36 SVG[] noleg = new SVG[7];
   37 
   38 int drawx = 260;
   39 int drawy = 320;
   40 
   41 int[] lettermap = {
   42   1,1,1,0,1,1,1, //a 
   43   0,0,1,1,1,1,1, //b
   44   1,0,0,1,1,1,0, //c
   45   0,1,1,1,1,0,1, //d
   46   1,0,0,1,1,1,1, //e
   47   1,0,0,0,1,1,1, //f
   48   1,1,1,1,0,1,1, //g
   49   0,1,1,0,1,1,1, //h
   50   0,1,1,0,0,0,0, //i
   51   0,1,1,1,1,0,0, //j
   52   0,0,0,0,1,1,1, //k
   53   0,0,0,1,1,1,0, //l
   54   1,0,1,0,1,0,0, //m
   55   0,0,1,0,1,0,1, //n
   56   1,1,1,1,1,1,0, //o
   57   1,1,0,0,1,1,1, //p
   58   1,1,1,0,0,1,1, //q
   59   0,0,0,0,1,0,1, //r
   60   1,0,1,1,0,1,1, //s
   61   0,0,0,1,1,1,1, //t
   62   0,1,1,1,1,1,0, //u
   63   0,0,1,1,1,0,0, //v
   64   0,1,0,1,0,1,0, //w
   65   0,1,1,0,1,1,1, //x
   66   0,1,1,1,0,1,1, //y
   67   1,1,0,1,1,0,1  //z
   68 };
   69 
   70 BufferedReader reader;
   71 
   72 void setup(){
   73   
   74   randomSeed(second());
   75   
   76   background(0);
   77   size(1280,800);
   78   
   79   // mm = new MovieMaker(this, width, height, "drawing.mov",1, MovieMaker.H263, MovieMaker.HIGH);
   80   
   81   nocolon  = new SVG(this, "colon_off.svg");
   82     
   83   svgletter = new SVG(this, "7segment.svg");
   84   leg[0] = svgletter.get("a_on_");  noleg[0] = svgletter.get("a_off_");
   85   leg[1] = svgletter.get("b_on_");  noleg[1] = svgletter.get("b_off_");
   86   leg[2] = svgletter.get("c_on_");  noleg[2] = svgletter.get("c_off_");
   87   leg[3] = svgletter.get("d_on_");  noleg[3] = svgletter.get("d_off_");
   88   leg[4] = svgletter.get("e_on_");  noleg[4] = svgletter.get("e_off_");
   89   leg[5] = svgletter.get("f_on_");  noleg[5] = svgletter.get("f_off_");
   90   leg[6] = svgletter.get("g_on_");  noleg[6] = svgletter.get("g_off_"); 
   91 
   92   reader = createReader("fourletters.txt");
   93 }
   94 
   95 
   96 void draw() {
   97   
   98   int i = 0;
   99   int charnum = 0;
  100 
  101   delay(1000); // 1 second
  102   background(0);
  103   
  104   try { 
  105     
  106     String line = reader.readLine(); 
  107     
  108     if (line == null) { // eof
  109       noLoop();
  110       // mm.finish();
  111     } 
  112     else 
  113     {
  114       nocolon.draw(600,260);        
  115       for (i=0; i < line.length(); i++) {
  116         draw_letter(line.charAt(i),charnum++);
  117       }
  118     }
  119     
  120   }
  121   catch (IOException e) {
  122     println("I/O error: " + e.toString());
  123     e.printStackTrace();
  124   }
  125   // mm.addFrame();
  126 }
  127 
  128 
  129 // draw a single character on the screen at the specified position
  130 void draw_letter(char letter, int position) {
  131 
  132   // the next line finds the starting position for this char in our letter bitmap
  133   int i = (letter-97)*7;  
  134   int x = drawx+(position*210); // the x position of this character on the screen
  135   if (position > 1) x += 62;    // tweak the x position to account for the colon
  136   if (debug) print(letter + " (chr " + i + ") x=" + x + " y=" + drawy + " => ");
  137   
  138   draw_leg( boolean(lettermap[i+0]), 0, x, drawy );
  139   draw_leg( boolean(lettermap[i+1]), 1, x, drawy );
  140   draw_leg( boolean(lettermap[i+2]), 2, x, drawy );
  141   draw_leg( boolean(lettermap[i+3]), 3, x, drawy );
  142   draw_leg( boolean(lettermap[i+4]), 4, x, drawy );
  143   draw_leg( boolean(lettermap[i+5]), 5, x, drawy );
  144   draw_leg( boolean(lettermap[i+6]), 6, x, drawy );
  145 
  146   if (debug) println();
  147 } 
  148 
  149 
  150 // draw a single leg of a 7-segment character at the specified xy position
  151 void draw_leg(boolean on, int legnum, int x, int y)
  152 {
  153   if (on) {
  154     if (debug) print("1"); 
  155     leg[legnum].draw(x,y); 
  156   } else { 
  157     if (debug) print("0"); 
  158     noleg[legnum].draw(x,y);
  159   }
  160 }
  161 
  162 
  163 /*
  164 
  165 // Finish the movie early if space bar is pressed
  166 void keyPressed() {
  167   if (key == ' ') mm.finish();
  168 }
  169 
  170 */
  171