We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › arrays, mysql and text
Page Index Toggle Pages: 1
arrays, mysql and text (Read 127 times)
arrays, mysql and text
Mar 2nd, 2009, 8:50pm
 
hello

trying to make a sketch that will read info from a mysql database and display said data on the screen.

what i need it to do is to keep checking back to see if any new data has been added to the data base and then display the new info. i have a crude prototype working where i can read in the database and it displays it line by line (which it kind of does at the moment) just need it to auto update itself but wihtout showing the info that has already been on screen.

hope that makes sense

code as follows


bit of a hack job as i am still learning.

import de.bezier.mysql.*;
import processing.video.*;
MovieMaker mm;
String s = "";
String sCopy = s;
float xoff = 0.0f;
float w;
float h = 400;
float fpx = 40;
float fpy = 0;
int tempw;
int linePos = 100;


PVector[][] posizioni;
PVector origin;
ArrayList particles = new ArrayList();

MySQL msql;


void setup()
{
   size( 500, 500 );
  colorMode(HSB, 360, 100, 100, 100);
  PFont font = loadFont("Helvetica-Bold-48.vlw");
 textFont(font, 48);
 posizioni = new PVector[width][height];

   // this example assumes that you are running the
   // mysql server locally (on "localhost").
   //

   // replace --username--, --password-- with your mysql-account.
   //
   String user     = "daver";
   String pass     = "superhero";

   // name of the database to use
   //
   String database = "daver";

   // name of the table that will be created
   //
   String table    = "inbound";

   // connect to database of server "localhost"
   //
   msql = new MySQL( "xxxxxxxxxxxxx", database, user, pass, this );
   
   if ( msql.connect() )
   {  
     
       msql.query( "SELECT * FROM " + table );
       
       while (msql.next())
       {
           String s = msql.getString("message");
           int n = msql.getInt("id");
           println(s + "   " + n);
           draw(s);
           findScanArea(s);
           scan();
           
         
           
       }
       
       // need to find out how many rows there are in table?
       //
       msql.query( "SELECT COUNT(*) FROM " + table );
       msql.next();
       println( "number of rows: " + msql.getInt(1) );
       
       
   }
   else
   {
       // connection failed !
   }
}
void draw(String msg)
{
   background(1, 0, 100, 100);
  if ((linePos<= 100) || (linePos>=100)){
             linePos = linePos + 50;
           }
 
 fill(1, 100, 100, 1);
 text(msg, 40, linePos);
 fill(1, 100, 100, 0);
 text(msg, 40, linePos);

   for (int h = 0; h<particles.size()-1; h++){
     Particle prt = (Particle) particles.get(h);
     prt.run();

     PVector actualVel = prt.getVelocity();
     PVector attrito = PVector.mult(actualVel,-0.5);
     prt.add_force(attrito);

     PVector origLoc = prt.getOrigin();
     PVector diff = PVector.sub(origLoc,prt.getLocation());
     diff.normalize();
     diff.mult(0.30f);
     prt.setAcceleration(diff);
     if(prt.dead()){
       particles.remove(h);
     }
   }
}
   

void draw()
{
   background(1, 0, 100, 100);
if ((linePos<= 100) || (linePos>=100)){
             linePos = linePos + 150;
           }
 
 fill(1, 100, 100, 1);
 text(s, 40, linePos);
 fill(1, 100, 100, 0);
 text(sCopy, 40, linePos);

   for (int h = 0; h<particles.size()-1; h++){
     Particle prt = (Particle) particles.get(h);
     prt.run();

     PVector actualVel = prt.getVelocity();
     PVector attrito = PVector.mult(actualVel,-0.05);
     prt.add_force(attrito);

     PVector origLoc = prt.getOrigin();
     PVector diff = PVector.sub(origLoc,prt.getLocation());
     diff.normalize();
     diff.mult(0.30f);
     prt.setAcceleration(diff);
     if(prt.dead()){
       particles.remove(h);
     }
     
     /*if(mousePressed) {  
        PVector mouseLoc = new PVector(mouseX, mouseY, 0);
        PVector dif2 = PVector.sub(mouseLoc,prt.getLocation());
        dif2.normalize();
        dif2.mult(1.0f);
        prt.setAcceleration(dif2);
     }      
   }  

 //print(get(mouseX, mouseY) + " ");
 //mm.addFrame();
}*/
}
}

void findScanArea(String ss){
 w = width;
}




void scan(){
  for(int i=int(fpx); i<int(fpx+w); i++) {
   for(int j = int(fpy); j<int(fpy+h); j++) {
     if(get(i,j) == -258){

         posizioni[i][j] = new PVector(i,j,0);
         origin = new PVector(posizioni[i][j].x, 100 + posizioni[i][j].y, 0);
         PVector a = new PVector();
         PVector v = new PVector();
         PVector l = new PVector(random(width), random(height), 0);
         particles.add(new Particle(a,v,l, origin, random(0.5f, 1.0f)));
       
     }
   }
  }
}



//void keyPressed(){
//  if(s.length() <= 35){
//  s += key;
//  fpx += tempw;
//  sCopy = s.substring(s.length()-1);
//  tempw = int(textWidth(sCopy));
//  }
//  else {
//    s = "";
//    sCopy = s;
//    fpx = 40;
//    tempw = int(textWidth(sCopy));
//  }
//  if((key == DELETE) || (key == BACKSPACE))
//  {
//   mm.finish();
//  }              
//}
//void keyReleased(){
//  findScanArea(s);
//  scan();
//}
//






Page Index Toggle Pages: 1