jellyTransform static method
Creates a jelly transform matrix based on velocity.
Implementation
static Matrix4 jellyTransform({
required Offset velocity,
double maxDistortion = 0.7,
double velocityScale = 1000.0,
}) {
final speed = velocity.distance;
if (speed == 0) return Matrix4.identity();
final direction = velocity / speed;
final distortionFactor =
(speed / velocityScale).clamp(0.0, 1.0) * maxDistortion;
final squashX = 1.0 - (direction.dx.abs() * distortionFactor * 0.5);
final squashY = 1.0 - (direction.dy.abs() * distortionFactor * 0.5);
final stretchX = 1.0 + (direction.dy.abs() * distortionFactor * 0.3);
final stretchY = 1.0 + (direction.dx.abs() * distortionFactor * 0.3);
final scaleX = squashX * stretchX;
final scaleY = squashY * stretchY;
return Matrix4.identity()..scale(scaleX, scaleY);
}