欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
HTML代码
 
html部分代码比较简单,引入了一个<div>块,设置了CSS样式
 
<!DOCTYPE html>
 
<html lang="en" >
 
<head>
 
<meta charset="UTF-8">
 
<title>HTML5 Canvas千纸鹤动画特效</title>
 
<link rel="stylesheet" href="css/style.css">
 
</head>
 
<body>
 
<div id="controls"></div>
 
<script src='js/p5.min.js'></script>
 
<script src="js/index.js"></script>
 
</body>
 
</html>
 
CSS代码
 
* { margin:0; padding:0; } 
 
html, body { width:100%; height:100%; overflow: hidden; background:black;} 
 
canvas { display:block; }
 
#controls {
 
  z-index: 2;
 
  margin: 20px;
 
  position: absolute;
 
  top: 0; left: 0;
 
  color: white;
 
}
 
js部分代码
 
index.js
 
function randColor(base = 0, amt=.2){
 
  return [(base+random(amt)-amt/2)%1, .2 + random(amt), .8 + random(amt)];
 
}
 
function setup (){
 
  pixelDensity(1);
 
  createCanvas();
 
  colorMode(HSB, 1, 1, 1);
 
  windowResized();
 
}
 
function init(){
 
  birds = [];
 
  for (let i = 0; i < numBirds; i++) birds.push(new Bird());
 
  birds = birds.sort((a,b) => a.size - b.size);
 
}
 
function draw(){
 
  background(0, .5);
 
  birds.map(b => b.render());
 
}
 
function mousePressed(){windowResized();}
 
function windowResized(){
 
  resizeCanvas(windowWidth, windowHeight); 
 
  init();
 
}

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64227.shtml