commit 97dadfe597527a38f727a043193a8d73b2e58d2a
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Nov 1 17:20:44 2016 +0000

    1. Attempt to deal with unstable Orthonormal Base in Dynamic class (so far unsuccessful)
    2. Improvements to the 'Dynamic' (and by necessity, 'MovingEffects') applications (to be able to debug the previous)

diff --git a/src/main/java/org/distorted/examples/dynamic/DynamicActivity.java b/src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
index 10b1515..697aa16 100644
--- a/src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
+++ b/src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
@@ -56,10 +56,6 @@ public class DynamicActivity extends Activity implements OnSeekBarChangeListener
       progress1=0;
       progress2=0;
 
-
-      //textD.setText("Duration: 10 s");
-      //textN.setText("Noise: 0.0");
-
       bar = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
       bar.setProgress(0);
       bar.setOnSeekBarChangeListener(this);
diff --git a/src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java b/src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java
index e46e3e7..3d38742 100644
--- a/src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java
+++ b/src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java
@@ -31,26 +31,22 @@ import android.opengl.GLSurfaceView;
 
 import org.distorted.library.DistortedBitmap;
 import org.distorted.library.Distorted;
-import org.distorted.library.EffectTypes;
-import org.distorted.library.type.Static3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class DynamicRenderer implements GLSurfaceView.Renderer
+class DynamicRenderer implements GLSurfaceView.Renderer
    {  
-   public static final int BWID = 300;
-   public static final int BHEI = 400;
-   
    private GLSurfaceView mView;
    private DistortedBitmap mBackground;
    private Canvas mCanvas;
    private Bitmap mBitmap;
    private Paint mPaint;
-   private int texWidth, texHeight;
+
+   static int texW, texH;
     
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   public DynamicRenderer(GLSurfaceView v)
+   DynamicRenderer(GLSurfaceView v)
      {    
      mPaint = new Paint();
      mPaint.setAntiAlias(true);
@@ -59,19 +55,12 @@ public class DynamicRenderer implements GLSurfaceView.Renderer
      mPaint.setStyle(Style.FILL);
       
      mView = v;
-      
-     texWidth = BWID;
-     texHeight= BHEI;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
      {   
-     mBackground = new DistortedBitmap(texWidth,texHeight, 2);    
-     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
-     mCanvas = new Canvas(mBitmap);
-     
      try
         {
         Distorted.onSurfaceCreated(mView.getContext());
@@ -86,10 +75,14 @@ public class DynamicRenderer implements GLSurfaceView.Renderer
 
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
      {
-     mBackground.abortEffects(EffectTypes.MATRIX);
-     mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
-     Distorted.onSurfaceChanged(width, height);
-     DynamicSurfaceView.setScreenSize(width,height);
+     texW = width;
+     texH = height;
+
+     mBackground = new DistortedBitmap(texW,texH, 2);
+     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
+     mCanvas = new Canvas(mBitmap);
+
+     Distorted.onSurfaceChanged(texW,texH);
      }
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -100,7 +93,7 @@ public class DynamicRenderer implements GLSurfaceView.Renderer
        
      long time = System.currentTimeMillis();
       
-     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
+     mCanvas.drawRect(0, 0, texW, texH, mPaint);
      DynamicSurfaceView.drawCurve(mCanvas,time);
      mBackground.setBitmap(mBitmap);
      mBackground.draw(time);
diff --git a/src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java b/src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
index b87851c..03c886a 100644
--- a/src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
+++ b/src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
@@ -44,26 +44,22 @@ public class DynamicSurfaceView extends GLSurfaceView
     public static final int DIM_3DXY = 2; 
     public static final int DIM_3DXZ = 3; 
 
-    private static final int NUM_INTERPOLATIONS= 100;
-    private static final int MAX_VECTORS       =   6;
+    private static final int NUM_POINTS = 400;
+    private static final int MAX_VECTORS=   6;
 
     private static final Object lock = new Object();
 
-    private static int xDown,yDown;
-    private static int mScrW, mScrH;
-   
     private static Dynamic1D di1D;
     private static Dynamic2D di2D;
     private static Dynamic3D di3D;
     
     private static Paint mPaint;
     private static int moving;
-    private static long mTime = 0;
     private static int mDuration;
-    private static float mPosition;
+    private static int mPosition;
     private static float mNoise0, mNoise1, mNoise2;
     
-    private static int currentDim = DIM_2D;
+    private static int currentDim;
     
     private static Static1D p1D;
     private static Static2D p2D;
@@ -73,7 +69,7 @@ public class DynamicSurfaceView extends GLSurfaceView
     private static Static2D p2N;
     private static Static3D p3N;
 
-    private static float[] mDrawCoord = new float[3];
+    private static float[] mPoints = new float[3*NUM_POINTS];
       
 ///////////////////////////////////////////////////////////////////
     
@@ -84,7 +80,8 @@ public class DynamicSurfaceView extends GLSurfaceView
       mPaint = new Paint();
       mPaint.setStyle(Style.FILL);
       mPaint.setAntiAlias(true);
-      
+
+      currentDim= DIM_2D;
       moving    = -1;
       mDuration = 10000;
       mPosition = 0;
@@ -92,11 +89,11 @@ public class DynamicSurfaceView extends GLSurfaceView
       mNoise1   = 0.0f;
       mNoise2   = 0.0f;
 
-      di1D = new Dynamic1D(mDuration,0.5f);
+      di1D = new Dynamic1D(mDuration,0.0f);
       p1N  = new Static1D(mNoise0);
-      di2D = new Dynamic2D(mDuration,0.5f);
+      di2D = new Dynamic2D(mDuration,0.0f);
       p2N  = new Static2D(mNoise0,mNoise1);
-      di3D = new Dynamic3D(mDuration,0.5f);
+      di3D = new Dynamic3D(mDuration,0.0f);
       p3N  = new Static3D(mNoise0,mNoise1,mNoise2);
 
       if(!isInEditMode())
@@ -124,14 +121,6 @@ public class DynamicSurfaceView extends GLSurfaceView
       di2D.setMode(mode);
       di3D.setMode(mode);
       }
-      
-///////////////////////////////////////////////////////////////////
-    
-    public static void setScreenSize(int width, int height)
-      {
-      mScrW = width;
-      mScrH = height;
-      }
 
 ///////////////////////////////////////////////////////////////////
 
@@ -174,6 +163,11 @@ public class DynamicSurfaceView extends GLSurfaceView
             di1D.removeAll();
             di2D.removeAll();
             di3D.removeAll();
+
+            for(int i=0; i<3*NUM_POINTS; i++)
+              {
+              mPoints[i] = -10.0f;
+              }
             }
           }
       
@@ -185,7 +179,7 @@ public class DynamicSurfaceView extends GLSurfaceView
     
     public static void drawCurve(Canvas c, long time)
       {
-      mPosition += (mTime>0 && mDuration>0) ? ((float)(time-mTime)*NUM_INTERPOLATIONS/mDuration) : 0; 
+      if ( ++mPosition >= NUM_POINTS ) mPosition=0;
          
       synchronized(lock)
         {
@@ -196,8 +190,6 @@ public class DynamicSurfaceView extends GLSurfaceView
           default    : drawCurve3D(c,time); break;
           }
         }
-      
-      mTime = time;
       }
 
 ///////////////////////////////////////////////////////////////////
