P5实现鼠标跟随散布动画效果

代码语言:html

所属分类:粒子

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Plibt</title>
<style>
    html, body {
  margin: 0;
  padding: 0;
}

.gif-wrapper {
  position: absolute;
  top: 0;
  left: 0;
}
  </style>

</head>
<body translate="no">
<html>
<head>
<script src="http://repo.bfw.wiki/bfwrepo/js/p5.min.js"></script>


</head>
<body>
<div class="gif-wrapper">
</div>
</body>
</html>

<script>
const NUM_POINTS_IN_SPRAY = 3;
const LIFE_DECAY_RATE = 2;
const STARTING_LIFE_VAL = 255;
let pointsArr = [];

//////////////
//  SETUP
/////////////
function setup() {
  createCanvas(window.innerWidth, window.innerHeight);

 
}

//////////////
//  DRAW
/////////////
function draw() {
  background(map(mouseX, 0, windowWidth, 150, 255));
  
  // text('pointsArr.length:  ' + pointsArr.length, 10, 90);
  
  // add new points if user is moving mouse
  if(pmouseY !== mouseX && pmouseY !== mouseY) {
    for(let i = 0; i < NUM_POINTS_IN_SPRAY; i++) {
      pointsArr.push(new Point(mouseX, mouseY));
    }
  }
    
  begin.........完整代码请登录后点击上方下载按钮下载查看

网友评论0