/** * Letters. * * Draws letters to the screen. This requires loading a font, * setting the font, and then drawing the letters. */ PFont fontA; int offset=0; int i=0; int j=0; int NUMCHARS=4; int INCREMENT=3; int letter_width=250; String lines[] = { "" }; void setup() { size(800, 600); background(255); smooth(); // Load the font. Fonts must be placed within the data // directory of your sketch. A font must first be created // using the 'Create Font...' option in the Tools menu. // Uncomment the following two lines to see the available fonts //String[] fontList = PFont.list(); //println(fontList); textAlign(LEFT); fontA = createFont("Helvetica-Bold", 255); fill(0); textFont(fontA, 600); loadText("/Users/rtwomey/script/script.txt"); //textMode(SCREEN); i=0; offset=0; } void draw() { background(255); fill(0); text(lines[j].substring(i, i+NUMCHARS), offset, 500); offset-=INCREMENT; if(offset<-1*int(textWidth(lines[j].charAt(i)))) { offset=0; i+=1; }; if(i>lines[j].length()-NUMCHARS) { findNextLine(); i=0; }; } void loadText(String filename) { //String lines[] = loadStrings("two stroke engine2.txt"); //String lines[] = loadStrings("script.txt"); //String lines[] = loadStrings("SCIP.txt"); lines = loadStrings(filename); if(lines != null){ println("there are " + lines.length + " lines:"); } else { println("error, no text in file "+filename+". exiting."); exit(); }; // zero our line counter j=0; // look for first line of 4 or more characters findNextLine(); } void findNextLine() { // find the next line with 4 or more characters j++; while (lines[j].length() < 4) { if(j>=lines.length) { println("error, no lines in file with 4 or more characters. exiting."); exit(); }; j++; }; println(j+" of "+lines.length); };