root/InOutExpositor/oExpl.pde

Revision 5972babe7c40454704b75ea69ba2e12d80927eaa, 7.9 kB (checked in by Robin Gareus <robin@…>, 3 years ago)

fixed expositor to compile w/processing-1.0.9

  • Property mode set to 100644
Line 
1///////////////////////////////////////////////////////////////////////////////////////////////////////
2class Pt {
3  float x,y ;
4  Pt(float _x, float _y) {
5    x = _x ;
6    y = _y ;
7  } 
8}
9Pt getEllipsePosition( float depth, float ang ) {
10  Pt res = new Pt( width/2 + ellipseA*depth*cos( ang ), centerY + ellipseB*depth*sin( ang ) ) ;
11  return res ;
12}
13///////////////////////////////////////////////////////////////////////////////////////////////////////
14//// Arborescence with provenance et destination (avec exhibition minimale distance)
15class Branche { // Link A -------> B
16  Client A,B ;
17  boolean realA, realB ;
18  float aAng, bAng ; // avec l'angle et le depth, on connait la position
19  int depth ;
20  int type ;
21
22  ///////////////// For live tracing
23  float tgv = 0.5 ;
24  float t ;
25  boolean end,killed ;
26  Branche(Client _A, Client _B, int d, int intyp) {
27    A = _A ;
28    B = _B ;
29    depth = d ;
30    type = intyp ;
31    //////
32    realA = true ;
33    realB = true ;
34    aAng = 0 ;
35    bAng = 0 ;
36    ////// for live tracing
37    t = 0 ;
38    end = false ;
39    killed = false ;
40  }
41  void updateIfRealClientPositions() {
42    // only t‚àö‚Ñ¢te
43    if(realB) {
44      print("...moving "+B.name+"\n") ;
45      B.moveTo( getEllipsePosition(depth,bAng).x, getEllipsePosition(depth,bAng).y ) ;
46    }
47  }
48  void traceLink() {
49    float opp = 50-depth*3.5 ;
50    stroke(getColorType(type),opp) ;
51    float a,b,na,nb ;
52    if(realA) {
53      a = A.x() ;
54      b = A.y() ;
55    }
56    else {
57      a = getEllipsePosition(depth-1,aAng).x ;
58      b = getEllipsePosition(depth-1,aAng).y ;
59    }
60    if(realB) {
61      na = B.x() ;
62      nb = B.y() ;
63    }
64    else {
65      na = getEllipsePosition(depth,bAng).x ;
66      nb = getEllipsePosition(depth,bAng).y ;     
67    }
68    if(!realA || !realB) drawSimpleDottedLineOp(a,b,na,nb, opp) ;
69    if(!realA) A.traceClientCloneAt(a,b, opp) ;
70    if(!realB) B.traceClientCloneAt(na,nb, opp) ;
71    //text("P:"+depth,a,b) ;
72    //text("P:"+(depth),na,nb) ;
73  }
74  void traceLinkWithColor( int op ) {
75    noFill() ;
76    stroke(getColorType(type),op);
77    line(A.x(),A.y(),B.x(),B.y()) ;
78    strokeWeight(2) ;
79    ellipse(A.x(), A.y(), 11, 11) ;
80    ellipse(B.x(), B.y(), 11, 11) ;
81    strokeWeight(1) ;
82  }
83  void traceLive() {
84    float dd = sqrt(pow(A.x()-B.x(),2) + pow(A.y()-B.y(),2)) ;
85    t+=20.0*tgv/dd ;
86    stroke(getColorType(type),100) ;
87    traceTrajetLinkFlux(A.x(), A.y(), B.x(), B.y(),t) ;
88    if(t>=1) end = true ;
89  }
90}
91
92////////////////////////////////////////////////////////////
93////////////////////////////////////////////////////////////
94////////////////////////////////////////////////////////////
95////////////////////////////////////////////////////////////
96class Explorator { // for a Client A, got the in & out trajects (branches en profondeur)
97  Client A ;
98  Vector oL ;
99
100  int depIn = explDepthMAX ;
101  int depOut = explDepthMAX ;
102  Vector inBranches, outBranches ; // Vecteur des branches par profondeur
103  Vector inCells, outCells ;        // contient les CLient touchees par le CLient
104
105  Explorator( Client _A, int iD, int oD ) {
106    A = _A ;
107    depIn = iD ;
108    depOut = oD ;
109
110    ///////////////////// INIT exploration
111    for(int i=0;i<nClients;i++) ((Client)getClient(i)).toBeCloned = false ;
112
113    if(showEllipses) {
114      Pt rPt ;
115      for(int i=0;i<nClients;i++) {
116        float cLune = shiftANG-PI/2 ;
117        rPt = getEllipsePosition(random(4.1,4.9), random(cLune-PI/4,cLune+PI/4) ) ;
118        ((Client)getClient(i)).moveTo(rPt.x,rPt.y);
119        A.moveTo( width/2, centerY ) ;
120      }
121    }
122    A.toBeCloned = true ;
123
124    inBranches = new Vector() ;
125    outBranches = new Vector() ;
126    Vector firstCol = new Vector() ;
127    Branche sourceBranche = new Branche(A,A,0,0) ;
128    firstCol.addElement( sourceBranche ) ;
129    inBranches.addElement( firstCol ) ;
130    outBranches.addElement( firstCol ) ;
131
132    //////////////// STart !
133    explore( false ) ; // explore IN
134    explore( true ) ; // explore OUT
135
136    //////// For live sun beam traject links [sic]
137    oL = new Vector() ;
138    oL.addElement( new Branche(A,A,0,0) ) ;
139  }
140  ///////////////////////////
141  ///////////////////////////
142  void trace( boolean isOut ) {
143    int maxOd ;
144    Vector col ;
145    if(isOut) {
146      maxOd = min(outDepth,depOut) ;
147    }
148    else {
149      maxOd = min(inDepth,depIn) ;
150    }
151
152    for(int u=0;u<=maxOd;u++) {
153      if(isOut) col = (Vector)outBranches.elementAt(u) ;
154      else col = (Vector)inBranches.elementAt(u) ;
155
156      for(int v=0;v<col.size();v++) {
157        Branche br = (Branche)col.elementAt(v) ;
158        //int op = int(200-200*u/(maxOd+3.0)) ;
159        //br.traceLinkWithColor( op ) ;
160        br.traceLink() ;
161      }
162    }
163  }
164  ///////////////////////////
165  void explore( boolean isOut ) {
166    //print("---------------------- Explore  :"+A.name+"\n") ;
167
168    ////////// parcours
169    int prof = 0 ;
170    Vector oldCol ;
171    boolean encore = true ;
172
173    int dept = depIn ;
174    if(isOut) dept = depOut ;
175
176    while( prof<dept && encore ) {
177      //print("New profondeur-------------------: "+prof+"\n") ;
178      encore = false ;
179      Vector newCol = new Vector() ;
180      oldCol = new Vector() ;
181
182      if(isOut) oldCol = (Vector)outBranches.elementAt(prof) ;
183      else oldCol = (Vector)inBranches.elementAt(prof) ;
184
185      int NinDepth = oldCol.size() ;
186      for(int u=0;u<NinDepth;u++) { // For all Clients of a Depth
187
188        Branche fromBranche = (Branche)oldCol.elementAt(u) ;
189        Client from = fromBranche.B ;
190
191        Vector lCopins ;
192
193        // get out linked clients of each
194        if(isOut) lCopins = getOutLinkedClients( from ) ;
195        else lCopins = getInLinkedClients( from ) ;
196
197        // for all linked clients, add a Branche
198        int nbSuivants = lCopins.size() ;
199        for(int v=0;v<nbSuivants;v++) {
200          Client to = (Client)lCopins.elementAt(v) ;
201
202          int t = 0 ;
203          Branche newBr = new Branche(from,to,prof+1,t) ;
204
205          newBr.realB = !to.toBeCloned ;
206          to.toBeCloned = true ;
207
208          newBr.realA = fromBranche.realB ;
209          newBr.aAng = fromBranche.bAng ;
210
211          if(prof==0) {
212            if(!isOut) fromBranche.bAng = shiftANG+PI ;
213            else fromBranche.bAng = shiftANG ;
214          }
215          if(nbSuivants==1) newBr.bAng = fromBranche.bAng ;
216          else newBr.bAng = fromBranche.bAng + (openANG)*(float)v/(nbSuivants-1) - openANG/2 ;
217         
218          float divz = 100.3 ; // 15
219          newBr.bAng += random(-PI/divz,PI/divz) ;
220         
221          if(showEllipses) {
222            //////// moving POSITION of real Clients
223            newBr.updateIfRealClientPositions() ;
224          }
225          //print("Adding branche "+v+" from "+nbSuivants+" :("+prof+" :::: "+newBr.A.name+" to "+newBr.B.name+"\n") ;
226          //print("Reality: "+newBr.realA+" to "+newBr.realB+"\n") ;
227
228          newCol.addElement( newBr ) ;
229          encore = true ;
230        }
231      }
232
233      if(isOut) outBranches.addElement( newCol ) ;
234      else inBranches.addElement( newCol ) ;
235
236      prof++ ;
237    }
238    if(isOut) depOut = prof-1 ;
239    else depIn = prof-1 ;
240  }
241  ///////////////////////////
242  void runLive() {
243    stroke(210,20,20,20) ;
244    for(int i=oL.size()-1;i>=0;i--) {
245      Branche l = (Branche)oL.elementAt(i) ;
246      if( !l.killed )
247        l.traceLive() ;
248      else oL.removeElement(l) ;
249    }
250  }
251  ///////////////////////////
252  void exploreOutLive() {
253    int tS = oL.size() ;
254    for(int i=0;i<tS;i++) { // pour tous les link
255      Branche l = (Branche)oL.elementAt(i) ;
256      if( !l.killed && l.end ) { // live link finished (on est arrive a une cellule)
257        l.killed = true ;
258        for(int t=0;t<3;t++) {
259          Client endc = l.B ;
260          for(int j=0;j<nClients;j++) { // dans toutes les cellules
261            if( drawnState.isLink(t,endc.id,j) ) { // si lien endId -----> autre (j)
262              oL.addElement( new Branche(endc,getClient(j),0,t) );
263            }
264          }
265        }
266      }
267    }
268  }
269  ///////////////////////////
270}
271////////////////////////////////////////////////////////////
272////////////////////////////////////////////////////////////
273
274
275
276
Note: See TracBrowser for help on using the browser.