Would like to create a "glass teletype" display

edited June 2015 in How To...

Another project for the battleship New Jersey museum ship is to have a monitor in the Radio Room displaying 'messages' and text which will keep scrolling up as each new line is displayed. We can put an LCD monitor where the old CRT is and it looks just right. Would like to be able to have a large text file in the DATA folder (stuff from old radio messages, etc) that would print continuously, and just loop around and start over at the end of the file.

What I'd like to do is have the letters of the text appear on the screen like being type by a teletype - or as though they were being typed by hand... and at the end of each line all the text moves up one line and the next line begins in the lower left corner.

Just getting started with Processing and can't seem to create the effect of a vertical scroll on a block of text... also need to get the letters to type across the screen... This doesn't seem like it should be too hard - just don't know all the in's and out's of processing yet!

Answers

  • Answer ✓

    Use as you see fit - credit me if you like!

    void setup() {
      size(600, 600);
      scroll = new Scroll("yourfile.txt");
    }
    
    void draw() {
      background(0);
      scroll.draw();
    }
    
    Scroll scroll;
    
    class Scroll {
      //String[] tex; // Use this line instead if loading from file.
      String[] tex = {
        "New orders: Turn ship six degrees starboard.", 
        "Captain Hanks reports a fire in the command room!", 
        "Lunch today is fish and chips... again.", 
        "First class cabins are closed for cleaning."
      };
      int which_line, letter_count;
      Scroll(String filename) {
        which_line = 0;
        letter_count = 0;
        //tex = loadStrings(filename); // Uncomment if loading from file.
      }  
      void draw() {
        fill(0, 255, 128);
        if (frameCount%5==0) {
          letter_count++;
        }
        if (letter_count > tex[which_line].length()) {
          which_line++;
          which_line%=tex.length;
          letter_count = 0;
        }
        text( tex[which_line].substring(0, letter_count), 20, height - 20);
        for( int i = 0; i*20 < (height-40); i++){
          int w = (which_line-1-i);
          while(w < 0) w+=tex.length; 
          text( tex[w] , 20, height - 40 - 20 * i );
        }
      }
    }
    
  • DUDE! A most awesome and helpful reply! Thanks so much - will def include all credits in the code. Is this a Class you wrote? It will also be a great reference - I've done some Classes in The Arduino - this will be great to compare and study.

  • edited June 2015 Answer ✓

    Rather than have the class loadStrings() itself, a much better option is pass an already loaded resource to its constructor. :-\"
    Also we can have an overloaded Scroll's constructor in order to have 1 that receives the loaded resource and another which simply uses its String[] tex field's default content: O:-)

    Scroll scroll;
    
    void setup() {
      size(600, 600, JAVA2D);
      smooth(4);
    
      scroll = new Scroll(); // gonna use constructor "Overload 1".
      //scroll = new Scroll( loadStrings("yourfile.txt") ); // "Overload 2".
    }
    
    void draw() {
      background(0);
      scroll.draw();
    }
    
    class Scroll {
      String[] tex = {
        "New orders: Turn ship six degrees starboard.", 
        "Captain Hanks reports a fire in the command room!", 
        "Lunch today is fish and chips... again.", 
        "First class cabins are closed for cleaning."
      };
    
      int which_line, letter_count;
    
      Scroll() { // Overload 1: uses default tex[].
      }
    
      Scroll(String... lines) { // Overload 2: reassigns tex[] w/ passed lines[].
        tex = lines;
      }
    
      // ...
    
    }
    
  • Thanks for that update...

  • Just a little update - have created a sketch with this code (including the overload) and it works flawlessly! Just what we needed. Huge thanks again!

Sign In or Register to comment.