canvas实现多种树叶铺满屏幕效果代码

代码语言:html

所属分类:其他

代码描述:canvas实现多种树叶铺满屏幕效果代码,点击切换效果。

代码标签: canvas树叶 铺满 屏幕

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

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

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

<style>
    body {
  height: 100vh;
  width: 100vw;
  overflow:hidden;
}

canvas {
  height: 100vh;
  width: 100vw;
}
</style>

</head>

<body>
 
    <canvas id="canvas"></canvas>
 
    <script>
        (function () {

  //fields
  var canvas = document.getElementById("canvas");
  var body = document.getElementsByTagName("body")[0];
  var positions = []
  var ctx = canvas.getContext("2d");
  
  /*Initialize flowers*/
  body.addEventListener("click",function(ev){
    drawFlowers(false)
  })
  window.onload = ()=>{drawFlowers(true)}
  window.onresize = ()=>{drawFlowers(false)}

  /*Flower flunctions*/
  function Flower(opt) {
   
    this.r = opt.allowLarge && chance(.05) ? getRandomInt(50,150) : getRandomInt(20,50)
    this.x = getRandomInt(0, canvas.width)
    this.y = getRandomInt(0, canvas.height)

    this.lw = 4;    
    this.angle = getRandomInt(-30,30)
    this.rad = this.angle * (Math.PI / 180) /*FLOWER ROTATION*/
    this.opacity = 1;
    this.petals = chance(.03) ? 4 : 3;
    this.shiftOut = this.petals == 4 ? 0 : 0
    this.petalBase = 0;
    this.petalSpread1 = getRandomFloat(opt.minSpread, opt.maxSpread)
    this.petalLength1 = this.petalSpread1 * getRandomFloat(1.4, 1.8).........完整代码请登录后点击上方下载按钮下载查看

网友评论0