Re: 10.24 Share some Code
Posted: Mon Nov 21, 2011 7:08 am
Here, I compare 'political' texts to 'revolutionary' texts checked out during the twelve month cycle during 2007. I added a bit of a propagandistic tint to the color, and a transparency to each of the layered bar graphs so that if one of the layers was beneath one another at any time, it would remain visible with slight color variation.
import de.bezier.data.sql.*;
MySQL msql;
void setup()
{
size( 600, 600 );
background(255, 10, 100);
String user = "mat259";
String pass = "V1sual1zat1on";
/*String [] monthLables = new String[12];
monthLables[0] = "Jan";
monthLables[1] = "Feb";
monthLables[2] = "Mar";
monthLables[3] = "Apr";
monthLables[4] = "May";
monthLables[5] = "Jun";
monthLables[6] = "Jul";
monthLables[7] = "Aug";
monthLables[8] = "Sep";
monthLables[9] = "Oct";
monthLables[10] = "Nov";
monthLables[11] = "Dec";*/
// regular way of defining an array
String [] monthLables = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)
String database = "spl_years";
msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );
if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%political%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );
int month2Count = 0;
while(msql.next()) {
int amonth = msql.getInt(1);
int count = msql.getInt(2);
fill(255, 455, 223 , 50);
stroke(0 ,50);
rect( month2Count * (width/12) , height , width /12 , count * -0.5);
println(count);
fill(255);
textAlign(CENTER);
text(monthLables[month2Count], 20+ month2Count * (width/12) , 550);
month2Count++;
}
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%revolutionary%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );
int month4Count = 0;
while(msql.next()) {
int amonth = msql.getInt(1);
int count = msql.getInt(2);
fill(255, 400, 300 , 50);
stroke(0 ,50);
rect( month4Count * (width/12) , height , width /12 , count * -0.5);
println(count);
fill(255);
textAlign(CENTER);
text(monthLables[month4Count], 20+ month4Count * (width/12) , 550);
month4Count++;
}
}
else
{
println( "Conection Failed!! ");
}
}
void draw()
{
}
import de.bezier.data.sql.*;
MySQL msql;
void setup()
{
size( 600, 600 );
background(255, 10, 100);
String user = "mat259";
String pass = "V1sual1zat1on";
/*String [] monthLables = new String[12];
monthLables[0] = "Jan";
monthLables[1] = "Feb";
monthLables[2] = "Mar";
monthLables[3] = "Apr";
monthLables[4] = "May";
monthLables[5] = "Jun";
monthLables[6] = "Jul";
monthLables[7] = "Aug";
monthLables[8] = "Sep";
monthLables[9] = "Oct";
monthLables[10] = "Nov";
monthLables[11] = "Dec";*/
// regular way of defining an array
String [] monthLables = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; // inline version of defining an array (same as above)
String database = "spl_years";
msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass );
if ( msql.connect() )
{
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%political%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );
int month2Count = 0;
while(msql.next()) {
int amonth = msql.getInt(1);
int count = msql.getInt(2);
fill(255, 455, 223 , 50);
stroke(0 ,50);
rect( month2Count * (width/12) , height , width /12 , count * -0.5);
println(count);
fill(255);
textAlign(CENTER);
text(monthLables[month2Count], 20+ month2Count * (width/12) , 550);
month2Count++;
}
msql.query( "select month(ckoutDateTime), count(*) from transactions2007 where title like '%revolutionary%' "+
"group by month(ckoutDateTime) order by month(ckoutDateTime)" );
int month4Count = 0;
while(msql.next()) {
int amonth = msql.getInt(1);
int count = msql.getInt(2);
fill(255, 400, 300 , 50);
stroke(0 ,50);
rect( month4Count * (width/12) , height , width /12 , count * -0.5);
println(count);
fill(255);
textAlign(CENTER);
text(monthLables[month4Count], 20+ month4Count * (width/12) , 550);
month4Count++;
}
}
else
{
println( "Conection Failed!! ");
}
}
void draw()
{
}