Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a matrix for a smuge/wobble effet ( see pictures ) in Android
    primarykey
    data
    text
    <p><strong><em>THANKS Torious, got it:</em></strong></p> <pre><code> private void smudge() { for (int i = 0; i &lt; COUNT*2; i += 2) { float xOriginal = matrixOriganal[i+0]; float yOriginal = matrixOriganal[i+1]; float distX = Math.abs(pointX-xOriginal); float distY = Math.abs(pointY-yOriginal); float dist = FloatMath.sqrt( distX*distX + distY*distY ); float coof = ( bubbleSize - dist ) / bubbleSize; float oc = (float) -Math.sin(coof * 2*Math.PI) * 0.15f ; if ( dist &lt; bubbleSize ) { matrixVertsMoved[i+0] = xOriginal + smudgeAmount * (coof+oc); matrixVertsMoved[i+1] = yOriginal; } else { matrixVertsMoved[i+0] = xOriginal; matrixVertsMoved[i+1] = yOriginal; } } invalidate(); } </code></pre> <hr> <p><strong>old:</strong> Right now I have this code that I made based on the api sample that comes with the SDK.</p> <pre><code>public class main extends Activity { //////////////////////////////////////////////////////// @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); LinearLayout ll01 = (LinearLayout)findViewById(R.id.linearLayout1); SampleView sv = new SampleView(this); ll01.addView(sv); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static class SampleView extends View { static int WIDTH = 8; // sections static int HEIGHT = 8; static int COUNT = (WIDTH + 1) * (HEIGHT + 1); // total verts count Bitmap mBitmap; // declaring a bitmap float[] matrixVertsMoved = new float[COUNT*2]; // declaring an array with double amount of vert count, one for x and one for y float[] matrixOriganal = new float[COUNT*2]; float clickX; float clickY; static void setXY(float[] array, int index, float x, float y) { array[index*2 + 0] = x; array[index*2 + 1] = y; } /// public SampleView(Context context) { super(context); setFocusable(true); mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.w); // construct our mesh int index = 0; for (int y = 0; y &lt;= HEIGHT; y++) { float fy = mBitmap.getHeight() * y / HEIGHT; for (int x = 0; x &lt;= WIDTH; x++) { float fx = mBitmap.getWidth() * x / WIDTH; setXY(matrixVertsMoved, index, fx, fy); setXY(matrixOriganal, index, fx, fy); index += 1; } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override protected void onDraw(Canvas canvas) { canvas.drawBitmapMesh(mBitmap, WIDTH, HEIGHT, matrixVertsMoved, 0, null, 0, null); Paint p1 = new Paint(); p1.setColor(0x660000FF); Paint p2 = new Paint(); p2.setColor(0x99FF0000); Paint p3 = new Paint(); p3.setColor(0xFFFFFB00); for (int i = 0; i &lt; COUNT*2; i += 2) { float x = matrixOriganal[i+0]; float y = matrixOriganal[i+1]; canvas.drawCircle(x, y, 4, p1); float x1 = matrixOriganal[i+0]; float y1 = matrixOriganal[i+1]; float x2 = matrixVertsMoved[i+0]; float y2 = matrixVertsMoved[i+1]; canvas.drawLine(x1, y1, x2, y2, p1); } for (int i = 0; i &lt; COUNT*2; i += 2) { float x = matrixVertsMoved[i+0]; float y = matrixVertsMoved[i+1]; canvas.drawCircle(x, y, 4, p2); } canvas.drawCircle(clickX, clickY, 6, p3); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void smudge() { for (int i = 0; i &lt; COUNT*2; i += 2) { float xOriginal = matrixOriganal[i+0]; float yOriginal = matrixOriganal[i+1]; float dist_click_to_origin_x = clickX - xOriginal; // distance from current vertex in the original matrix to the place clicked. float dist_click_to_origin_y = clickY - yOriginal; float kv_kat = dist_click_to_origin_x*dist_click_to_origin_x + dist_click_to_origin_y*dist_click_to_origin_y; float pull = ( 1000000 / kv_kat / FloatMath.sqrt(kv_kat) ); if (pull &gt;= 1) { matrixVertsMoved[i+0] = clickX; matrixVertsMoved[i+1] = clickY; } else { matrixVertsMoved[i+0] = xOriginal + dist_click_to_origin_x * pull; matrixVertsMoved[i+1] = yOriginal + dist_click_to_origin_y * pull; } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override public boolean onTouchEvent(MotionEvent event) { clickX = event.getX(); clickY = event.getY(); smudge(); // change the matrix. invalidate(); // calls a redraw on the canvas. return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// } </code></pre> <p>The important this is the wrap function at the end. Here's what it produces.</p> <p>// blue dots are the vertexes of the original matrix, while the red ones show how they moved from the click ( yellow dot ).</p> <p><img src="https://i.stack.imgur.com/P2zp3.png" alt="enter image description here"></p> <p>Yet that I need is it not to pinch in a vertex, but to sort of smudge it, like this.</p> <p><img src="https://i.stack.imgur.com/K5wqK.png" alt="enter image description here"></p> <p>For example, this smudge function could take in pixel or vertex coordinates from where to start the smudge, x and y offset and strength of the smudge, i.e. how hard should be the surrounding vertexes be affected.</p> <p>Any ideas how to do that?</p> <p><strong>edit: basically I'm trying to make something similar to <a href="http://www.andwobble.com/" rel="noreferrer">http://www.andwobble.com/</a></strong></p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload