當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。