svg制作能量流动效果完整代码
时间: 2023-11-16 19:04:12 浏览: 40
以下是一个简单的 SVG 制作能量流动效果的完整代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>SVG Energy Flow Animation</title>
<style>
body {
background-color: #333;
}
</style>
</head>
<body>
<svg width="500" height="300">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#00ccff" />
<stop offset="100%" stop-color="#ff3300" />
</linearGradient>
</defs>
<path id="path" fill="none" stroke="url(#gradient)" stroke-width="6"
d="M 50 150 C 100 100, 400 100, 450 150 S 300 200, 250 150 S 500 150, 550 200" />
<circle id="circle" cx="50" cy="150" r="10" fill="#fff" />
<animateMotion xlink:href="#circle" dur="5s" repeatCount="indefinite"
path="M 50 150 C 100 100, 400 100, 450 150 S 300 200, 250 150 S 500 150, 550 200" />
</svg>
</body>
</html>
```
解释一下代码:
- 我们首先定义了一个线性渐变 `linearGradient`,用于给路径 `path` 创建流动的颜色。
- `path` 定义了一条起点为 `(50, 150)` 的路径,路径经过四个控制点,最后回到终点 `(550, 200)`。这条路径将被用于控制小圆点的动画运动。
- `circle` 定义了一个起点为 `(50, 150)` 的圆,颜色为白色。
- `animateMotion` 定义了一个动画效果,它将在路径 `path` 上进行运动,时间为 5 秒,重复次数为无限次。
当你打开这个 HTML 文件时,你将会看到一个小圆点沿着路径 `path` 进行流动,并且带有颜色渐变效果。你可以更改路径和渐变的颜色以创建自己的能量流动效果。