|
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 // smoke2 by Glen Murphy. |
|
11 // View the applet in use at http://bodytag.org/ |
|
12 // Code has not been optimised, and will run fairly slowly. |
|
13 |
|
14 import TUIO.*; |
|
15 TuioProcessing tuioClient; |
|
16 |
|
17 int realWidth = 640, realHeight = 480-200; |
|
18 int WIDTH = 300; |
|
19 int HEIGHT = 300; |
|
20 |
|
21 //Port du Client TUIO. |
|
22 int port = 80; |
|
23 //Limites de la zone de recherche pour les mains. |
|
24 float minDistHands = 1; |
|
25 float maxDistHands = 1.5; |
|
26 |
|
27 int RES = 2; |
|
28 int PENSIZE = 30; |
|
29 |
|
30 int lwidth = WIDTH/RES; |
|
31 int lheight = HEIGHT/RES; |
|
32 int PNUM = 30000; |
|
33 vsquare[][] v = new vsquare[lwidth+1][lheight+1]; |
|
34 vbuffer[][] vbuf = new vbuffer[lwidth+1][lheight+1]; |
|
35 |
|
36 TuioPoint pt1, pt2, precPt1, precPt2; |
|
37 |
|
38 particle[] p = new particle[PNUM]; |
|
39 int pcount = 0; |
|
40 int mouse1Xvel = 0; |
|
41 int mouse1Yvel = 0; |
|
42 int mouse2Xvel = 0; |
|
43 int mouse2Yvel = 0; |
|
44 |
|
45 int randomGust = 0; |
|
46 int randomGustMax; |
|
47 float randomGustX; |
|
48 float randomGustY; |
|
49 float randomGustSize; |
|
50 float randomGustXvel; |
|
51 float randomGustYvel; |
|
52 |
|
53 void setup() { |
|
54 size(WIDTH,HEIGHT); |
|
55 tuioClient = new TuioProcessing(this, port); |
|
56 background(#cccccc); |
|
57 noStroke(); |
|
58 for(int i = 0; i < PNUM; i++) { |
|
59 p[i] = new particle(random(WIDTH/2-20,WIDTH/2+20),random(HEIGHT-20,HEIGHT)); |
|
60 } |
|
61 for(int i = 0; i <= lwidth; i++) { |
|
62 for(int u = 0; u <= lheight; u++) { |
|
63 v[i][u] = new vsquare(i*RES,u*RES); |
|
64 vbuf[i][u] = new vbuffer(i*RES,u*RES); |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 void draw() { |
|
70 tuioInput(); |
|
71 |
|
72 int a1xvel = 0, a1yvel = 0, a2xvel = 0, a2yvel = 0; |
|
73 if(precPt1 != null && pt1 != null) |
|
74 { |
|
75 float X1Rev = map(pt1.getX(), realWidth, realHeight, WIDTH, HEIGHT); |
|
76 float Y1Rev = map(pt1.getY(), realWidth, realHeight, WIDTH, HEIGHT); |
|
77 float X1PrecRev = map(precPt1.getX(), realWidth, realHeight, WIDTH, HEIGHT); |
|
78 float Y1PrecRev = map(precPt1.getY(), realWidth, realHeight, WIDTH, HEIGHT); |
|
79 a1xvel = (int)X1Rev-(int)X1PrecRev; |
|
80 a1yvel = (int)Y1Rev-(int)Y1PrecRev; |
|
81 mouse1Xvel = (a1xvel != mouse1Xvel) ? a1xvel : 0; |
|
82 mouse1Yvel = (a1yvel != mouse1Yvel) ? a1yvel : 0; |
|
83 } |
|
84 if(precPt2 != null && pt2 != null) |
|
85 { |
|
86 float X2Rev = map(pt2.getX(), realWidth, realHeight, WIDTH, HEIGHT); |
|
87 float Y2Rev = map(pt2.getY(), realWidth, realHeight, WIDTH, HEIGHT); |
|
88 float X2PrecRev = map(precPt2.getX(), realWidth, realHeight, WIDTH, HEIGHT); |
|
89 float Y2PrecRev = map(precPt2.getY(), realWidth, realHeight, WIDTH, HEIGHT); |
|
90 a2xvel = (int)X2Rev-(int)X2PrecRev; |
|
91 a2yvel = (int)Y2Rev-(int)Y2PrecRev; |
|
92 mouse2Xvel = (a2xvel != mouse2Xvel) ? a2xvel : 0; |
|
93 mouse2Yvel = (a2yvel != mouse2Yvel) ? a2yvel : 0; |
|
94 } |
|
95 |
|
96 if(randomGust <= 0) { |
|
97 if(random(0,10)<1) { |
|
98 randomGustMax = (int)random(5,12); |
|
99 randomGust = randomGustMax; |
|
100 randomGustX = random(0,WIDTH); |
|
101 randomGustY = random(0,HEIGHT-10); |
|
102 randomGustSize = random(0,50); |
|
103 if(randomGustX > WIDTH/2) randomGustXvel = random(-8,0); |
|
104 else randomGustXvel = random(0,8); |
|
105 randomGustYvel = random(-2,1); |
|
106 } |
|
107 randomGust--; |
|
108 } |
|
109 |
|
110 for(int i = 0; i < lwidth; i++) { |
|
111 for(int u = 0; u < lheight; u++) { |
|
112 vbuf[i][u].updatebuf(i,u); |
|
113 v[i][u].col = 0; |
|
114 } |
|
115 } |
|
116 for(int i = 0; i < PNUM-1; i++) { |
|
117 p[i].updatepos(); |
|
118 } |
|
119 for(int i = 0; i < lwidth; i++) { |
|
120 for(int u = 0; u < lheight; u++) { |
|
121 v[i][u].addbuffer(i, u); |
|
122 v[i][u].updatevels(mouse1Xvel, mouse1Yvel, pt1); |
|
123 if(pt2 != null) |
|
124 v[i][u].updatevels(mouse2Xvel, mouse2Yvel, pt2); |
|
125 v[i][u].display(i, u); |
|
126 } |
|
127 } |
|
128 randomGust = 0; |
|
129 } |
|
130 |
|
131 void update(TuioPoint _pt1, TuioPoint _pt2) |
|
132 { |
|
133 pt1 = _pt1; |
|
134 pt2 = _pt2; |
|
135 } |