// dream journal // by jeff watson // 29 january 2009 import rita.*; import ddf.minim.*; // fire it up Minim minim; AudioSample kick; AudioSample lock; AudioSample water; int FRAGMENT = 20; int PARAGRAPH = 60; int WORD = 10; float bg = 255; PImage b; RiText rts[]; RiMarkov markov; // movement-related stuff boolean movingUp; RiText rts1[] = new RiText[16]; void setup() { size(380, 500); smooth(); background(bg); // the keyPressed thing crashes the program unless there's some // markov-generated text already onscreen, so i took out this title card: // new RiText(this, "D R E A M J R N L", 133, (height/2)-24); // new RiText(this, "move / click / type", 135, (height/2)+24); RiText.setDefaultAlignment(LEFT); // start minim, load samples with buffer minim = new Minim(this); kick = minim.loadSample("BD.mp3", 2048); lock = minim.loadSample("lock.mp3", 2048); water = minim.loadSample("water.mp3", 2048); // n=3 seems to work best for the text parser thing (markov)...no idea why markov = new RiMarkov(this, 3); // load some text files into the markov magic machine markov.loadFile("dream1.txt"); markov.loadFile("dream2.txt"); // click the mouse (so that there's some text onscreen in case // a key is pressed) mouseClicked(); } void draw() { background(bg); } // generate text and sound on mouse move void mouseMoved() { float r = random(200)+54; float g = random(200)+54; float b = random(200)+54; float x = random(235)+20; float y = random(300)+30; background(r,g,b); // clear rita text RiText.deleteAll(); String[] lines = markov.generateSentences(1); // prints the text rts = RiText.createLines(this, lines, x, y, FRAGMENT); kick.trigger(); } // generate a different type of text and a new sound on click void mouseClicked() { // clear it again RiText.deleteAll(); String[] lines = markov.generateSentences(10); rts = RiText.createLines(this, lines, 24, 80, PARAGRAPH); water.trigger(); } void keyPressed() { float x = random(235)+40; float y = random(300)+30; // weird movement hackzz movingUp = !movingUp; for (int i = 0; i < rts.length; i++) { float xPos = random(14)+24; float yPos = random(420)+24; if (rts[i] == null) rts[i] = new RiText(this,(char)(i+65)+"", xPos, yPos); rts[i].setMotionType(i); rts[i].moveTo(xPos, yPos, 0.5); } lock.trigger(); } void stop() { kick.close(); minim.stop(); super.stop(); }