@@ -205,22 +197,25 @@ public class DynamicSurfaceView extends GLSurfaceView
     private static void drawCurve1D(Canvas c, long time)
       {
       int len = di1D.getNumPoints();   
-        
+      int size1 = DynamicRenderer.texH/200;
+      int size2 = DynamicRenderer.texH/80;
+
       mPaint.setColor(0xff000000);
       
-      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
-      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
-      
+      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint);
+      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
+
       if( len>=2 )
         {
-        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
+        di1D.interpolateMain(mPoints,3*mPosition, time);
+
+        for(int i=0; i<NUM_POINTS; i++)
           {
-          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
-                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
+          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
+                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
          
           mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
-          di1D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
-          c.drawCircle(mDrawCoord[0], DynamicRenderer.BHEI/2 , 2.0f, mPaint );
+          c.drawCircle(mPoints[3*i], DynamicRenderer.texH/2 , size1, mPaint );
           }
         }
      
@@ -229,7 +224,7 @@ public class DynamicSurfaceView extends GLSurfaceView
       for(int curr=0; curr<len; curr++)
         {      
         p1D = di1D.getPoint(curr);
-        c.drawCircle(p1D.getX(), DynamicRenderer.BHEI/2 , 5.0f, mPaint);
+        c.drawCircle(p1D.getX(), DynamicRenderer.texH/2 , size2, mPaint);
         }   
       }
     
