水滴融合动画效果

代码语言:html

所属分类:粒子

代码描述:水滴融合动画效果

代码标签: 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
/* basic style */
html,
body {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  background: radial-gradient(circle at center, rgb(62, 62, 62), rgb(12, 12, 12));
  color: #fff;
  font-family: "Brown", serif;
}

/* canvas style */
.canvas-wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
  width: 110%;
  height: 110%;
  -webkit-filter: url("#goo");
	filter: url("#goo");
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}
</style>

</head>
<body translate="no">
<div class="canvas-wrap">
<canvas id="canvas">
canvas not support
</canvas>
</div>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="12" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 18 -7" result="joint" />
</filter>
</defs>
</svg>

<script>
class Particle {
  /**
                 * コンストラクター
                 * @param {Number} x
                 * @param {Number} y
                 * @param {Number} radius
                 * @param {Number} angle
                 * @param {Number} distance
                 */
  constructor(canvas, radius, angle, distance, color) {
    this.canvas = canvas;
    this.radius = radius;
    this.angle = angle;
    this.distance = distance;
    this.color = color;
    this.x = 0;
    this.y = 0;
    this.speed = 1;
  }
  update() {
    this.distance += -this.speed;
    this.angle += .01;
    this.x = this.canvas.width / 2 + Math.cos(this.angle) * this.distance;
    this.y = this.canvas.height / 2 + Math.sin(this.angle) * this.distance;
    if (this.x > this.canvas.width) {
      this.distance *= -1;
    }
    if (this.x < 0) {
      this.distance *= -1;
    }
    if (this.y > this.canvas.height) {
      this.distance *= -1;
    }
    if (this.y < 0) {
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0