import ddf.minim.*; import rita.*; /* * @desc Displays lines one character at a time with sound. */ String s = "This is a typewriter typing a line."; int idx; RiText rt; RiSample key, bell; void setup() { size(400,400); RiText.createDefaultFont("arial", 24); rt = new RiText(this, s.charAt(idx++), 20, 30); key = RiTa.loadSample(this, "key.wav"); bell = RiTa.loadSample(this, "bell.wav"); RiTa.setCallbackTimer(this, "keytimer", .1f); } void onRiTaEvent(RiTaEvent re) { rt.setText(s.substring(0, idx)); if (idx++ == s.length()) { // start a new line RiTa.resetCallbackTimer(this, "keytimer", .5f, .1f); float nextY = rt.y + 30; rt = new RiText(this,"", 20, nextY); bell.play(); idx = 0; } else if (!rt.getText().endsWith(" ")) key.play(); } void draw() { background(255); }