当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


SVG <feSpotLight>用法及代码示例


SVG代表可缩放矢量图形。它可以像HTML画布一样用于制作图形和动画。
<feSpotLight> SVG定义可产生 spotlight 效果的光源。它定义了一个 spotlight ,其光线指向特定的点,并且仅在有限的区域照明。

用法:

<feSpotLight x="" y="" z="" pointsAtX="" pointsAtY="" 
    pointsAtZ="" specularExponent="" limitingConeAngle="" />

属性:

  • x, y, z:它告诉坐标系中相应的x,y,z。
  • pointsAtX, pointsAtY, pointsAtZ:发光点的X,Y,Z位置。
  • specularExponent:它告诉光聚焦在单个点上。预设值为1。
  • limitingConeAngle:它以角度为单位告诉两条线,即 spotlight 轴和 spotlight 锥。

范例1:

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg width="200" height="200"> 
        <defs> 
            <filter id="spotlight"> 
                <feSpecularLighting result="spec3" 
                    in="blur3" specularConstant="1.2" 
                    specularExponent="7"
                    lighting-color="#FFF"> 
  
                    <feSpotLight x="400" y="400" 
                        z="900" limitingConeAngle="9" /> 
                </feSpecularLighting> 
  
                <feComposite in="SourceGraphic" 
                    in2="spotlight" operator="out" 
                    k1="0" k2="1" k3="1" k4="0" /> 
            </filter> 
        </defs> 
  
        <rect x="40" y="40" width="100" height="100" 
            style="stroke:#000000; 
                fill:lightgreen; 
                filter:url(#spotlight);" /> 
  
        <rect x="40" y="40" width="100" height="100" 
            style="stroke:#000000;  
                fill:green;  
                filter:url(#spotlight);" /> 
  
        <g fill="#FFFFFF" stroke="black" font-size="10" 
            font-family="Verdana"> 
              
            <text x="50" y="90">GeeksForGeeks</text> 
    </svg> 
</body> 
  
</html>

输出:



范例2:

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg width="200" height="200"> 
        <defs> 
            <filter id="FillPaint"> 
                <feSpecularLighting result="spec3" 
                    in="blur3" specularConstant="1.2" 
                    specularExponent="7"
                    lighting-color="#FFF"> 
  
                    <feSpotLight x="600" y="600" 
                        z="1200" pointAtX="400" 
                        pointAtY="400" pointAtZ="400"
                        limitingConeAngle="9" /> 
                </feSpecularLighting> 
  
                <feComposite in="SourceGraphic" 
                    in2="spotlight" operator="out" 
                    k1="0" k2="1" k3="1" k4="0" /> 
            </filter> 
        </defs> 
  
        <rect x="1" y="1" width="198" 
            height="118" style="stroke:#000000;  
                                fill:black; 
                        filter:url(#FillPaint);" /> 
  
        <circle cx="100" cy="60" r="55" 
            stroke="darkgreen" stroke-width="3" 
            fill="Lightgreen"
            style="stroke:filter:url(#FillPaint);" /> 
  
        <g fill="#FFFFFF" stroke="Green" 
            font-size="10" c font-family="Verdana"> 
            <text x="60" y="62">GeeksForGeeks</text> 
    </svg> 
</body> 
  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自epistler_999大神的英文原创作品 SVG <feSpotLight> Element。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。