Is there a way to achieve a perfect seamless waving effect for the whole of a svg. I tried approaching the problem by animating the baseFrequency
of feTurbulence
filter but it is not giving me what I need.
const lower = 0;
const upper = 0.008;
const step = 0.0001;
const time = 5000;
function animateBaseFrequency() {
let direction = 1; // 1 for incrementing, -1 for decrementing
let x = lower;
d3.select('#fltOne')
.transition()
.duration(time)
.ease(d3.easeLinear)
.tween('x', function() {
return function(t) {
x = x + step * direction;
if (x >= upper || x <= lower) {
direction *= -1; // Reverse direction at upper and lower bounds
}
d3.select(this).attr('baseFrequency', x);
};
}).on('end', animateBaseFrequency);
}
animateBaseFrequency();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script type="text/javascript" src="https://d3js.org/d3.v7.min.js"></script>
<body>
<link rel="stylesheet" href="style.css">
<div id="container" class="svg-container">
<svg viewBox="0 0 1280 720" xmlns="http://www.w3.org/2000/svg">
<defs id="pattern">
<pattern id="af" width="100%" height="100%" patternContentUnits="objectBoundingBox">
<image xlink:href="https://raw.githubusercontent.com/d3/d3-logo/master/d3.svg"
preserveAspectRatio="xMidYMid meet" width="1" height="1"></image>
</pattern>
<pattern patternContentUnits="userSpaceOnUse" id="main">
<rect class="patRect" width="400" height="300" fill="url(#af)"></rect>
</pattern>
<filter id="filt">
<feTurbulence result="TURBULENCE" numOctaves="1" seed="1" baseFrequency="0" stitchTiles="noStitch"
id="fltOne"></feTurbulence>
<feDisplacementMap in="SourceGraphic" in2="TURBULENCE" scale="30" result="dist" id="fltTwo">
</feDisplacementMap>
</filter>
</defs>
<rect class="rectOne" x="100" y="100" width="400" height="300" fill="url(#af)"
style="filter: url("#filt");"></rect>
</svg>
</div>
<!--d3 script-->
<script src="prod.js" defer></script>
</body>
</html>