[HSS8123] – Rolling Alphabet/ code

Basic code from TUIO library, main conncet support from reacTIVISion app.

Code develop help from Tom and Xiyuan.
import TUIO.*;
import processing.sound.*;
TuioProcessing tuioClient;
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;
boolean verbose = false;
boolean callback = true;
///——–IMPORT IMAGES——–/////
PImage background;
PImage veraA;
PImage veraB;
PImage veraC;
PImage veraD;
PImage veraE;
PImage veraF;
PImage veraG;
PImage veraH;
PImage veraI;
PImage veraJ;
PImage veraK;
PImage veraL;
PImage veraM;
PImage veraN;
PImage veraO;
PImage veraP;
PImage veraQ;
PImage veraR;
PImage veraS;
PImage veraT;
PImage veraU;
PImage veraV;
PImage veraW;
PImage veraX;
PImage veraY;
PImage veraZ;
///——-IMPORT SOUND—-////
SoundFile veraAsound;
SoundFile veraBsound;
SoundFile veraCsound;
SoundFile veraDsound;
SoundFile veraEsound;
SoundFile veraFsound;
SoundFile veraGsound;
SoundFile veraHsound;
SoundFile veraIsound;
SoundFile veraJsound;
SoundFile veraKsound;
SoundFile veraLsound;
SoundFile veraMsound;
SoundFile veraNsound;
SoundFile veraOsound;
SoundFile veraPsound;
SoundFile veraQsound;
SoundFile veraRsound;
SoundFile veraSsound;
SoundFile veraTsound;
SoundFile veraUsound;
SoundFile veraVsound;
SoundFile veraWsound;
SoundFile veraXsound;
SoundFile veraYsound;
SoundFile veraZsound;
///——-SOUND SWITCHES—//////
boolean Asound = false;
boolean Bsound = false;
boolean Csound = false;
boolean Dsound = false;
boolean Esound = false;
boolean Fsound = false;
boolean Gsound = false;
boolean Hsound = false;
boolean Isound = false;
boolean Jsound = false;
boolean Ksound = false;
boolean Lsound = false;
boolean Msound = false;
boolean Nsound = false;
boolean Osound = false;
boolean Psound = false;
boolean Qsound = false;
boolean Rsound = false;
boolean Ssound = false;
boolean Tsound = false;

boolean Usound = false;
boolean Vsound = false;
boolean Wsound = false;

