root/InOutExpositor/dLink.pde

Revision e4e203671406cf05793d8bdd3f90000f29767307, 8.8 kB (checked in by Robin Gareus <robin@…>, 2 years ago)

fixed monitoring.. (load previews)

  • Property mode set to 100644
Line 
1////////////////////////////////////////////////////////////
2// Links drawing utilities
3////////////////////////////////////////////////////////////
4void initTrajet()
5{
6  background(0) ;
7  liveExplorator = new Explorator( getSelected(), 0, 0 ) ;
8}
9void traceTrajet()
10{
11  liveExplorator.exploreOutLive() ;
12  liveExplorator.runLive() ;
13
14  //print("Showing Flux ( "+ tL.size() +" )\n") ;
15  if( liveExplorator.oL.size()>1000 ) {
16    displayTrajet = false ;
17    clearBackground = true ;
18  }
19}
20////////////////////////////////////////////////////////////
21////////////////////////////////////////////////////////
22void drawOutLinkTriangle( Client A )
23{
24  Vector outCopins = getOutLinkedClients(A) ;
25  Client copin ;
26  int nb = 0 ;
27  if(A.connected) {
28    stroke(50,130) ;
29    fill(50,130) ;
30  }
31  else {
32    stroke(50,90) ;
33    fill(50,90) ;
34  }
35
36  int n = int(A.out[0].on) + int(A.out[1].on) + int(A.out[2].on) ;
37  ellipse(A.x(),A.y(),2*15*n,2*15*n) ;
38
39  for(int i=0;i<outCopins.size();i++) {
40    nb = 0 ;
41    copin = (Client)outCopins.elementAt(i) ;
42    if(showType[0] && drawnState.isLink(0,A.id,copin.id)) nb++ ;
43    if(showType[1] && drawnState.isLink(1,A.id,copin.id)) nb++ ;
44    if(showType[2] && drawnState.isLink(2,A.id,copin.id)) nb++ ;
45    drawClientsTriangle(A,copin,nb) ;
46  }
47}
48void drawClientsTriangle( Client A, Client B, int nb )
49{
50  float larg = 2+nb*15;
51  float ang = (float)getLinkAngle(A,B)+PI/2 ;
52  arc(A.x(),A.y(),2*larg,2*larg,ang,ang+PI) ;
53  drawTriangle(A.x(),A.y(),B.x(),B.y(),larg) ;
54}
55void drawTriangle(float a, float b, float c, float d, float larg) {
56  float ang = (float)getPointsAngle(a,b,c,d)+PI/2;
57  beginShape(TRIANGLES);
58  vertex(c,d) ;
59  vertex(a+larg*cos(ang), b+larg*sin(ang)) ;
60  vertex(a-larg*cos(ang), b-larg*sin(ang)) ;
61  vertex(c,d) ;
62  endShape() ;
63}
64////////////////////////////////////////////////////////////////////////////
65void drawArrowLine(float x1, float y1, float x2, float y2)
66{
67  float x = (0.7*x1+0.3*x2) ;
68  float y = (0.7*y1+0.3*y2) ;
69  line(x1,y1,x,y) ;
70}
71////////////////////////////////////////////////////////////////////////////
72void drawSimpleLine( Client A, Client B, int type) {
73  stroke(getColorType(type)) ;
74  float decal = 0 ;
75  float beg = 1.7 ;
76  float pas = 1.2 ;
77  if(type==0) decal = beg  ;
78  if(type==1) decal = beg + pas ;
79  if(type==2) decal = beg + 2*pas ;
80  float a = (float)getLinkAngle(A,B)+PI/2 ;
81  line(A.x()+ decal*cos(a),A.y()+ decal*sin(a),B.x()+ decal*cos(a),B.y()+ decal*sin(a)) ;
82}
83////////////////////////////////////////////////////////////////////////////
84void drawOrientedSimpleLine( Client A, Client B, int type) {
85  int nSegm = 2+int(2*distance(A,B)/10.0) ;
86  float maxWidth = 11.2 ;
87  float sw,xa,ya,xb,yb ;
88  float opac ;
89  for(int k=0;k<nSegm;k++) {
90    sw = 0.5 + maxWidth - k*maxWidth/(nSegm-1) ;
91    strokeWeight(sw) ;
92    opac = 255 - 255*k/(nSegm-1) ;
93    stroke(getColorType(type),opac) ;
94    xa = lerp(A.x(), B.x(), k/(float)nSegm);
95    ya = lerp(A.y(), B.y(), k/(float)nSegm);
96    xb = lerp(A.x(), B.x(), (k+1)/(float)nSegm);
97    yb = lerp(A.y(), B.y(), (k+1)/(float)nSegm);
98    line(xa,ya,xb,yb) ;
99  }
100  strokeWeight(1) ;
101}
102////////////////////////////////////////////////////////////////////////////////
103////////////////////////////////////////////////////////////////////////////////
104void drawSimpleDottedLine(float x1, float y1, float x2, float y2) {
105  float dd = sqrt(pow(x1-x2,2)+pow(y1-y2,2)) ;
106  int n = int(dd/3.0) ;
107  stroke(190,130) ;
108  for(int k=0; k<=n; k=k+2) {
109    //alph = 150-(float)k*255/(float)n ;
110    //sw = 3.5-(float)k*2/(float)n ;
111    //strokeWeight(sw) ;
112    //stroke(hu, sat , lum, alph) ;
113    float xa = lerp(x1, x2, k/(float)n);
114    float ya = lerp(y1, y2, k/(float)n);
115    float xb = lerp(x1, x2, (k+1)/(float)n);
116    float yb = lerp(y1, y2, (k+1)/(float)n);
117    line(xa, ya, xb, yb);
118  }
119}
120void drawSimpleDottedLineOp(float x1, float y1, float x2, float y2, float op) {
121  float dd = sqrt(pow(x1-x2,2)+pow(y1-y2,2)) ;
122  int n = int(dd/3.0) ;
123  stroke(190,op) ;
124  for(int k=0; k<=n; k=k+2) {
125    //alph = 150-(float)k*255/(float)n ;
126    //sw = 3.5-(float)k*2/(float)n ;
127    //strokeWeight(sw) ;
128    //stroke(hu, sat , lum, alph) ;
129    float xa = lerp(x1, x2, k/(float)n);
130    float ya = lerp(y1, y2, k/(float)n);
131    float xb = lerp(x1, x2, (k+1)/(float)n);
132    float yb = lerp(y1, y2, (k+1)/(float)n);
133    line(xa, ya, xb, yb);
134  }
135}
136////////////////////////////////////////
137void drawOrientedDottedLine(Client A, Client B, int type) // A -----------> B
138{
139  float decal = 4 ;
140  float a = (float)getLinkAngle(A,B)+PI/2.0 ;
141  float x1 = A.x() + decal*cos((float)a) ;
142  float y1 = A.y() + decal*sin((float)a) ;
143  float x2 = B.x() + decal*cos((float)a) ;
144  float y2 = B.y() + decal*sin((float)a) ;
145  drawDottedLine(x1, y1, x2, y2, type) ;
146}
147////////////////////////////////////////////////////////////////////////////
148float dPointFROM = 15 ;
149float dPointTO = 25 ;
150float dPoint = dPointFROM ;
151void drawDottedLine(float x1, float y1, float x2, float y2, int type)
152{
153  dPoint += 0.1 ;
154  if(dPoint>dPointTO) dPoint=dPointFROM ;
155
156  float dd = sqrt(pow(x1-x2,2)+pow(y1-y2,2)) ;
157  int n = floor(dd*7/((float)dPoint));
158  int from = 0 ;
159
160  float hu = 0 ;
161  float sat = 200 ;
162  float lum = 200;
163  float alph ;
164  float sw = 1 ;
165
166  if(type==2) { // VIDEO
167    hu = hue(getColorType(2)) ;
168  }
169  if(type==1) { // AUDIO
170    hu = hue(getColorType(1));
171    from=from+1;
172  }
173  if(type==0) { // DATA
174    lum = 255 ;
175    sat = 0 ;
176    from=from+2;
177    hu = hue(getColorType(0)) ;
178  }
179  colorMode(HSB);
180  for(int k=from; k<=n; k=k+3) {
181    alph = 200-(float)k*200/(float)n ;
182    sw = 5.5-(float)k*2/(float)n ;
183    strokeWeight(sw) ;
184    stroke(hu, sat , lum, alph) ;
185    float xa = (float)lerp(x1, x2, (float)k/(float)n);
186    float ya = (float)lerp(y1, y2, (float)k/(float)n);
187    float xb = (float)lerp(x1, x2, (float)(k+1)/(float)n);
188    float yb = (float)lerp(y1, y2, (float)(k+1)/(float)n);
189    line((float)xa, (float)ya, (float)xb, (float)yb);
190  }
191  strokeWeight(1) ;
192  colorMode(RGB);
193}
194////////////////////////////////////////////////////////////////////////////
195// For live sun beam links traject
196void traceTrajetLinkFlux( float x1, float y1, float x2, float y2, float t)
197{
198  //float x = x2*t + x1*(1-t) ;
199  //float y = y2*t + y1*(1-t) ;
200  //ellipse(x,y,3,3) ;
201
202  for(int k=-3;k<3;k=k+2) {
203    float t1 = t+k*0.02-0.02 ;
204    float t2 = t+k*0.02 ;
205    float ax = x2*t1 + x1*(1-t1) ;
206    float ay = y2*t1 + y1*(1-t1) ;
207    float bx = x2*t2 + x1*(1-t2) ;
208    float by = y2*t2 + y1*(1-t2) ;
209    if(t1>=0 && t2<=1) line(ax,ay,bx,by) ;
210  }
211}
212////////////////////////////////////////////////////////////////////////////
213void drawArcLink(Client A, Client B, boolean curv, int type)
214{
215  Client temp ;
216  if(curv) {
217    temp=A ;
218    A=B ;
219    B=temp ;
220  }
221  float ax = A.x() ;
222  float ay = A.y() ;
223  float bx = B.x() ;
224  float by = B.y() ;
225
226  float sina = sin(A.angle) ;
227  float cosa = cos(A.angle) ;
228  float sinb = sin(B.angle+PI) ;
229  float cosb = cos(B.angle+PI) ;
230
231  float ddst = sqrt(pow(ax-bx,2) + pow(ay-by,2)) ;
232  float d = ddst*2 ;
233
234  float u = clientBoxL/3 ;
235  float v = d ;
236  if(!curv) { v= 4.4*d/(sqrt(1+d));}
237
238  noFill() ;
239  stroke(getColorType(type),190) ;
240  strokeWeight(2.1) ;
241  if(curv) {
242    //curve(ax+v*cosa, ay+v*sina, ax-u*cosa, ay-u*sina, bx-u*cosb, by-u*sinb, bx+v*cosb, by+v*sinb) ;
243    float ix1,iy1,ix2,iy2,t1,t2,sw,alph ;
244    int steps = 5+int(distance(A,B)/3) ;
245    float macSW = 14.5 ;
246    for(int i=0;i<steps;i=i+1) { //+3
247      t1 = i/float(steps);
248      t2 = (i+1)/float(steps);
249      alph = 255-(float)(i+1)*255/(float)steps ;
250      sw = 0.5+ macSW-(float)(i+1)*macSW/(float)(steps) ;
251      strokeWeight(sw+1) ;
252      stroke(getColorType(type), alph) ;
253      ix1 = curvePoint(ax+v*cosa, ax-u*cosa, bx-u*cosb, bx+v*cosb, t1);
254      iy1 = curvePoint(ay+v*sina, ay-u*sina, by-u*sinb, by+v*sinb, t1);
255      ix2 = curvePoint(ax+v*cosa, ax-u*cosa, bx-u*cosb, bx+v*cosb, t2);
256      iy2 = curvePoint(ay+v*sina, ay-u*sina, by-u*sinb, by+v*sinb, t2);
257      line(ix1,iy1,ix2,iy2) ;
258    }
259  }
260  else bezier(ax+u*cosa, ay+u*sina, ax+v*cosa, ay+v*sina, bx+v*cosb, by+v*sinb, bx+u*cosb, by+u*sinb) ;
261  strokeWeight(1) ;
262}
263////////////////////////////////////////////
264void drawHalfCircle(Client A, Client B, float y, int type )  // A ------> B
265{
266  stroke(getColorType(type),120) ;
267
268  float x1 = A.x() ;
269  float x2 = B.x() ;
270  float an=0 ;
271  float r = abs(x1-x2)/2 ;
272  if(x1<x2) an=PI;
273  float nMorc = 2 + int(abs(x1-x2)/5.0);
274  float a,b,c,d ;
275  float o = (x1+x2)/2 ;
276  c=0 ;
277  d=0 ;
278  //// strokeweight
279  float sw ;
280  float maxWeight = 7 ;
281
282  for(int i=0;i<nMorc-1;i++) {
283    a = o + r*cos(an+(i*PI/nMorc)) ;
284    b = y + r*sin(an+(i*PI/nMorc)) ;
285    c = o + r*cos(an+((i+1)*PI/nMorc)) ;
286    d = y + r*sin(an+((i+1)*PI/nMorc)) ;
287    sw = 0.3 + maxWeight - i*maxWeight/(nMorc-2) ;
288    strokeWeight(sw) ;
289    line(a,b,c,d) ;
290  }
291  line(c,d,x2,y) ;
292  strokeWeight(1) ;
293}
294/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
295
296
297
298
299
Note: See TracBrowser for help on using the browser.