/** * Word brush * *

Elie Zananiri
* CART 253, Winter 2008

*/ PFont f; String[] textFile; // contents of external file split by word int textIndex = 0; // tracks the current location in the textFile array void setup() { size(400, 400); smooth(); frameRate(30); background(0); // load and set the font f = loadFont("Skia-48.vlw"); textFont(f, 12); // load the contents of the external file into the String array String[] linesFile = loadStrings("hamsters.txt"); // join the lines, placing a space between each entry String allText = join(linesFile, " "); // split the text every time there is a space textFile = split(allText, " "); fill(255); } void draw() { // keep the motor running } void mouseDragged() { sprayText(); } void keyPressed() { if (key == ' ') { // clear screen background(0); } } /* writes a word at the mouse position */ void sprayText() { text(textFile[textIndex], mouseX, mouseY); textIndex++; // if we reach the end of the array, reset index to the beginning if (textIndex >= textFile.length) { textIndex = 0; } }