boolean Xsound = false;
boolean Ysound = false;
boolean Zsound = false;
float tobjNo = -1;
float symbolFoundThisTime = -1;
void setup()
{

noCursor();

size(displayWidth,displayHeight);
noStroke();
fill(0);

if (!callback) {
frameRate(60);
loop();
} else noLoop();

font = createFont(“Arial”, 18);
scale_factor = height/table_size;

tuioClient = new TuioProcessing(this);

////—–LOAD IMAGES——////
background = loadImage(“background.jpg”);
veraA = loadImage(“p1.jpg”);
veraB = loadImage(“p2.jpg”);
veraC = loadImage(“p3.jpg”);
veraD = loadImage(“p4.jpg”);
veraE = loadImage(“p5.jpg”);
veraF = loadImage(“p6.jpg”);
veraG = loadImage(“p7.jpg”);
veraH = loadImage(“p8.jpg”);
veraI = loadImage(“p9.jpg”);
veraJ = loadImage(“p10.jpg”);
veraK = loadImage(“p11.jpg”);
veraL = loadImage(“p12.jpg”);
veraM = loadImage(“p13.jpg”);
veraN = loadImage(“p14.jpg”);
veraO = loadImage(“p15.jpg”);
veraP = loadImage(“p16.jpg”);
veraQ = loadImage(“p17.jpg”);
veraR = loadImage(“p18.jpg”);
veraS = loadImage(“p19.jpg”);
veraT = loadImage(“p20.jpg”);
veraU = loadImage(“p21.jpg”);
veraV = loadImage(“p22.jpg”);
veraW = loadImage(“p23.jpg”);
veraX = loadImage(“p24.jpg”);
veraY = loadImage(“p25.jpg”);
veraZ = loadImage(“p26.jpg”);

///——LOAD SOUND—-/////
veraAsound = new SoundFile(this, “A.mp3”);
veraBsound = new SoundFile(this, “B.mp3”);
veraCsound = new SoundFile(this, “C.mp3”);
veraDsound = new SoundFile(this, “D.mp3”);

veraEsound = new SoundFile(this, “E.mp3”);
veraFsound = new SoundFile(this, “F.mp3”);
veraGsound = new SoundFile(this, “G.mp3”);
veraHsound = new SoundFile(this, “H.mp3”);
veraIsound = new SoundFile(this, “I.mp3”);
veraJsound = new SoundFile(this, “J.mp3”);
veraKsound = new SoundFile(this, “K.mp3”);
veraLsound = new SoundFile(this, “L.mp3”);
veraMsound = new SoundFile(this, “M.mp3”);
veraNsound = new SoundFile(this, “N.mp3”);
veraOsound = new SoundFile(this, “O.mp3”);
veraPsound = new SoundFile(this, “P.mp3”);
veraQsound = new SoundFile(this, “Q.mp3”);
veraRsound = new SoundFile(this, “R.mp3”);
veraSsound = new SoundFile(this, “S.mp3”);
veraTsound = new SoundFile(this, “T.mp3”);
veraUsound = new SoundFile(this, “U.mp3”);
veraVsound = new SoundFile(this, “V.mp3”);
veraWsound = new SoundFile(this, “W.mp3”);
veraXsound = new SoundFile(this, “X.mp3”);
veraYsound = new SoundFile(this, “Y.mp3”);
veraZsound = new SoundFile(this, “Z.mp3”);
}
void draw()
{
textFont(font,18*scale_factor);
float obj_size = object_size*scale_factor;
float cur_size = cursor_size*scale_factor;
ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
for (int i=0;i<tuioObjectList.size();i++) {
TuioObject tobj = tuioObjectList.get(i);
symbolFoundThisTime = tobj.getSymbolID();
}
println(symbolFoundThisTime);
if(symbolFoundThisTime == tobjNo){
}
else{
chooseAndStopSample(tobjNo);
chooseAndPlaySample(symbolFoundThisTime);
tobjNo = symbolFoundThisTime;
}
chooseAndDrawImage(symbolFoundThisTime);

}
void addTuioObject(TuioObject tobj) {
if (verbose) println(“add obj “+tobj.getSymbolID()+” (“+tobj.getSessionID()+”) “+tobj.getX()+” “+tobj.getY()+” “+tobj.getAngle());
}
void chooseAndDrawImage(float tobjNo){
if (tobjNo == -1){
image(background, 0,0,width,height);
}
else if(tobjNo == 0){
image(veraA, 0,0,width,height);
}
else if(tobjNo == 1){
image(veraB, 0,0,width,height);
}
}
void chooseAndPlaySample(float tobjNo){
if(tobjNo == 0){
image(veraA, 0,0,width,height);
veraAsound.play();
}
else if(tobjNo == 1){
image(veraB, 0,0,width,height);
veraBsound.play();
}
else if(tobjNo == 2){
image(veraC, 0,0,width,height);
veraCsound.play();
}
else if(tobjNo == 3){
image(veraD, 0,0,width,height);
veraDsound.play();
}
else if(tobjNo == 4){
image(veraE, 0,0,width,height);
veraEsound.play();
}
else if(tobjNo == 5){
image(veraF, 0,0,width,height);
veraFsound.play();
}

else if(tobjNo == 6){
image(veraG, 0,0,width,height);
veraGsound.play();
}
else if(tobjNo == 7){
image(veraH, 0,0,width,height);
veraHsound.play();
}
else if(tobjNo == 8){
image(veraI, 0,0,width,height);
veraIsound.play();
}
else if(tobjNo == 9){
image(veraJ, 0,0,width,height);
veraJsound.play();
}
else if(tobjNo == 10){
image(veraK, 0,0,width,height);
veraKsound.play();
}
else if(tobjNo == 11){
image(veraL, 0,0,width,height);
veraLsound.play();
}
else if(tobjNo == 12){
image(veraM, 0,0,width,height);
veraMsound.play();
}
else if(tobjNo == 13){
image(veraN, 0,0,width,height);
veraNsound.play();
}
else if(tobjNo == 14){
image(veraO, 0,0,width,height);
veraOsound.play();
}
else if(tobjNo == 15){
image(veraP, 0,0,width,height);
veraPsound.play();
}
else if(tobjNo == 16){
image(veraQ, 0,0,width,height);
veraQsound.play();
}

else if(tobjNo == 17){
image(veraR, 0,0,width,height);
veraRsound.play();
}
else if(tobjNo == 18){
image(veraS, 0,0,width,height);
veraSsound.play();
}
else if(tobjNo == 19){
image(veraT, 0,0,width,height);
veraTsound.play();
}
else if(tobjNo == 20){
image(veraU, 0,0,width,height);
veraUsound.play();
}
else if(tobjNo == 21){
image(veraV, 0,0,width,height);
veraVsound.play();
}
else if(tobjNo == 22){
image(veraW, 0,0,width,height);
veraWsound.play();
}

else if(tobjNo == 23){
image(veraX, 0,0,width,height);
veraXsound.play();
}

else if(tobjNo == 24){
image(veraY, 0,0,width,height);
veraYsound.play();
}
else if(tobjNo == 25){
image(veraZ, 0,0,width,height);
veraZsound.play();
}
}
void chooseAndStopSample(float tobjNo){
if(tobjNo == 0){
veraAsound.stop();////stops the file many times instead of once. how to solve?
}
else if(tobjNo == 1){
veraBsound.stop();
}
else if(tobjNo == 2){
veraCsound.stop();
}
else if(tobjNo == 3){
veraDsound.stop();
}
else if(tobjNo == 4){
veraEsound.stop();
}
else if(tobjNo == 5){
veraFsound.stop();
}
else if(tobjNo == 6){
veraGsound.stop();
}
else if(tobjNo == 7){
veraHsound.stop();
}
else if(tobjNo == 8){
veraIsound.stop();
}
else if(tobjNo == 9){
veraJsound.stop();
}
else if(tobjNo == 10){
veraKsound.stop();
}
else if(tobjNo == 11){
veraLsound.stop();
}
else if(tobjNo == 12){
veraMsound.stop();
}
else if(tobjNo == 13){
veraNsound.stop();
}
else if(tobjNo == 14){
veraOsound.stop();
}
else if(tobjNo == 15){
veraPsound.stop();
}
else if(tobjNo == 16){
veraQsound.stop();
}
else if(tobjNo == 17){
veraRsound.stop();
}
else if(tobjNo == 18){
veraSsound.stop();
}
else if(tobjNo == 19){
veraTsound.stop();
}
else if(tobjNo == 20){
veraUsound.stop();
}
else if(tobjNo == 21){
veraVsound.stop();
}
else if(tobjNo == 22){
veraWsound.stop();
}
else if(tobjNo == 23){
veraXsound.stop();
}
else if(tobjNo == 24){
veraYsound.stop();
}
else if(tobjNo == 25){
veraZsound.stop();
}
}
void updateTuioObject (TuioObject tobj) {
if (verbose) println(“set obj “+tobj.getSymbolID()+” (“+tobj.getSessionID()+”) “+tobj.getX()+” “+tobj.getY()+” “+tobj.getAngle()
+” “+tobj.getMotionSpeed()+” “+tobj.getRotationSpeed()+” “+tobj.getMotionAccel()+” “+tobj.getRotationAccel());
}
void removeTuioObject(TuioObject tobj) {
if (verbose) println(“del obj “+tobj.getSymbolID()+” (“+tobj.getSessionID()+”)”);
}
void addTuioCursor(TuioCursor tcur) {
if (verbose) println(“add cur “+tcur.getCursorID()+” (“+tcur.getSessionID()+ “) ” +tcur.getX()+” “+tcur.getY());
}
void updateTuioCursor (TuioCursor tcur) {
if (verbose) println(“set cur “+tcur.getCursorID()+” (“+tcur.getSessionID()+ “) ” +tcur.getX()+” “+tcur.getY()
+” “+tcur.getMotionSpeed()+” “+tcur.getMotionAccel());
}
void removeTuioCursor(TuioCursor tcur) {
if (verbose) println(“del cur “+tcur.getCursorID()+” (“+tcur.getSessionID()+”)”);
}
void addTuioBlob(TuioBlob tblb) {
if (verbose) println(“add blb “+tblb.getBlobID()+” (“+tblb.getSessionID()+”) “+tblb.getX()+” “+tblb.getY()+” “+tblb.getAngle()+” “+tblb.getWidth()+” “+tblb.getHeight()+” “+tblb.getArea());
}

void updateTuioBlob (TuioBlob tblb) {
if (verbose) println(“set blb “+tblb.getBlobID()+” (“+tblb.getSessionID()+”) “+tblb.getX()+” “+tblb.getY()+” “+tblb.getAngle()+” “+tblb.getWidth()+” “+tblb.getHeight()+” “+tblb.getArea()
+” “+tblb.getMotionSpeed()+” “+tblb.getRotationSpeed()+” “+tblb.getMotionAccel()+” “+tblb.getRotationAccel());
}
void removeTuioBlob(TuioBlob tblb) {
if (verbose) println(“del blb “+tblb.getBlobID()+” (“+tblb.getSessionID()+”)”);
}
void refresh(TuioTime frameTime) {
if (verbose) println(“frame #”+frameTime.getFrameID()+” (“+frameTime.getTotalMilliseconds()+”)”);
if (callback) redraw();
}

Comments are closed.