@@ -238,25 +233,30 @@ public class DynamicSurfaceView extends GLSurfaceView
     private static void drawCurve2D(Canvas c, long time)
       {
       int len = di2D.getNumPoints();   
-        
+      int size1 = DynamicRenderer.texH/200;
+      int size2 = DynamicRenderer.texH/80;
+
       mPaint.setColor(0xff000000);
       
-      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
-      c.drawLine(DynamicRenderer.BWID/2, 0, DynamicRenderer.BWID/2, DynamicRenderer.BHEI, mPaint);
+      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint);
+      c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH, mPaint);
       
-      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
-      c.drawText("y", 0.55f* DynamicRenderer.BWID, 0.05f* DynamicRenderer.BHEI , mPaint);
+      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
+      c.drawText("y", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
       
       if( len>=2 )
         {
-        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
+        di2D.interpolateMain(mPoints,3*mPosition, time);
+
+//android.util.Log.e("surface", "pos="+mPosition+" x="+mPoints[3*mPosition]+" y="+mPoints[3*mPosition+1]+" time="+time);
+
+        for(int i=0; i<NUM_POINTS; i++)
           {
-          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
-                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
+          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
+                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
          
-          mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
-          di2D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
-          c.drawCircle(mDrawCoord[0], mDrawCoord[1], 2.0f, mPaint );
+          mPaint.setColor( 0xffffff + ((color&0xff)<<24) );
+          c.drawCircle(mPoints[3*i], mPoints[3*i+1], size1, mPaint );
           }
         }
      
@@ -265,7 +265,7 @@ public class DynamicSurfaceView extends GLSurfaceView
       for(int curr=0; curr<len; curr++)
         {      
         p2D = di2D.getPoint(curr);
-        c.drawCircle(p2D.getX(),p2D.getY(), 5.0f, mPaint);
+        c.drawCircle(p2D.getX(),p2D.getY(), size2, mPaint);
         }
       }
 
@@ -274,25 +274,28 @@ public class DynamicSurfaceView extends GLSurfaceView
     private static void drawCurve3D(Canvas c, long time)
       {
       int len = di3D.getNumPoints();   
-      
+      int size1 = DynamicRenderer.texH/200;
+      int size2 = DynamicRenderer.texH/80;
+
       mPaint.setColor(0xff000000);
       
-      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
-      c.drawLine(DynamicRenderer.BWID/2, 0, DynamicRenderer.BWID/2, DynamicRenderer.BHEI, mPaint);
+      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW  , DynamicRenderer.texH/2, mPaint);
+      c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH  , mPaint);
       
-      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
-      c.drawText( currentDim==DIM_3DXY ? "y" : "z", 0.55f* DynamicRenderer.BWID, 0.05f* DynamicRenderer.BHEI , mPaint);
+      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
+      c.drawText( currentDim==DIM_3DXY ? "y" : "z", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
       
       if( len>=2 )
         {
-        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
+        di3D.interpolateMain(mPoints, 3*mPosition, time);
+
+        for(int i=0; i<NUM_POINTS; i++)
           {
-          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
-                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
+          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
+                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
          
           mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
-          di3D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
-          c.drawCircle(mDrawCoord[0], mDrawCoord[currentDim==DIM_3DXY ? 1:2], 2.0f, mPaint );
+          c.drawCircle(mPoints[3*i], mPoints[3*i + (currentDim==DIM_3DXY ? 1:2) ], size1, mPaint );
           }
         }
      
@@ -301,7 +304,7 @@ public class DynamicSurfaceView extends GLSurfaceView
       for(int curr=0; curr<len; curr++)
         {      
         p3D = di3D.getPoint(curr);
-        c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), 5.0f, mPaint);
+        c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), size2, mPaint);
         }   
       }
     
@@ -321,7 +324,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                        p1D = di1D.getPoint(g);  
                        gx = p1D.getX();
                                     
