front_processing/src/Interaction_examples/Hand_signal/Hand_signal.pde
changeset 8 e4e7db2435f8
child 9 0f44b7360c8d
equal deleted inserted replaced
7:8a21bec5d45f 8:e4e7db2435f8
       
     1 /*
       
     2 * This file is part of the TraKERS\Front Processing package.
       
     3 *
       
     4 * (c) IRI <http://www.iri.centrepompidou.fr/>
       
     5 *
       
     6 * For the full copyright and license information, please view the LICENSE_FRONT
       
     7 * file that was distributed with this source code.
       
     8 */
       
     9 
       
    10 /*Exemple tiré de processing.org*/
       
    11 
       
    12 import TUIO.*;
       
    13 TuioProcessing tuioClient;
       
    14 int port = 80;
       
    15 //Taille de la fenêtre
       
    16 int WIDTH = 640, HEIGHT = 480;
       
    17 
       
    18 float minDistHands = 1, maxDistHands = 1.5;
       
    19 //Distance de "click" minimum/maximum avec la main.
       
    20 float minClickHand = minDistHands+0.2, maxClickHand = maxDistHands-0.2;
       
    21 //Définit les coordonnées de la main la plus proche et si elle a cliqué (se trouve dans une certaine zone du champ d'intéraction).
       
    22 int X, Y;
       
    23 boolean clicked;
       
    24 
       
    25 int[] xvals;
       
    26 int[] yvals;
       
    27 int[] bvals;
       
    28 
       
    29 void setup() 
       
    30 {
       
    31   size(WIDTH, HEIGHT);
       
    32   tuioClient = new TuioProcessing(this, port);
       
    33   xvals = new int[width];
       
    34   yvals = new int[width];
       
    35   bvals = new int[width];
       
    36 }
       
    37 
       
    38 int arrayindex = 0;
       
    39 
       
    40 void draw()
       
    41 {
       
    42   tuioInput();
       
    43   background(102);
       
    44   
       
    45   for(int i=1; i<width; i++) { 
       
    46     xvals[i-1] = xvals[i]; 
       
    47     yvals[i-1] = yvals[i];
       
    48     bvals[i-1] = bvals[i];
       
    49   } 
       
    50   // Add the new values to the end of the array 
       
    51   xvals[width-1] = X; 
       
    52   yvals[width-1] = Y;
       
    53   if(clicked) {
       
    54     bvals[width-1] = 0;
       
    55   } else {
       
    56     bvals[width-1] = 255;
       
    57   }
       
    58   
       
    59   fill(255);
       
    60   noStroke();
       
    61   rect(0, height/3, width, height/3+1);
       
    62 
       
    63   for(int i=1; i<width; i++) {
       
    64     stroke(255);
       
    65     point(i, xvals[i]/3);
       
    66     stroke(0);
       
    67     point(i, height/3+yvals[i]/3);
       
    68     stroke(255);
       
    69     line(i, 2*height/3+bvals[i]/3, i, (2*height/3+bvals[i-1]/3));
       
    70   }
       
    71 }
       
    72 
       
    73 /*MET A JOUR X et Y
       
    74 Entrée : Les positions d'un point 2D
       
    75 Sortie : Met à jour X et Y et si la main a "clické"*/
       
    76 void update(int x, int y, boolean click)
       
    77 {
       
    78   X = x;
       
    79   Y = y;
       
    80   clicked = click;
       
    81 }