18
$\begingroup$

I'm trying to achieve a jelly / water surface effect. I'd like it to be a bit smoother. Here I am taking a triangulated rectangle and perturbing all points by a little random noise for each frame. This warps the polygons and stretches the texture so it looks like it's a turbulent liquid surface:

img = ExampleData[{"TestImage", "House"}];
mesh = TriangulateMesh@Rectangle[{0, 0}, {1, 1}];
coords = MeshCoordinates[mesh];
cells = MeshCells[mesh, 2];
texture = Texture[img];

Table[With[{newcoords = coords + 0.01*RandomPoint[Disk[], Length[coords]]},
   Rasterize[
    Graphics[{texture, 
      GraphicsComplex[newcoords, cells, 
       VertexTextureCoordinates -> coords]}]]
   ], {30}] // ListAnimate

water ripple image effect

To make this better and less jumpy I think I need to accumulate the small random disturbances of the coordinates of the mesh. But I don't want any point on the mesh to drift and deform its polygon so much over time that it becomes highly distorted with extreme self-intersections. Any ideas how I can do this and not push up computation time?

$\endgroup$

2 Answers 2

20
$\begingroup$

perhaps:

timg = ImageEffect[img, {"TornFrame"}];

tr[t_] := # + {5 10^-3 Cos[20 #[[2]] + 5 t], 5 10^-3 Sin[20 #[[1]] + 5 t]} &

frames = Table[ImageTransformation[timg, tr[t]], {t, Subdivide[0, 2 Pi, 40]}];

ListAnimate @ frames

enter image description here

$\endgroup$
1
  • $\begingroup$ Nice. No need for triangulation as it turns out, and it's smooth. $\endgroup$
    – flinty
    Commented Nov 14, 2020 at 17:49
14
$\begingroup$

This method seems to work quite well. Instead of changing the positions randomly, I rotate each vertex around in a small circle centered at each original vertex position. Every vertex starts at a randomly assigned phase so the polygons are not all in sync:

img = ExampleData[{"TestImage", "House"}];
mesh = TriangulateMesh[Rectangle[{0, 0}, {1, 1}], 
  MaxCellMeasure -> .003]
coords = MeshCoordinates[mesh];
cells = MeshCells[mesh, 2];
texture = Texture[img];
phases = RandomReal[{0, 2 Pi}, Length[coords]];
amplitude = 0.012;
frequency = 1.;
period = 1/30.;
ParallelTable[
  With[{newcoords = 
     MapThread[#1 + 
        amplitude {Cos[2 Pi t frequency + #2], 
          Sin[2 Pi t frequency + #2]} &, {coords, phases}]},
   Graphics[{texture, 
     GraphicsComplex[newcoords, cells, 
      VertexTextureCoordinates -> coords]}]
   ]
  , {t, 0, 1, period}] // ListAnimate

liquid image mesh rotating vertices

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.