import de.bezier.data.sql.*; MySQL msql; PFont font; // what table and what column to query in db // this determines what data is played back //String table = "reading"; //String column = "line"; //String table = "objects"; //String column = "name"; //String table = "script"; //String column = "line"; String table = "words"; String column = "word"; int minID; int maxID; // vars holding response most recent query String data= ""; int id=0; // timing int last=0; void setup() { // general graphics setup size( 1280, 720 ); background(0); smooth(); // Font and text drawing setup font = loadFont("HelveticaNeue-48.vlw"); textAlign(CENTER); textAlign(CENTER,CENTER); rectMode(CORNER); fill(255); textFont(font, 64); int randomseed = 0; randomSeed(randomseed); // this example assumes that you are running the // mysql server locally (on "localhost"). // // replace --username--, --password-- with your mysql-account. // String user = "bob"; String pass = "password"; // name of the database to use String database = "naming"; // connect to database of server "localhost" msql = new MySQL( this, "localhost", database, user, pass ); if ( msql.connect() ) { msql.query( "SELECT MIN(id) FROM " + table ); msql.next(); minID=msql.getInt(1); println( "min row ID: " + minID ); msql.query( "SELECT MAX(id) FROM " + table ); msql.next(); maxID=msql.getInt(1); println( "max row ID: " + maxID ); } else { // connection failed ! println("connection failed!"); exit(); } } void draw() { background(0); // new query every 1000 ms if(millis()-last>2500) { // get a number for a random row int rand_row = int(random(minID, maxID)); println(rand_row); // select data from that random row msql.query("SELECT * FROM "+table+" WHERE id>= "+rand_row+" ORDER BY id LIMIT 1"); while(msql.next()) { data = msql.getString(column); id = msql.getInt("id"); //println(data + " " + id); } last=millis(); } fill(map(millis()-last, 0, 1000, 0, 192)); textFont(font, 64); text(data, 0, 0, width, height);//width/2, 200); fill(map(millis()-last, 0, 1000, 0, 128)); textFont(font, 16); text(id, width/2, height*.6666); }