canvas实现彩色小球喷射鼠标悬浮躲避粒子动画交互效果代码

代码语言:html

所属分类:粒子

代码描述:canvas实现彩色小球喷射鼠标悬浮躲避粒子动画交互效果代码

代码标签: canvas 彩色 小球 喷射 鼠标 悬浮 躲避 粒子 动画 交互

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
* {
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  font-family: Arial;
}

.circle {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: black;
}

h4 {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: none;
}
</style>


  
  
</head>

<body >
  <h4>play with 'em!</h4>

  
      <script>
let centerVec, mouseVec;
let total = 200;
let initialForce = 2;
let friction = .8;
let springForce = 1;
let k = 0.1;
let mouseThreshold = 60;
let mouseRepelForce = 0.1;
let forceToCenter = 0.008;
let minDist = 25;
let minDistSQ = minDist * minDist;
let particles = [];
let count = 0;
let instructionVisible = false;

function init() {
  centerVec = new Vector(window.innerWidth / 2, window.innerHeight / 2);
  mouseVec = new Vector();

  window.addEventListener("mousemove", inputMove);
  window.addEventListener("touchmove", inputMove, { passive: false });
  window.addEventListener("resize", resize);

  update();
}

function inputMove(.........完整代码请登录后点击上方下载按钮下载查看

网友评论0