import java.util.regex.*; String intxt[]; PFont font; Text txt; int index = 0; int margin = 60; // how much space is left at edges of screen, in pixels int bodyWidth; // set in setup() int lineHeight = 40; // default space between lines float spaceWidth; // set in setup() Gauge gauges[] = new Gauge[5]; // allocate new gauge objects // letters used to change gauges; index 0 is up, index 1 is down char gaugeID[][] = { { 'q', 'a' }, { 'w', 's' }, { 'e', 'd' }, { 'r', 'f' }, { 't', 'g' } }; void setup() { size(720, 600); frameRate(30); intxt = loadStrings("text"); txt = new Text(join(intxt, " ")); bodyWidth = width - (margin * 2); font = loadFont("Georgia-32.vlw"); textFont(font); spaceWidth = textWidth(" "); for (int i = 0; i < gauges.length; i++) { gauges[i] = new Gauge(); } } void draw() { background(255); textAlign(LEFT); textFont(font); int runningLength = 0; // keeps track of how many pixels' worth of words we've // drawn per line int currentLine = 0; //lineHeight = (int)(40 + (40 * gauges[3].get())); // randomize indices int[] indices = randRange(txt.tokens.size(), gauges[0].get()); // main word-drawing loop for (int i = 0; i < indices.length; i++) { fill(0); Token currToken = (Token)txt.tokens.get(indices[i]); String tokStr; // set tokStr to transformed word if currToken is a Word object; otherwise, // just get the string if (currToken instanceof Word) { Word currWord = (Word)currToken; tokStr = currWord.mixUpSparesOutside(gauges[1].get()) .replaceVowelsWithE(gauges[4].get()) .charsObliterated(gauges[3].get()) .toString(); } else { tokStr = currToken.toString(); } // get width from 32pt type textSize(32); float tokWidth = textWidth(currToken.toString()); // advance a line if the current line's length plus the width of the token // exceeds bodywidth if (runningLength + tokWidth > bodyWidth) { currentLine++; runningLength = 0; } // decrease text size for this token randomly /* if (gauges[3].get() > noise(indices[i] + currToken.toString().hashCode(), i)) { textSize(16); } */ // draw new token if random threshold is broken textAlign(CENTER); if (gauges[2].get() < noise(indices[i], currToken.toString().hashCode()+i)) { text(tokStr, margin + runningLength + tokWidth/2, margin + lineHeight * currentLine); } runningLength += tokWidth; // check to see if the next token is a word; if so, insert a space // FIXME - shouldn't advance after hyphens, etc. if (i < indices.length-1) { if (txt.tokens.get(indices[i+1]) instanceof Word) { runningLength += spaceWidth; } } } drawGauges(); } void keyPressed() { for (int i = 0; i < gaugeID.length; i++) { if (key == gaugeID[i][0]) { gauges[i].increment(); } else if (key == gaugeID[i][1]) { gauges[i].decrement(); } } } void drawGauges() { for (int i = 0; i < gauges.length; i++) { pushMatrix(); translate(margin+(i*(width-2*margin)/gauges.length), height-40); gauges[i].display(); popMatrix(); } }