Revision 508f22b5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java | ||
---|---|---|
44 | 44 |
public static final int DIM_3DXY = 2; |
45 | 45 |
public static final int DIM_3DXZ = 3; |
46 | 46 |
|
47 |
private static final int NUM_POINTS = 400;
|
|
48 |
private static final int MAX_VECTORS= 6;
|
|
47 |
private static final int NUM_POINTS = 250;
|
|
48 |
private static final int MAX_POINTS = 6;
|
|
49 | 49 |
|
50 | 50 |
private static final Object lock = new Object(); |
51 | 51 |
|
... | ... | |
58 | 58 |
private static int mDuration; |
59 | 59 |
private static int mPosition; |
60 | 60 |
private static float mNoise0, mNoise1, mNoise2; |
61 |
|
|
62 |
private static int currentDim; |
|
61 |
|
|
62 |
private static int mSize1, mSize2, mSizeT, mAvg; |
|
63 |
|
|
64 |
private static int currentDim= DIM_2D; |
|
63 | 65 |
|
64 | 66 |
private static Static1D p1D; |
65 | 67 |
private static Static2D p2D; |
... | ... | |
81 | 83 |
mPaint.setStyle(Style.FILL); |
82 | 84 |
mPaint.setAntiAlias(true); |
83 | 85 |
|
84 |
currentDim= DIM_2D; |
|
85 | 86 |
moving = -1; |
86 | 87 |
mDuration = 10000; |
87 | 88 |
mPosition = 0; |
... | ... | |
113 | 114 |
} |
114 | 115 |
} |
115 | 116 |
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
public static void onSurfaceChanged(int width,int height) |
|
120 |
{ |
|
121 |
mAvg = (width+height)/2; |
|
122 |
|
|
123 |
mSize1 = mAvg/150; |
|
124 |
mSize2 = mAvg/60; |
|
125 |
mSizeT = mAvg/30; |
|
126 |
|
|
127 |
mPaint.setTextSize(mSizeT); |
|
128 |
|
|
129 |
clearPoints(); |
|
130 |
} |
|
131 |
|
|
116 | 132 |
/////////////////////////////////////////////////////////////////// |
117 | 133 |
|
118 | 134 |
public static void setMode(int mode) |
... | ... | |
164 | 180 |
di2D.removeAll(); |
165 | 181 |
di3D.removeAll(); |
166 | 182 |
|
167 |
for(int i=0; i<3*NUM_POINTS; i++) |
|
168 |
{ |
|
169 |
mPoints[i] = -10.0f; |
|
170 |
} |
|
183 |
clearPoints(); |
|
171 | 184 |
} |
172 | 185 |
} |
173 | 186 |
|
... | ... | |
193 | 206 |
} |
194 | 207 |
|
195 | 208 |
/////////////////////////////////////////////////////////////////// |
196 |
|
|
209 |
|
|
210 |
private static void clearPoints() |
|
211 |
{ |
|
212 |
for(int i=0; i<3*NUM_POINTS; i++) |
|
213 |
{ |
|
214 |
mPoints[i] = -10.0f; |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
/////////////////////////////////////////////////////////////////// |
|
219 |
|
|
197 | 220 |
private static void drawCurve1D(Canvas c, long time) |
198 | 221 |
{ |
199 | 222 |
int len = di1D.getNumPoints(); |
200 |
int size1 = DynamicRenderer.texH/200; |
|
201 |
int size2 = DynamicRenderer.texH/80; |
|
202 |
|
|
203 | 223 |
mPaint.setColor(0xff000000); |
204 | 224 |
|
205 | 225 |
c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint); |
206 |
c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
|
|
226 |
c.drawText("x", 0.95f*DynamicRenderer.texW, DynamicRenderer.texH /2 + mSizeT , mPaint);
|
|
207 | 227 |
|
208 | 228 |
if( len>=2 ) |
209 | 229 |
{ |
... | ... | |
215 | 235 |
: 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1); |
216 | 236 |
|
217 | 237 |
mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); |
218 |
c.drawCircle(mPoints[3*i], DynamicRenderer.texH/2 , size1, mPaint );
|
|
238 |
c.drawCircle(mPoints[3*i], DynamicRenderer.texH/2 , mSize1, mPaint );
|
|
219 | 239 |
} |
220 | 240 |
} |
221 | 241 |
|
... | ... | |
224 | 244 |
for(int curr=0; curr<len; curr++) |
225 | 245 |
{ |
226 | 246 |
p1D = di1D.getPoint(curr); |
227 |
c.drawCircle(p1D.getX(), DynamicRenderer.texH/2 , size2, mPaint);
|
|
247 |
c.drawCircle(p1D.getX(), DynamicRenderer.texH/2 , mSize2, mPaint);
|
|
228 | 248 |
} |
229 | 249 |
} |
230 | 250 |
|
... | ... | |
233 | 253 |
private static void drawCurve2D(Canvas c, long time) |
234 | 254 |
{ |
235 | 255 |
int len = di2D.getNumPoints(); |
236 |
int size1 = DynamicRenderer.texH/200; |
|
237 |
int size2 = DynamicRenderer.texH/80; |
|
238 |
|
|
239 | 256 |
mPaint.setColor(0xff000000); |
240 | 257 |
|
241 | 258 |
c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint); |
242 | 259 |
c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH, mPaint); |
243 | 260 |
|
244 |
c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
|
|
245 |
c.drawText("y", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
|
|
261 |
c.drawText("x", 0.95f* DynamicRenderer.texW , DynamicRenderer.texH/2+mSizeT , mPaint);
|
|
262 |
c.drawText("y", DynamicRenderer.texW/2 + mSizeT, mSizeT , mPaint);
|
|
246 | 263 |
|
247 | 264 |
if( len>=2 ) |
248 | 265 |
{ |
249 | 266 |
di2D.interpolateMain(mPoints,3*mPosition, time); |
250 | 267 |
|
251 |
//android.util.Log.e("surface", "pos="+mPosition+" x="+mPoints[3*mPosition]+" y="+mPoints[3*mPosition+1]+" time="+time); |
|
252 |
|
|
253 | 268 |
for(int i=0; i<NUM_POINTS; i++) |
254 | 269 |
{ |
255 | 270 |
int color = i<=mPosition ? 0xff - (mPosition -i)*0xff/(NUM_POINTS-1) |
256 | 271 |
: 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1); |
257 | 272 |
|
258 | 273 |
mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); |
259 |
c.drawCircle(mPoints[3*i], mPoints[3*i+1], size1, mPaint );
|
|
274 |
c.drawCircle(mPoints[3*i], mPoints[3*i+1], mSize1, mPaint );
|
|
260 | 275 |
} |
261 | 276 |
} |
262 | 277 |
|
... | ... | |
265 | 280 |
for(int curr=0; curr<len; curr++) |
266 | 281 |
{ |
267 | 282 |
p2D = di2D.getPoint(curr); |
268 |
c.drawCircle(p2D.getX(),p2D.getY(), size2, mPaint);
|
|
283 |
c.drawCircle(p2D.getX(),p2D.getY(), mSize2, mPaint);
|
|
269 | 284 |
} |
270 | 285 |
} |
271 | 286 |
|
... | ... | |
274 | 289 |
private static void drawCurve3D(Canvas c, long time) |
275 | 290 |
{ |
276 | 291 |
int len = di3D.getNumPoints(); |
277 |
int size1 = DynamicRenderer.texH/200; |
|
278 |
int size2 = DynamicRenderer.texH/80; |
|
279 |
|
|
280 | 292 |
mPaint.setColor(0xff000000); |
281 | 293 |
|
282 | 294 |
c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW , DynamicRenderer.texH/2, mPaint); |
283 | 295 |
c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH , mPaint); |
284 | 296 |
|
285 |
c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
|
|
286 |
c.drawText( currentDim==DIM_3DXY ? "y" : "z", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
|
|
297 |
c.drawText( "x" , 0.95f* DynamicRenderer.texW , DynamicRenderer.texH/2 + mSizeT , mPaint);
|
|
298 |
c.drawText( currentDim==DIM_3DXY ? "y" : "z", DynamicRenderer.texW/2 + mSizeT, mSizeT , mPaint);
|
|
287 | 299 |
|
288 | 300 |
if( len>=2 ) |
289 | 301 |
{ |
... | ... | |
295 | 307 |
: 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1); |
296 | 308 |
|
297 | 309 |
mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); |
298 |
c.drawCircle(mPoints[3*i], mPoints[3*i + (currentDim==DIM_3DXY ? 1:2) ], size1, mPaint );
|
|
310 |
c.drawCircle(mPoints[3*i], mPoints[3*i + (currentDim==DIM_3DXY ? 1:2) ], mSize1, mPaint );
|
|
299 | 311 |
} |
300 | 312 |
} |
301 | 313 |
|
... | ... | |
304 | 316 |
for(int curr=0; curr<len; curr++) |
305 | 317 |
{ |
306 | 318 |
p3D = di3D.getPoint(curr); |
307 |
c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), size2, mPaint);
|
|
319 |
c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), mSize2, mPaint);
|
|
308 | 320 |
} |
309 | 321 |
} |
310 | 322 |
|
... | ... | |
324 | 336 |
p1D = di1D.getPoint(g); |
325 | 337 |
gx = p1D.getX(); |
326 | 338 |
|
327 |
if( (x-gx)*(x-gx) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
|
|
339 |
if( (x-gx)*(x-gx) < (mAvg*mAvg/100) )
|
|
328 | 340 |
{ |
329 | 341 |
moving = g; |
330 | 342 |
break; |
... | ... | |
334 | 346 |
{ |
335 | 347 |
synchronized(lock) |
336 | 348 |
{ |
337 |
if( len>=MAX_VECTORS ) di1D.removeAll(); |
|
349 |
if( len>=MAX_POINTS ) |
|
350 |
{ |
|
351 |
di1D.removeAll(); |
|
352 |
clearPoints(); |
|
353 |
} |
|
338 | 354 |
di1D.add(new Static1D(x)); |
339 | 355 |
} |
340 | 356 |
} |
... | ... | |
347 | 363 |
gx = p2D.getX(); |
348 | 364 |
gy = p2D.getY(); |
349 | 365 |
|
350 |
if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
|
|
366 |
if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (mAvg*mAvg/100) )
|
|
351 | 367 |
{ |
352 | 368 |
moving = g; |
353 | 369 |
break; |
... | ... | |
357 | 373 |
{ |
358 | 374 |
synchronized(lock) |
359 | 375 |
{ |
360 |
if( len>=MAX_VECTORS ) di2D.removeAll(); |
|
376 |
if( len>=MAX_POINTS ) |
|
377 |
{ |
|
378 |
di2D.removeAll(); |
|
379 |
clearPoints(); |
|
380 |
} |
|
361 | 381 |
di2D.add(new Static2D(x,y)); |
362 | 382 |
} |
363 | 383 |
} |
... | ... | |
373 | 393 |
|
374 | 394 |
if( currentDim==DIM_3DXY ) |
375 | 395 |
{ |
376 |
if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
|
|
396 |
if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (mAvg*mAvg/100) )
|
|
377 | 397 |
{ |
378 | 398 |
moving = g; |
379 | 399 |
break; |
... | ... | |
381 | 401 |
} |
382 | 402 |
if( currentDim==DIM_3DXZ ) |
383 | 403 |
{ |
384 |
if( (x-gx)*(x-gx) + (y-gz)*(y-gz) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
|
|
404 |
if( (x-gx)*(x-gx) + (y-gz)*(y-gz) < (mAvg*mAvg/100) )
|
|
385 | 405 |
{ |
386 | 406 |
moving = g; |
387 | 407 |
break; |
... | ... | |
392 | 412 |
{ |
393 | 413 |
synchronized(lock) |
394 | 414 |
{ |
395 |
if( len>=MAX_VECTORS ) di3D.removeAll(); |
|
415 |
if( len>=MAX_POINTS ) |
|
416 |
{ |
|
417 |
di3D.removeAll(); |
|
418 |
clearPoints(); |
|
419 |
} |
|
396 | 420 |
|
397 | 421 |
if( currentDim==DIM_3DXY ) |
398 | 422 |
{ |
Also available in: Unified diff
Improvements to the Dynamic app.