front_idill/extern/fajran-tuiojs/examples/tracker.html
changeset 25 a7b0e40bcab0
equal deleted inserted replaced
24:2bdf5d51d434 25:a7b0e40bcab0
       
     1 <!DOCTYPE html>
       
     2 <html>
       
     3 <head><title>TUIO Client plugin test</title>
       
     4 <style type="text/css">
       
     5 body { margin: 0px; overflow: hidden; }
       
     6 </style>
       
     7 <script type="text/javascript" src="../src/tuio.js"></script>
       
     8 <script type="text/javascript" src="../connector/npTuioClient/tuiojs.npTuioClient.js"></script>
       
     9 <script type="text/javascript">
       
    10 
       
    11 var canvas;
       
    12 var ctx;
       
    13 var w = 0;
       
    14 var h = 0;
       
    15 
       
    16 var timer;
       
    17 var updateStarted = false;
       
    18 
       
    19 function updateCanvasSize() {
       
    20 	var nw = window.innerWidth;
       
    21 	var nh = window.innerHeight;
       
    22 
       
    23 	if ((w != nw) || (h != nh)) {
       
    24 		w = nw;
       
    25 		h = nh;
       
    26 		canvas.style.width = w+'px';
       
    27 		canvas.style.height = h+'px';
       
    28 		canvas.width = w;
       
    29 		canvas.height = h;
       
    30 	}
       
    31 }
       
    32 
       
    33 var colors = {};
       
    34 
       
    35 tuio.cursor_remove(function(data) {
       
    36 	delete colors[data.sid];
       
    37 });
       
    38 
       
    39 function update() {
       
    40 	if (updateStarted) return;
       
    41 	updateStarted = true;
       
    42 
       
    43 	ctx.clearRect(0, 0, w, h);
       
    44 
       
    45 	var i, len = tuio.cursors.length;
       
    46 	for (i=0; i<len; i++) {
       
    47 		var obj = tuio.cursors[i];
       
    48 		var x = obj.x;
       
    49 		var y = obj.y;
       
    50 		var px = x * w;
       
    51 		var py = y * h;
       
    52 
       
    53 		ctx.beginPath();
       
    54 		ctx.arc(px, py, 20, 0, 2*Math.PI, true);
       
    55 
       
    56 		var r, g, b;
       
    57 		if (colors[obj.sid] == undefined) {
       
    58 			r = parseInt(Math.random() * 255);
       
    59 			g = parseInt(Math.random() * 255);
       
    60 			b = parseInt(Math.random() * 255);
       
    61 			colors[obj.sid] = [r, g, b];
       
    62 		}
       
    63 
       
    64 		var c = colors[obj.sid];
       
    65 
       
    66 		ctx.fillStyle = "rgba("+c[0]+", "+c[1]+", "+c[2]+", 0.2)";
       
    67 		ctx.fill();
       
    68 
       
    69 		ctx.lineWidth = 5.0;
       
    70 		ctx.strokeStyle = "rgba(0, 0, 0, 0.7)";
       
    71 		ctx.stroke();
       
    72 	}
       
    73 
       
    74 	updateStarted = false;
       
    75 }
       
    76 
       
    77 function init() {
       
    78 	canvas = document.getElementById('canvas');
       
    79 	ctx = canvas.getContext('2d');
       
    80 	updateCanvasSize();
       
    81 	timer = setInterval(update, 15);
       
    82 	tuio.start();
       
    83 };
       
    84 
       
    85 </script>
       
    86 </head>
       
    87 <body onload="init()">
       
    88 	
       
    89 <canvas id="canvas" width="300" height="300" style="top:0px; left:0px; width: 300px; height: 300px;"></canvas>
       
    90 
       
    91 </body>
       
    92 </html>