-                       if( (xDown-gx)*(xDown-gx) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
+                       if( (x-gx)*(x-gx) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
                          {
                          moving = g;
                          break;
@@ -332,7 +335,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                        synchronized(lock)
                          {
                          if( len>=MAX_VECTORS ) di1D.removeAll();
-                         di1D.add(new Static1D(xDown));
+                         di1D.add(new Static1D(x));
                          }
                        }
                      break;
@@ -344,7 +347,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                        gx = p2D.getX();
                        gy = p2D.getY();
                                     
-                       if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
+                       if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
                          {
                          moving = g;
                          break;
@@ -355,7 +358,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                        synchronized(lock)
                          {
                          if( len>=MAX_VECTORS ) di2D.removeAll();
-                         di2D.add(new Static2D(xDown,yDown));
+                         di2D.add(new Static2D(x,y));
                          }
                        }
                      break;
@@ -370,7 +373,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                                
                      if( currentDim==DIM_3DXY )
                        {
-                       if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
+                       if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
                          {
                          moving = g;
                          break;
@@ -378,7 +381,7 @@ public class DynamicSurfaceView extends GLSurfaceView
                        }
                      if( currentDim==DIM_3DXZ )
                        {
-                       if( (xDown-gx)*(xDown-gx) + (yDown-gz)*(yDown-gz) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
+                       if( (x-gx)*(x-gx) + (y-gz)*(y-gz) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
                          {
                          moving = g;
                          break;
@@ -393,11 +396,11 @@ public class DynamicSurfaceView extends GLSurfaceView
                     
                        if( currentDim==DIM_3DXY )
                          {
-                         di3D.add(new Static3D(xDown,yDown, DynamicRenderer.BHEI/2));
+                         di3D.add(new Static3D(x,y, DynamicRenderer.texH/2));
                          }
                        if( currentDim==DIM_3DXZ )
                          {
-                         di3D.add(new Static3D(xDown, DynamicRenderer.BHEI/2,yDown));
+                         di3D.add(new Static3D(x, DynamicRenderer.texH/2,y));
                          }
                        }
                      }
@@ -410,19 +413,20 @@ public class DynamicSurfaceView extends GLSurfaceView
     @Override public boolean onTouchEvent(MotionEvent event) 
       {
       int action = event.getAction();
-          
+      int xDown, yDown;
+
       switch(action)
         {
-        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX()* DynamicRenderer.BWID/mScrW;
-                                      yDown = (int)event.getY()* DynamicRenderer.BHEI/mScrH;
+        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX();
+                                      yDown = (int)event.getY();
                                       
                                       addNewPoint(xDown,yDown);
                                     
                                       break;
         case MotionEvent.ACTION_MOVE: if( moving>=0 )
                                         {
-                                        xDown = (int)event.getX()* DynamicRenderer.BWID/mScrW;
-                                        yDown = (int)event.getY()* DynamicRenderer.BHEI/mScrH;
+                                        xDown = (int)event.getX();
+                                        yDown = (int)event.getY();
                                         
                                         switch(currentDim)
                                           {
diff --git a/src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java b/src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
index e40409c..e3bf4a0 100644
--- a/src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
+++ b/src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
@@ -31,27 +31,22 @@ import android.opengl.GLSurfaceView;
 
 import org.distorted.library.DistortedBitmap;
 import org.distorted.library.Distorted;
-import org.distorted.library.EffectTypes;
-import org.distorted.library.type.Static3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class MovingEffectsRenderer implements GLSurfaceView.Renderer 
+class MovingEffectsRenderer implements GLSurfaceView.Renderer
    {  
-   public static final int NUMLINES = 10;
-   public static final int BWID = 300;
-   public static final int BHEI = 400;
-   
    private GLSurfaceView mView;
-   public static DistortedBitmap mBackground;
    private Canvas mCanvas;
    private Bitmap mBitmap;
    private Paint mPaint;
-   private int texWidth, texHeight;
-    
+   private int texW, texH;
+
+   static DistortedBitmap mBackground;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   public MovingEffectsRenderer(GLSurfaceView v)
+   MovingEffectsRenderer(GLSurfaceView v)
      {    
      mPaint = new Paint();
      mPaint.setAntiAlias(true);
@@ -59,53 +54,60 @@ public class MovingEffectsRenderer implements GLSurfaceView.Renderer
      mPaint.setStyle(Style.FILL);
       
      mView = v;
-      
-     texWidth = BWID;
-     texHeight= BHEI;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
    private void drawBackground()
      {
+     int NW, NH;
+
+     if( texH<texW )
+       {
+       NH = 10;
+       NW = NH*texW/texH;
+       }
+     else
+       {
+       NW = 10;
+       NH = NW*texH/texW;
+       }
+
      mPaint.setColor(0xff008800);
-     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
+     mCanvas.drawRect(0, 0, texW, texH, mPaint);
      mPaint.setColor(0xffffffff);
          
-     for(int i=0; i<=NUMLINES ; i++ )
-       {
-       mCanvas.drawRect(texWidth*i/NUMLINES - 2,                       0,  texWidth*i/NUMLINES + 2,  texHeight               , mPaint);
-       mCanvas.drawRect(                      0, texHeight*i/NUMLINES -2,  texWidth               ,  texHeight*i/NUMLINES + 2, mPaint);  
-       } 
+     for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2,  texW,  texH*i/NH + 2, mPaint);
+     for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2,  texH, mPaint);
      }
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
-     {         
-     mBackground = new DistortedBitmap(texWidth,texHeight, 80);   
-     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
-     mCanvas = new Canvas(mBitmap); 
-      
+     {
      try
-        {
-        Distorted.onSurfaceCreated(mView.getContext());
-        }
-      catch(Exception ex)
-        {
-        android.util.Log.e("Renderer", ex.getMessage() );
-        }
+       {
+       Distorted.onSurfaceCreated(mView.getContext());
+       }
+     catch(Exception ex)
+       {
+       android.util.Log.e("Renderer", ex.getMessage() );
+       }
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
      {
-     mBackground.abortEffects(EffectTypes.MATRIX);
-     mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
-   
-     Distorted.onSurfaceChanged(width, height);
-     MovingEffectsSurfaceView.setScreenSize(width, height);    
+     texW = width;
+     texH = height;
+
+     mBackground = new DistortedBitmap(texW,texH, 80);
+     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
+     mCanvas = new Canvas(mBitmap);
+
+     Distorted.onSurfaceChanged(texW, texH);
+     MovingEffectsSurfaceView.onSurfaceChanged(texW,texH);
      }
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java b/src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java
index 2c5585c..e2ade90 100644
--- a/src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java
+++ b/src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java
@@ -29,9 +29,7 @@ import android.view.MotionEvent;
 import android.util.AttributeSet;
 
 import org.distorted.library.EffectTypes;
-import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.Dynamic2D;
-import org.distorted.library.type.Dynamic3D;
 import org.distorted.library.type.Dynamic4D;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static2D;
@@ -43,7 +41,7 @@ import org.distorted.library.type.Static4D;
 public class MovingEffectsSurfaceView extends GLSurfaceView
     {
     private static final int LOOP_TIME = 5000;
-    private static final int NUM_INTERPOLATIONS= 100;
+    private static final int NUM_POINTS= 100;
    
     public static final int EFFECT_POINTS=0;
     public static final int EFFECT_BUBBLE=1;
@@ -51,11 +49,6 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
     public static final int EFFECT_TRANS =3;
     public static final int EFFECT_CHROMA=4;
     public static final int EFFECT_SWIRL =5;
-   
-    private static MovingEffectsRenderer mRenderer;
-    
-    private static int xDown,yDown;
-    private static int mScrW, mScrH;
 
     private static Dynamic2D di2D;
     private static Static4D dr;
@@ -63,11 +56,13 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
 
     private static Paint mPaint;
     private static int moving;
-    private static Object lock = new Object();
+    private static final Object lock = new Object();
     private static long mTime = 0;
     
     private static int mCurrEffect;
-    
+    private static int mSize1, mSize2, mSizeR;
+    private static int mMax;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
     
     public MovingEffectsSurfaceView(Context c, AttributeSet attrs) 
@@ -81,7 +76,6 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
       
       di2D    = new Dynamic2D(LOOP_TIME,0.0f);
       mRegion = new Dynamic4D(LOOP_TIME,0.0f);
-      dr      = new Static4D(0,0,60,60);
 
       if(!isInEditMode())
         {
@@ -95,17 +89,22 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
           setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
           }
         
-        mRenderer = new MovingEffectsRenderer(this);
+        MovingEffectsRenderer mRenderer = new MovingEffectsRenderer(this);
         setRenderer(mRenderer);
         }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public static void setScreenSize(int width, int height)
+    public static void onSurfaceChanged(int width,int height)
       {
-      mScrW = width;
-      mScrH = height;
+      mMax = width>height ? width:height;
+
+      mSize1 = mMax/200;
+      mSize2 = mMax/80;
+      mSizeR = mMax/6;
+
+      dr = new Static4D(0,0, mSizeR,mSizeR);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -125,7 +124,7 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
         {
         MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.VERTEX);
         MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.FRAGMENT);
-        MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,30) , di2D, dr);
+        MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,mMax/10) , di2D, dr);
         mCurrEffect = EFFECT_BUBBLE;
         }
       }
@@ -211,20 +210,23 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
       synchronized(lock)
         {  
         int len = di2D.getNumPoints();
+
         float[] drawCoord = new float[2];
         Static2D cu;
-        int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_INTERPOLATIONS/LOOP_TIME)  : 0; 
+        int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_POINTS/LOOP_TIME)  : 0;
             
         if( len>=2 )
           {
-          for(int i=0; i<NUM_INTERPOLATIONS; i++) 
+          float step = (float)LOOP_TIME/(NUM_POINTS+1);
+
+          for(int i=0; i<NUM_POINTS; i++)
             {
-            int color = i<=lit ? 0xff - (lit                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
-                               : 0xff - (lit+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
+            int color = i<=lit ? 0xff - (lit           -i)*0xff/(NUM_POINTS-1)
+                               : 0xff - (lit+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
          
             mPaint.setColor( 0xffffff + ((color&0xff)<<24) );  
-            di2D.interpolate( drawCoord, 0, (float)i/NUM_INTERPOLATIONS);
-            c.drawCircle(drawCoord[0], drawCoord[1], 2.0f, mPaint );
+            di2D.interpolateMain( drawCoord, 0, (long)(i*step) );
+            c.drawCircle(drawCoord[0], drawCoord[1], mSize1, mPaint );
             }
           }
      
@@ -233,7 +235,7 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
         for(int curr=0; curr<len; curr++)
           {       
           cu = di2D.getPoint(curr);
-          c.drawCircle(cu.getX(), cu.getY(), 5.0f, mPaint);
+          c.drawCircle(cu.getX(), cu.getY(), mSize2, mPaint);
           }
         
         if( time-mTime > LOOP_TIME ) mTime = time;
@@ -245,11 +247,13 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
     @Override public boolean onTouchEvent(MotionEvent event) 
       {
       if( mCurrEffect!=EFFECT_POINTS ) return true;   
-      
+
+      int xDown, yDown;
+
       switch(event.getAction())
         {
-        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW; 
-                                      yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH;
+        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX();
+                                      yDown = (int)event.getY();
                                     
                                       float gx, gy;
                                       Static2D dv;
@@ -261,7 +265,7 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
                                         gx = dv.getX();
                                         gy = dv.getY();
                                     
-                                        if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (MovingEffectsRenderer.BHEI*MovingEffectsRenderer.BHEI)/100 )
+                                        if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (mMax*mMax)/100 )
                                           {
                                           moving = g;
                                           break;
@@ -272,16 +276,17 @@ public class MovingEffectsSurfaceView extends GLSurfaceView
                                         synchronized(lock)
                                           {
                                           di2D.add(new Static2D(xDown,yDown));
-                                          mRegion.add(new Static4D(xDown,yDown,60,60));
+                                          mRegion.add(new Static4D(xDown,yDown,mSizeR,mSizeR));
                                           }
                                         } 
                                       break;
         case MotionEvent.ACTION_MOVE: if( moving>=0 )
                                         {
-                                        xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW; 
-                                        yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH;
+                                        xDown = (int)event.getX();
+                                        yDown = (int)event.getY();
+
                                         di2D.setPoint(moving, xDown, yDown);
-                                        mRegion.setPoint(moving, xDown, yDown, 60, 60);
+                                        mRegion.setPoint(moving, xDown, yDown, mSizeR, mSizeR);
                                         }                           
                                       break;
         case MotionEvent.ACTION_UP  : moving = -1;
