| 1 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // Used to get and display the preview .png files for each project |
|---|
| 3 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 4 | class Pnger { |
|---|
| 5 | int vImID = -1; |
|---|
| 6 | PImage[] vIm ; |
|---|
| 7 | PImage[] aIm ; |
|---|
| 8 | PImage[] dIm ; |
|---|
| 9 | int type =2 ; |
|---|
| 10 | int curr =0 ; |
|---|
| 11 | String login ; |
|---|
| 12 | int pId ; |
|---|
| 13 | int[] tMax ; |
|---|
| 14 | int lastTime = 0; |
|---|
| 15 | |
|---|
| 16 | Pnger(int pid, String logi) { |
|---|
| 17 | pId = pid ; |
|---|
| 18 | login = logi ; |
|---|
| 19 | vIm = new PImage[MAXPNGER] ; |
|---|
| 20 | aIm = new PImage[MAXPNGER] ; |
|---|
| 21 | dIm = new PImage[MAXPNGER] ; |
|---|
| 22 | tMax = new int[3] ; |
|---|
| 23 | tMax[0]=tMax[1]=tMax[2]=0 ; |
|---|
| 24 | } |
|---|
| 25 | void loadImages() { |
|---|
| 26 | Client parent = getClient(pId) ; |
|---|
| 27 | int currTime = millis() ; |
|---|
| 28 | if ( (parent.connected && currTime-lastTime>1000*PNGLOADINTERVAL) || lastTime==0 ) { // not re-loading if already done recently (every PNGLOADINTERVAL) |
|---|
| 29 | lastTime = millis() ; |
|---|
| 30 | /* old image routine |
|---|
| 31 | int dlType = 0 ; |
|---|
| 32 | |
|---|
| 33 | int[] lMax = new int[3] ; |
|---|
| 34 | lMax[0]=lMax[1]=lMax[2]=0 ; |
|---|
| 35 | ///////// DL PNG LISTS : choosing what type to DL |
|---|
| 36 | for(int typ=0;typ<3;typ++) { |
|---|
| 37 | String pngs[] = loadStrings(previewFilesAddress+"/"+getTypeString(typ)+"/"+login+"/"+"list.txt"); |
|---|
| 38 | lMax[typ]=pngs.length ; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | ////////////// Choosing type |
|---|
| 42 | if(lMax[0]>lMax[1]) dlType=0 ; |
|---|
| 43 | else dlType=1; |
|---|
| 44 | if(lMax[0]==lMax[1]) dlType=0 ; |
|---|
| 45 | if(lMax[2]>lMax[dlType]) dlType=2 ; |
|---|
| 46 | if(lMax[2]==lMax[dlType] && (random(0,1)<0.9)) dlType=2 ; |
|---|
| 47 | |
|---|
| 48 | setType(dlType) ; |
|---|
| 49 | |
|---|
| 50 | tMax[0]=tMax[1]=tMax[2]=0 ; |
|---|
| 51 | ///////// DL PNGs |
|---|
| 52 | String dlPngs[] = loadStrings(previewFilesAddress+"/"+getTypeString(dlType)+"/"+login+"/"+"list.txt"); |
|---|
| 53 | for(int n=0;n<dlPngs.length;n++) { |
|---|
| 54 | try{ |
|---|
| 55 | String imPath = previewFilesAddress + dlPngs[n] ; |
|---|
| 56 | PImage im = loadImage(imPath); |
|---|
| 57 | if(im==null || im.width==-1) { |
|---|
| 58 | print("IMAGELOAD PROBLEM: "+login+" "+n+" "+imPath+"\n"); |
|---|
| 59 | } |
|---|
| 60 | else { |
|---|
| 61 | if(dlType==0) dIm[tMax[dlType]] = im; |
|---|
| 62 | if(dlType==1) aIm[tMax[dlType]] = im; |
|---|
| 63 | if(dlType==2) vIm[tMax[dlType]] = im; |
|---|
| 64 | tMax[dlType]+=1 ; |
|---|
| 65 | print("IMAGELOAD OK: "+login+" "+n+" "+imPath+"\n"); |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | catch(Exception e) { |
|---|
| 69 | print("IMAGELOAD EXCEPTION Problem : "+n+" "+login+"\n") ; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | print("LOADED "+tMax[dlType]+" images\n") ; |
|---|
| 73 | */ |
|---|
| 74 | try{ |
|---|
| 75 | // URL encode spaces |
|---|
| 76 | String lin = login.replace(' ','+'); |
|---|
| 77 | String imPath = previewFilesAddress + lin + ".png?timeout=500"; |
|---|
| 78 | if (vImID>=0) { |
|---|
| 79 | print("discarding prev image request: "+login+": "+vImID+"\n") ; |
|---|
| 80 | loader.delImage(vImID); |
|---|
| 81 | } |
|---|
| 82 | vImID = loader.loadImg(imPath); |
|---|
| 83 | print("loading image: "+login+": "+vImID+"\n") ; |
|---|
| 84 | //PImage im = loadImage(imPath); |
|---|
| 85 | //vIm[0] = im; |
|---|
| 86 | } |
|---|
| 87 | catch(Exception e) { |
|---|
| 88 | print("IMAGELOAD EXCEPTION Problem : "+login+"\n") ; |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | else { |
|---|
| 92 | print("LOADING images already done recently.. "+login+" .. not doing\n") ; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | void traceImage(float a, float b, float w, float h) { |
|---|
| 96 | if (vImID >=0) { |
|---|
| 97 | PImage tmpIm ; |
|---|
| 98 | tmpIm = loader.getImage(vImID); |
|---|
| 99 | if (tmpIm != null) { |
|---|
| 100 | print("Image ID: "+vImID+" loaded."); |
|---|
| 101 | loader.delImage(vImID); |
|---|
| 102 | vImID=-1; |
|---|
| 103 | vIm[curr]=tmpIm; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | if (vIm[curr] == null) return; |
|---|
| 107 | |
|---|
| 108 | try{ |
|---|
| 109 | if(type==0) image(dIm[curr], a, b, w, h); |
|---|
| 110 | if(type==1) image(aIm[curr], a, b, w, h); |
|---|
| 111 | if(type==2) image(vIm[curr], a, b, w, h); |
|---|
| 112 | } |
|---|
| 113 | catch(Exception e) { |
|---|
| 114 | //print("EXCEPTION Problem tracing image: "+login+" "+type+" "+curr+"\n") ; |
|---|
| 115 | print(".") ; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | void nextImage() { |
|---|
| 119 | curr++ ; |
|---|
| 120 | if(curr>=tMax[type]) curr=0 ; |
|---|
| 121 | } |
|---|
| 122 | void setType(int t) { |
|---|
| 123 | curr = 0 ; |
|---|
| 124 | type = t ; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | //////////////////////////////////////////////////////////// |
|---|
| 128 | //////////////////////////////////////////////////////////// |
|---|
| 129 | float dBetwTent = 20 ; |
|---|
| 130 | int NPARTS = 2 ; |
|---|
| 131 | class Tentac{ |
|---|
| 132 | Particle parent ; |
|---|
| 133 | Particle[] tends ; |
|---|
| 134 | int type ; |
|---|
| 135 | boolean isOut ; |
|---|
| 136 | |
|---|
| 137 | Tentac(Particle p, int k) { |
|---|
| 138 | parent=p ; |
|---|
| 139 | if(k<2) { |
|---|
| 140 | isOut=false ; |
|---|
| 141 | type=k ; |
|---|
| 142 | } |
|---|
| 143 | else { |
|---|
| 144 | isOut=true ; |
|---|
| 145 | type=k-3 ; |
|---|
| 146 | } |
|---|
| 147 | tends = new Particle[NPARTS] ; |
|---|
| 148 | for(int v=0;v<NPARTS;v++) { |
|---|
| 149 | float rr = dBetwTent*(v+1) ; |
|---|
| 150 | float posx = rr*cos(2*PI*k/6) ; |
|---|
| 151 | float posy = rr*sin(2*PI*k/6) ; |
|---|
| 152 | tends[v] = physics.makeParticle( 0.2, posx, posy, 0 ); |
|---|
| 153 | if(v==0) physics.makeSpring( parent, tends[v], 0.2, 1, dBetwTent ); |
|---|
| 154 | else physics.makeSpring( tends[v-1], tends[v], 0.2, 1, dBetwTent ); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | void trace() { |
|---|
| 158 | float px,py,pxb,pyb ; |
|---|
| 159 | for(int v=0;v<NPARTS;v++) { |
|---|
| 160 | if(v==0) { |
|---|
| 161 | pxb = parent.position().x() ; |
|---|
| 162 | pyb = parent.position().y() ; |
|---|
| 163 | } |
|---|
| 164 | else { |
|---|
| 165 | pxb = tends[v-1].position().x() ; |
|---|
| 166 | pyb = tends[v-1].position().y() ; |
|---|
| 167 | } |
|---|
| 168 | px = tends[v].position().x() ; |
|---|
| 169 | py = tends[v].position().y() ; |
|---|
| 170 | fill(getColorType(type)) ; |
|---|
| 171 | stroke(220) ; |
|---|
| 172 | line(px,py,pxb,pyb) ; |
|---|
| 173 | ellipse(px,py,7,7) ; |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | //////////////////////////////////////////////////////////// |
|---|
| 178 | //////////////////////////////////////////////////////////// |
|---|
| 179 | class TentacSimple { |
|---|
| 180 | Particle parent ; |
|---|
| 181 | int type ; |
|---|
| 182 | boolean isOut ; |
|---|
| 183 | int nn ; |
|---|
| 184 | |
|---|
| 185 | TentacSimple(Particle p, int k) { |
|---|
| 186 | nn=k ; |
|---|
| 187 | parent=p ; |
|---|
| 188 | if(k<=2) { |
|---|
| 189 | isOut=false ; |
|---|
| 190 | type=k ; |
|---|
| 191 | } |
|---|
| 192 | else { |
|---|
| 193 | isOut=true ; |
|---|
| 194 | type=k-3 ; |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | void trace() { |
|---|
| 198 | float px,py,pxb,pyb ; |
|---|
| 199 | pxb = parent.position().x() ; |
|---|
| 200 | pyb = parent.position().y() ; |
|---|
| 201 | px = pxb+dBetwTent*cos(2*PI/3+2*PI*nn/6) ; |
|---|
| 202 | py = pyb+dBetwTent*sin(2*PI/3+2*PI*nn/6) ; |
|---|
| 203 | fill(getColorType(type)) ; |
|---|
| 204 | stroke(getColorType(type)) ; |
|---|
| 205 | line(px,py,pxb,pyb) ; |
|---|
| 206 | if(isOut) { |
|---|
| 207 | drawTriangle(pxb,pyb,px,py,5) ; |
|---|
| 208 | } |
|---|
| 209 | else { |
|---|
| 210 | ellipse(px,py,7,7) ; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | //////////////////////////////////////////////////////////// |
|---|
| 215 | //////////////////////////////////////////////////////////// |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|