Está en la página 1de 6

import processing.serial.*; import TUIO.

*;//Importamos la librera de Reactivision Serial port; TuioProcessing tuioClient; // Diversas variables para pintar sobre el sketch float cursor_size = 15; float object_size = 60; float table_size = 760; float scale_factor = 1; PFont font; // Se asocia cada id de los patrones (amoebas) a una letra int letraBuscada=2;// Aqu va la letra a buscar void setup() { size(640,480); // Tamao del sketch noStroke(); fill(0); loop(); frameRate(30); // 30 fotogramas/segundo //noLoop(); hint(ENABLE_NATIVE_FONTS // Habilitamos las fuentes del sistema ); font =createFont("Arial", 18); scale_factor =height/table_size; // Creamos una instancia para el reconociemiento de patrones tuioClient =new TuioProcessing(this); } // Mtodo a dibujar las letras dependiendo del id de los patrones encontrados void draw() { background(255); textFont(font,18*scale_factor); float obj_size = object_size*scale_factor; float cur_size = cursor_size*scale_factor; Vector tuioObjectList = tuioClient.getTuioObjects(); for (int i=0;i<tuioObjectList.size();i++) { // Obtenemos la lista de los patrones (amoebas) a usar. TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i); stroke(255, 102, 0); stroke(0, 0, 0);

//Imprime en pantalla le letra H if(tobj.getSymbolID()==0){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,55,80,55); line(80,5,80,100); popMatrix(); } //Imprime en pantalla la letra E if(tobj.getSymbolID()==1){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,5,80,5); line(5,55,50,55); line(5,100,80,100); popMatrix(); } //Imprime en pantalla la letra N if(tobj.getSymbolID()==2){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,5,85,100); line(85,100,85,5); popMatrix(); } //Imprime en pantalla la letra T if(tobj.getSymbolID()==3){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(10,10,100,10); line(55,10,55,100); popMatrix(); } //Imprime en pantalla la letra W if(tobj.getSymbolID()==4){

strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(10,10,40,100); line(40,100,70,10); line(70,10,100,100); line(100,100,130,10); popMatrix(); } //Imprime en pantalla la letra A if(tobj.getSymbolID()==5){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,100,40,5); line(40,5,90,100); line(24,60,68,60); popMatrix(); } //Imprime en pantalla la letra X if(tobj.getSymbolID()==6){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,80,80); line(5,80,80,5); popMatrix(); } //Imprime en pantalla la letra F if(tobj.getSymbolID()==7){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,5,80,5); line(5,55,50,55); popMatrix(); } //Imprime en pantalla la letra I if(tobj.getSymbolID()==8){ strokeWeight(6); pushMatrix();

translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(80,5,5,5); line(50,90,50,5); line(5,90,80,90); popMatrix(); } //Imprime en pantalla la letra K if(tobj.getSymbolID()==9){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,50,80,5); line(5,50,80,100); popMatrix(); } //Imprime en pantalla la letra L if(tobj.getSymbolID()==10){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,5,100); line(5,100,60,100); popMatrix(); } //Imprime en pantalla la letra V if(tobj.getSymbolID()==11){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,50,100); line(50,100,100,5); popMatrix(); } //Imprime en pantalla la letra Y if(tobj.getSymbolID()==12){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(5,5,30,40); line(40,5,20,80);

popMatrix(); } //Imprime en pantalla la letra Z if(tobj.getSymbolID()==13){ strokeWeight(6); pushMatrix(); translate(tobj.getScreenX( width),tobj.getScreenY( height)); rotate(tobj.getAngle()); line(100,5,5,5); line(5,80,100,5); line(5,80,100,80); popMatrix(); } } // Todo el cdigo anterior es para pintar en pantalla el cursos cuando // el ratn es pasado sobre el sketch y tambin pinta las letras // obteniendo como delimitadores el tamao (ancho y alto) del sketch Vector tuioCursorList = tuioClient.getTuioCursors(); for (int i=0;i<tuioCursorList.size();i++) { TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i); Vector pointList = tcur.getPath();

if (pointList.size()>0) { stroke(0,0,255); TuioPoint start_point = (TuioPoint)pointList.firstElement();; for (int j=0;j<pointList.size();j++) { TuioPoint end_point = (TuioPoint)pointList.elementAt(j); line(start_point.getScreenX( width),start_point.getScreenY( height-100) end_point.getScreenX(width),end_point.getScreenY( height-100)); start_point = end_point; } stroke(192,192,192); fill(192,192,192); ellipse( tcur.getScreenX(width), tcur.getScreenY(height-100), cur_size,cur_size); fill(0); text(""+ tcur.getCursorID(), tcur.getScreenX(width)-5, tcur.getScreenY(height-100)+5); } } } // stos mtodos son llamados cuando un evento del reconociemiento // de patrones en tiempo real ocurre //ste mtodo es llamado cuando un objeto (amoeba) es agregado al sketch

void addTuioObject(TuioObject tobj) { if(tobj.getSymbolID()==letraBuscada)port.write( 'b'); println("add object "+tobj.getSymbolID()+ ("+tobj.getSessionID()+ "+ " ") tobj.getX()+" "+tobj.getY()+ "+tobj.getAngle()); " } // ste mtodo es llamado cuando un objeto (amoeba) desaparece del sketch void removeTuioObject(TuioObject tobj) { println("remove object " +tobj.getSymbolID()+ ("+tobj.getSessionID()+ " ")"); } // ste mtodo es llamado cuando un objeto (amoeba) se mueve dentro del skecth, // es decir, cuando se mueve se va actualizando su estado. void updateTuioObject (TuioObject tobj) { if(tobj.getSymbolID()==letraBuscada)port.write( 'b'); println("update object " +tobj.getSymbolID()+ ("+tobj.getSessionID()+ " " ") +tobj.getX()+" "+tobj.getY()+ "+tobj.getAngle() " +" "+tobj.getMotionSpeed()+ "+tobj.getRotationSpeed()+ "+ " " tobj.getMotionAccel()+" "+tobj.getRotationAccel()); } // ste mtodo es llamado cuando el cursor pasa sobre el sketch void addTuioCursor(TuioCursor tcur) { println("add cursor "+tcur.getCursorID()+ ("+tcur.getSessionID()+ ") " " +tcur.getX()+" "+tcur.getY()); } // ste mtodo es llamado cuando el cursor se mueve sobre del sketch, // es decir se actualiza su estado conforme se mueve sobre del sketch void updateTuioCursor (TuioCursor tcur) { println("update cursor " +tcur.getCursorID()+ ("+tcur.getSessionID()+ ") " " +tcur.getX()+" "+tcur.getY()+ "+tcur.getMotionSpeed()+ "+ " " tcur.getMotionAccel()); } // ste mtodo es llamado cuando el cursor desaparece del sketch, es decir // el cursor no se encuentra sobre el skecth void removeTuioCursor(TuioCursor tcur) { println("remove cursor " +tcur.getCursorID()+ ("+tcur.getSessionID()+ " ")"); } //ste mtodo es llamado al final de cada fotograma void refresh(TuioTime bundleTime) { redraw(); // Volvemos a repintar en el skecth }

También podría gustarte