stefanino
YaBB Newbies
Offline
Posts: 2
Re: drawing on a video like on a upper layer
Reply #1 - Aug 12th , 2009, 8:25am
/** * * prototipo 0.5 * visualizza 1 video * scrive il valore bpm ricevuto (1) * sovrappone un rettangolo (2) con un effetto "bump" * disegna grafico (in bianco) tipo polar * invia ad arduino comando per ON striscia di led * */ import processing.net.*; import processing.video.*; import processing.serial.*; // Network connection Client c; // movie player Movie myMovie; // The serial port: Serial myPort; String input; int data[]; int area=3; float x[] = new float[area]; float y[] = new float[area]; float w[] = new float[area]; float h[] = new float[area]; float x00=0.; float y00=200; float xx=0.; float yy=0.; float x0=0.; float y0=0.; float incY=1.; float facY=1.5; float orgX=0.; float orgY=-60.; boolean sent = false; boolean flip = false; int bpm = 0; float mill = 0; float bump = 0; float btime= 0; float bleng= 0; int sizeX = 320 + 5 + 5; // 450; int sizeY = 240 + 10 + 10; // 255; //int sizeX=160; //int sizeY=120; void setup() { size(sizeX, sizeY, P2D); background(204); // //myMovie = new Movie(this, "station.mov"); myMovie = new Movie(this, "sfondo_cuore.mov"); myMovie.loop(); float hex=255; float alpha=128; tint(hex, alpha); // // non posso usare background con un movie //background(myMovie); // stroke(0); frameRate(16); // Slow it down a little // Connect to the server's IP address and port c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port // List all the available serial ports: println(Serial.list()); /* nx133 (windows: marco) [0] "COM1" [1] "COM4" [2] "COM7" */ int nP = 2; int speed=9600; myPort = new Serial(this, Serial.list()[nP], speed); PFont font; //String Tpath = "C:/a/processing-1.0.5/examples/Basics/Typography/Letters/data"; String Tfont = "CourierNew36.vlw"; font = loadFont(Tfont); textFont(font); x[0]=05; y[0]=40; w[0]=160; h[0]= -35; // bpm= x[1]=05; y[1]=100; w[1]=160; h[1]= -35; // bump color x[2]=50; y[2]=100; w[2]=110; h[2]= -35; // bump color if(false) { image(myMovie, 05, 10); } } void movieEvent(Movie myMovie) { myMovie.read(); } void draw() { mill = millis(); // if(false) { // sposta image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2); } if(true) { image(myMovie, 05, 10); } // if ( (mill - bump) <= btime ) { sent = false; } if ( (mill - bump) > btime ) { // a new bump here bump = mill; // memo this time-instant if( flip) { fill(128); } else { stroke(255); fill(64); } rect(x[1],y[1],w[1],h[1]); flip = !flip; if( flip) { fill(128+64); } else { fill(256+64); } fill(0); if (true) if(!sent) { sent = true; // Send a capital A out the serial port: myPort.write(65); } } if (false) if ( (mill - bump) > bleng ) { // a new bump here //bump = mill; // memo this time-instant if( flip) { fill(128+64); } else { stroke(255); fill(32); } rect(x[2],y[2],w[2],h[2]); if( flip) { fill(128+64); } else { fill(256+64); } fill(0); } if (mousePressed == true) { // Draw our line stroke(255); line(pmouseX, pmouseY, mouseX, mouseY); // Send mouse coords to other person c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n"); } // Receive data from server if (c.available() > 0) { input = c.readString(); int nl = input.indexOf("\n"); if(nl>=0) { input = input.substring(0, nl); // Only up to the newline data = int(split(input, ' ')); // Split values into an array bpm = data[0]; btime = (60./bpm)*1000.; // bump-time = time-length of a hearth bump bleng = btime/5.; // bump length if(true) { // Draw line using received coords stroke(255); // line(data[0], data[1], data[2], data[3]); xx = x00 + (xx +orgX) + incY; yy = y00 - (data[0]+orgY) * facY; if(xx > x0) line(x0,y0, xx,yy); x0=xx; y0=yy; if(x0 >sizeX) { background(204); stroke(0); x0=0; xx=0; } } if(true) { stroke(192); rect(x[0],y[0]+6,w[0],h[0]); fill(128); text("bpm="+bpm, x[0],y[0],0); fill(255); } if (true) { // display bpm rect(x[0],y[0]+6,w[0],h[0]); fill(128); text("bpm="+bpm, x[0],y[0],0); fill(255); } } // if(nl>=0) } // if (c.available() > 0) }