SVG

SVG 意为可缩放矢量图形(Scalable Vector Graphics)。

SVG 使用 XML 格式定义图像。


SVG 文件可通过以下标签嵌入 HTML 文档:<embed>、<object> 或者 <iframe>

<embed>:

  • 优势:所有主要浏览器都支持,并允许使用脚本
  • 缺点:不推荐在HTML4和XHTML中使用(但在HTML5允许)
  • <embed src="circle1.svg" type="image/svg+xml" />

<object>:

  • 优势:所有主要浏览器都支持,并支持HTML4,XHTML和HTML5标准
  • 缺点:不允许使用脚本。
  • <object data="circle1.svg" type="image/svg+xml"></object>

  • <iframe>:

    • 优势:所有主要浏览器都支持,并允许使用脚本
    • 缺点:不推荐在HTML4和XHTML中使用(但在HTML5允许)
    • <iframe src="circle1.svg"></iframe>

    SVG有一些预定义的形状元素,可被开发者使用和操作:

    • 矩形 <rect>:       <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <rect x="50" y="20" rx="20" ry="20" width="150" height="150"
        style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;
        stroke-opacity:0.9"/>
           </svg>
    • //CSS 的 fill 属性定义矩形的填充颜色(rgb 值、颜色名或者十六进制值)  
    • //CSS 的 stroke-opacity 属性定义笔触颜色的透明度(合法的范围是:0 - 1)
    • //rx 和 ry 属性可使矩形产生圆角。
    • 圆形 <circle>:    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
          <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
      </svg> 
    • //cx和cy属性定义圆点的x和y坐标。如果省略cx和cy,圆的中心会被设置为(0, 0)
    • //r属性定义圆的半径
    • 椭圆 <ellipse> :
    • <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <ellipse cx="300" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" />
      </svg>
      • //cx属性定义的椭圆中心的x坐标
      • //cy属性定义的椭圆中心的y坐标
      • //rx属性定义的水平半径
      • //ry属性定义的垂直半径

    • 线 <line> :
    • <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <line x1="0" y1="0" x2="200" y2="200"
        style="stroke:rgb(255,0,0);stroke-width:2"/>
      </svg>
      • //x1 属性在 x 轴定义线条的开始
      • //y1 属性在 y 轴定义线条的开始
      • //x2 属性在 x 轴定义线条的结束
      • //y2 属性在 y 轴定义线条的结束

    • 折线 <polyline> :
    • <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
        <polyline points="0,40 40,40 40,80 80,80 80,120 120,120 120,160" style="fill:white;stroke:red;stroke-width:4" />
      </svg>
    • //<polyline> 元素是用于创建任何只有直线的形状
    • 多边形 :<polygon>
    • <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    • <polygon points="100,10 40,180 190,60 10,60 160,180"
    • style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
    • </svg>
    • //points 属性定义多边形每个角的 x 和 y 坐标

    • 路径 <path> :
    • <svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="400" width="450">
      <path id="lineAB" d="M 100 350 l 150 -300" stroke="red" stroke-width="3" fill="none" />
        <path id="lineBC" d="M 250 50 l 150 300" stroke="red" stroke-width="3" fill="none" />
        <path d="M 175 200 l 150 0" stroke="green" stroke-width="3" fill="none" />
        <path d="M 100 350 q 150 -300 300 0" stroke="blue" stroke-width="5" fill="none" />
        <!-- Mark relevant points -->
        <g stroke="black" stroke-width="3" fill="black">
          <circle id="pointA" cx="100" cy="350" r="3" />
          <circle id="pointB" cx="250" cy="50" r="3" />
          <circle id="pointC" cx="400" cy="350" r="3" />
        </g>
        <!-- Label the points -->
        <g font-size="30" font="sans-serif" fill="black" stroke="none" text-anchor="middle">
          <text x="100" y="350" dx="-30">A</text>
          <text x="250" y="50" dy="-10">B</text>
          <text x="400" y="350" dx="30">C</text>
        </g>
      </svg>
    • [插入]
    • M = moveto
    • L = lineto
    • H = horizontal lineto
    • V = vertical lineto
    • C = curveto
    • S = smooth curveto
    • Q = quadratic Bézier curve
    • T = smooth quadratic Bézier curveto
    • A = elliptical Arc
    • Z = closepath
    • //以上所有命令均允许小写字母。大写表示绝对定位,小写表示相对定位。




  • SVG 文本 - <text>

  • <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
    xmlns:xlink="http://www.w3.org/1999/xlink">
      <a xlink:href="http://www.w3schools.com/svg/" target="_blank">//链接文本
        <text x="0" y="15" fill="red">I love SVG</text>
      </a>
    </svg>
SVG Stroke属性:
  • stroke:Stroke属性定义一条线,文本或元素轮廓颜色
  • stroke-width:Tstroke- width属性定义了一条线,文本或元素轮廓厚度
  • stroke-linecap:strokelinecap属性定义不同类型的开放路径的终结
  • stroke-dasharray:strokedasharray属性用于创建虚线
SVG模糊效果:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
    <filter id="f1" x="0" y="0">
      <feGaussianBlur in="SourceGraphic" stdDeviation="15" />
    </filter>
  </defs>
  <rect width="90" height="90" stroke="green" stroke-width="3"
  fill="yellow" filter="url(#f1)" />
</svg>

  • <filter>元素id属性定义一个滤镜的唯一名称
  • <feGaussianBlur>元素定义模糊效果
  • in="SourceGraphic"这个部分定义了由整个图像创建效果
  • stdDeviation属性定义模糊量
  • <rect>元素的滤镜属性用来把元素链接到"f1"滤镜


「LLM那些事」系列第 4 篇《上下文窗口的边界》,文章连接:https://blog.csdn.net/houwenjin/article/details/163999753。 演示什么:在「预测」Sheet 的黄色格子里输入一句话(默认「来泡一杯」),四个「模型」——分别只统计最后 1 / 2 / 3 / 4 个字的 n-gram 查表——同时预测下一个字。同一个输入,看的上下文越长,候选越少、预测越确定: ┌────────────────┬──────────┬───────────────┬──────┐ │ 只看最后几个字 │ 用的前缀 │ 候选下一字数 │ 预测 │ ├────────────────┼──────────┼───────────────┼──────┤ │ 1 个 │ 杯 │ 3(茶/子/水) │ 模糊 │ ├────────────────┼──────────┼───────────────┼──────┤ │ 2 个 │ 一杯 │ 2(茶/水) │ 收窄 │ ├────────────────┼──────────┼───────────────┼──────┤ │ 3 个 │ 泡一杯 │ 1(茶) │ 确定 │ ├────────────────┼──────────┼───────────────┼──────┤ │ 4 个 │ 来泡一杯 │ 1(茶) │ 确定 │ └────────────────┴──────────┴───────────────┴──────┘
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值