How to animate SVG fePointLight along a path

Viewed 121

I can animate an object along a path successfully but I am trying to animate moving the fePointLight along a path. I can animate it with a simple animate with values but not for a defined path.

Here is my code for attempting to animating using animateMotion referencing the #path element)

<!DOCTYPE html>
<html>
<body>

<svg height="450" width="400">
  <filter id="path-spot-light">
    
    <!-- Follows #path -- DOES NOT WORK-->
    <feGaussianBlur stdDeviation="3" result="blur" />
        <feSpecularLighting result="spec" in="blur" specularExponent="35" lighting-color="#cccccc">
        <!--Light source effect-->
        <fePointLight x="75" y="100" z="50">
          <!--Lighting Animation-->
          <animateMotion dur="3s" repeatCount="indefinite">
            <mpath xlink:href="#path"></mpath>
          </animateMotion>
        </fePointLight>
    </feSpecularLighting>
    <!--Composition of inputs-->
    <feComposite in="SourceGraphic" in2="spec" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="comp1"/>
    
    
  </filter>

  <rect x="0"   y="0"  width="400" height="450" rx="5" ry="5" fill="blue" filter="url(#path-spot-light)"/>
  
  <path id="path"  d="M200,0 L200,150 L350,150 L350,350 L400,400" stroke="#9c9696" stroke-width="3" fill="none"/>
  
  <circle cx="" cy="" r="8" fill="#529fd9" >
    <animateMotion dur="3s" repeatCount="indefinite">
      <mpath xlink:href="#path"></mpath>
    </animateMotion>
  </circle>
  
</svg>

</body>
</html>

Here is the code for animating with a simple animate with values but does not reference the #path

<!DOCTYPE html>
<html>
<body>

<svg height="450" width="400">
  <filter id="diagonal-spot-light">
    <!--Blur effect-->
    <feGaussianBlur stdDeviation="3" result="blur1" />
    <!--Lighting effect-->
    <feSpecularLighting result="spec1" in="blur1" specularExponent="35" lighting-color="#cccccc">
        <!--Light source effect-->
        <fePointLight x="75" y="100" z="50">
          <!--Lighting Animation-->
          <animate attributeName="x" values="0;400" dur="3s" repeatCount="indefinite" />
          <animate attributeName="y" values="0;450" dur="3s" repeatCount="indefinite" />
        </fePointLight>
    </feSpecularLighting>
    
    <!--Composition of inputs-->
    <feComposite in="SourceGraphic" in2="spec1" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="comp1"/>
    
  </filter>

  <rect x="0"   y="0"  width="400" height="450" rx="5" ry="5" fill="blue" filter="url(#diagonal-spot-light)"/>
  
  <path id="diagonal-path"  d="M0,0  L400,450" stroke="#9c9696" stroke-width="3" fill="none"/>
  
  <circle cx="" cy="" r="8" fill="#529fd9">
    <animateMotion dur="3s" repeatCount="indefinite">
      <mpath xlink:href="#diagonal-path"></mpath>
    </animateMotion>
  </circle>
  
</svg>

</body>
</html>

How do I animate the fePointLight along the path?

=== EDIT === Thanks to @enxaneta I was able to apply the animation properly.

Here is my updated SVG with the fePointLight animating along a path.

<!DOCTYPE html>
<html>
<body>

<svg height="450" width="400">
  <filter id="path-spot-light">
    <feGaussianBlur stdDeviation="3" result="blur" />
        <feSpecularLighting result="spec" in="blur" specularExponent="35" lighting-color="#529fd9">
        <fePointLight z="50"></fePointLight>
    </feSpecularLighting>
    <feComposite in="SourceGraphic" in2="spec" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="comp1"/>
  </filter>

  <rect x="0"   y="0"  width="400" height="450" rx="5" ry="5" fill="blue" />
  
  <circle cx="" cy="" r="200"  fill="blue" filter="url(#path-spot-light)">
    <animateMotion dur="3s" repeatCount="indefinite">
      <mpath xlink:href="#path"></mpath>
    </animateMotion>
  </circle>
  <path id="path"  d="M200,0 L200,150 L350,150 L350,350 L400,400" stroke="#9c9696" stroke-width="3" fill="none"/>
  
  
  
  <circle cx="" cy="" r="8" fill="#529fd9" >
    <animateMotion dur="3s" repeatCount="indefinite">
      <mpath xlink:href="#path"></mpath>
    </animateMotion>
  </circle>
  
</svg>

</body>
</html>

=== END EDIT ===

0 Answers
Related