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 & HelpPrograms › Guys I need ur help urgently
Page Index Toggle Pages: 1
Guys I need ur help urgently (Read 1143 times)
Guys I need ur help urgently
Feb 2nd, 2010, 4:20pm
 
Guy, I am working on a final semester project and I have few problems with my application, I was asked to design a game that teaches Kids shapes and colours, I have written codes to identify these shapes and some colors but I cant get around the next stage where I am supposed to place an image and have it stick on the interface, those coordinates are driving me nuts, e.g Place "triangle red" where there you see triangle red

this is my code below:

 import ddf.minim.*;
 import TUIO.*;
 TuioProcessing tuioClient;

 float obj_size = 100;
 int txtSize=12;

 PFont font;
 PImage bkgrnd,bkgrndbottom;
 public int choice=0;
 int id;
 
 HashMap symbols=new HashMap();
 Minim minim,playletter;
 AudioPlayer  ap,groove;
String objects[]={"triangle","rectangle","circle","ecclipse","star"};
 String colors[]= {"red","blue","green","yellow"};
 boolean played[]=new boolean[20];
 

 void setup()
 {

 bkgrnd=loadImage("bkgrnd.jpg");
 bkgrndbottom=loadImage("bkgrndbottom.gif");
 for (int i=0;i <20; i++)
  played[i]=false;
 minim = new Minim(this);
/* bd = minim.loadFile("tr.mp3", 12000);
 snare = minim.loadFile("tb.mp3", 12000);
 bass =  minim.loadFile("tg.mp3", 11000);
 cym = minim.loadFile("ty.mp3", 12000);
 intro = minim.loadFile("inero.mp3", 12000);
 cha = minim.loadFile("sr.mp3", 12000);
 ma = minim.loadFile("sb.mp3", 12000);
 re = minim.loadFile("sg.mp3", 12000);
 ge = minim.loadFile("sy.mp3", 12000);
 gh = minim.loadFile("cr.mp3", 12000);
 ju = minim.loadFile("cb.mp3", 12000);
 inm = minim.loadFile("cg.mp3", 12000);
 ur = minim.loadFile("cy.mp3", 12000);
 mss = minim.loadFile("errmsg.mp3", 12000);*/
 
 //intro.play();
 groove = minim.loadFile("backmusic.mp3" , 10000);
 groove.play();
 groove.loop();  
 
 size(1000,700);
 noStroke();
 font = createFont("Arial", txtSize);
 textFont(font,txtSize);
 tuioClient  = new TuioProcessing(this);
}


void drawshape(int i)
{
  if (i==0)
         triangle(30, 75, 58, 20, 86, 75);
  else if (i==1)    
          rect(30, 20, 100, 100);
 
}

void fillcolor(int i)
{
  if (i==0)
       fill(237, 28, 36);  
  else if (i==1)    
      fill(46, 49, 146);
  else if (i==2)
         fill(0, 166, 81);
  else if (i==3)
      fill(255, 242, 0);    
 
}
void draw()
{
 
 TuioObject[] tuioObjectList = sortObjs(tuioClient.getTuioObjects());
 
 background(1);
 image(bkgrndbottom,0,630);
image(bkgrnd,0,0);
 
 for (int i=0;i<tuioObjectList.length;i++) {
    TuioObject tobj = tuioObjectList[i];
     id = tobj.getSymbolID();
     fill(255);
      stroke(0);
      fill(192,168,225);
     
     
      String currentcolor=colors[id%4];
      String currentObject=objects[id/4];
     
      pushMatrix();
      translate(tobj.getScreenX(width),tobj.getScreenY(height));
      textSize(25);
       fillcolor(id%4);        
      drawshape(id/4);
      //text (currentObject.charAt(0)+""+currentcolor.charAt(0)+ ".mp3",400,400);
      if (played[id]==false)
      {
          playletter = new  Minim (this);
         ap = playletter.loadFile(currentObject.charAt(0)+""+currentcolor.charAt(0) + ".mp3", 12000);  
         ap.play();  
          playletter.stop();
          played[id]=true;
      }
     
      text ("shape" + currentObject + "Colour" + currentcolor ,-100,100);
      popMatrix();
     
       
 
 }  
}

TuioObject [] sortObjs(Vector objs){
 /* Sort the objects in order of their X position - left-most first */
 TuioObject [] newObjs = new TuioObject [objs.size()];
 int numObjs =objs.size();
 float prevX=-1;
 TuioObject o;
 for (int i =0; i<numObjs; i++){
   float minX = width;
   for (int j =0; j<numObjs; j++){
     TuioObject x=(TuioObject)objs.elementAt(j);
     if (x.getX()<minX && x.getX()>prevX){
       minX=x.getX();
       newObjs[i]=x;
     }
   }
   prevX=minX;
 }
 return newObjs;
}

// these callback methods are called whenever a TUIO event occurs

// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {

}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {

}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
}

// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
}

// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) {
 //redraw();
}
Re: Guys I need ur help urgently
Reply #1 - Feb 3rd, 2010, 4:34am
 
Asking questions at the wrong place (Exhibition instead of one section of Programming Questions & Help) won't help you to get quickly your answers.
Repeating the questions in private mails won't help more.

As I wrote, I don't even know what the TUIO library does, so I fear I can't help much.
Re: Guys I need ur help urgently
Reply #2 - Feb 3rd, 2010, 9:54am
 
The TUIO stuff is for touchscreen inputs.
TUIO programs are a pain in the behind for people without a touchscreen to debug/help with.  Undecided

Maybe I should write some code to fake touchscreen input so that us common mouse users can help... Hmmm...

Re: Guys I need ur help urgently
Reply #3 - Feb 3rd, 2010, 10:12am
 
PhiLho  wrote on Feb 3rd, 2010, 4:34am:
Asking questions at the wrong place (Exhibition instead of one section of Programming Questions & Help) won't help you to get quickly your answers.
Repeating the questions in private mails won't help more.

As I wrote, I don't even know what the TUIO library does, so I fear I can't help much.

ditto!
Re: Guys I need ur help urgently
Reply #4 - Feb 3rd, 2010, 10:32am
 
I wrote some TUIO code for Firefox/Mozilla Lily and Processing.js, and python... you've defined the methods to handle touch events, but you don't do anything with the data.... those functions are blank. It has to add and remove that data from the object you are re-instantiating on  each frame (which is also wrong, that variable should not be reinitialized)....


so... that sort of a lot of work, but for each of those events you have to decide what is the data coming in (like it would be id,x,y ) and what to do with it it...  like add it to tuioObjectList if it is a new ID, or remove it from tuioObjectList if the finger has been removed from the screen. But make sure tuioObjectList is outside of the loop.

Best of luck!!! That is the good part of TUIO, once you've mastered that, you've got it all.
Re: Guys I need ur help urgently
Reply #5 - Feb 3rd, 2010, 10:52am
 
well, actually on another look, I'm not so sure, it seems like the TUIOClient is perhaps keeping the state internal? I guess I haven't mess with this specific library... maybe you can describe what it does actually do at this point and what you want it to do instead?
Page Index Toggle Pages: 1