p5实现闪耀效果

代码语言:html

所属分类:粒子

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

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

<style>
* { margin:0; padding:0; } 
html, body { width:100%; height:100%; overflow: hidden; background:black;} 
canvas { display:block; margin:auto}
#controls {
  z-index: 2;
  margin: 20px;
  position: absolute;
  top: 0; left: 0;
  color: white;
}
</style>

</head>
<body translate="no">
<div id="controls"></div>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/p5.js"></script>
<script >
let c, img, orb, goal, prev;

function setup (){
  pixelDensity(1);
  c = createCanvas(0, 0);
  colorMode(HSB, 1, 1, 1);
  windowResized();
  rectMode(CENTER);
}

let init = () => {
  orb = {
    x:random(width),
    y:random(height),
    dir:1,
  }
  prev  = {...orb};
  goal = {
    x : random(width/2) + width/4,
    y : random(height/2) + height/4,
  }  
}


let orbit = () => {
  prev  = {...orb};
  let a = atan2(orb.y-goal.y, orb.x-goal.x);
  let d = dist(orb.x, orb.y, goal.x, goal.y);
  a += .05*orb.dir;
  d *= .98;
  orb.x = goal.x + cos(a)*d;
  orb.y = goal.y + sin(a)*d;
  
  if (random() < .05){
    goal = {
    x : random(width/2) + width/4,
    y .........完整代码请登录后点击上方下载按钮下载查看

网友评论0