canvas天女散花背景效果

代码语言:html

所属分类:背景

代码描述:canvas天女散花背景效果

代码标签: 效果

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

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

<style>
* {
  font-family: 'arial black', Helvetica, verdana, monospace, sans-serif;
  letter-spacing: 0.2rem;
  margin: 0;
  padding: 0;
  color: #FFF;
  overflow: hidden;
}

body {
  position: relative;
}

canvas#canvas {
  display: block;
  background: #FBD2D7;
}
</style>

</head>
<body translate="no">
<canvas id="canvas">Canvas not supported.</canvas>

<script>
(function () {
  'use strict';
  window.addEventListener('load', function () {
    var canvas = document.getElementById('canvas');

    if (!canvas || !canvas.getContext) {
      return false;
    }

    /********************
        Random Number
      ********************/

    function rand(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }

    /********************
        Var
      ********************/

    var ctx = canvas.getContext('2d');
    var X = canvas.width = window.innerWidth;
    var Y = canvas.height = window.innerHeight;
    var shapeNum = 1;
    var shapes = [];
    var style = {
      black: 'black',
      white: 'white',
      lineWidth: 4 };


    var colors = [
    'rgb(168, 230, 207)',
    'rgb(253, 213, 182)',
    'rgb(255, 171, 167)',
    'rgb(255, 141, 149)'];


    /********************
                             Animation
                           ********************/

    window.requestAnimationFrame =
    window.requestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function (cb) {
      setTimeout(cb, 17);
    };

    /********************
         Shape
       ********************/

    function Shape(ctx, x, y, r, i) {
      this.ctx = ctx;
      this.init(x, y, r, i);
    }

    Shape.prototype.init = function (x, y, r, i) {
      this.x = x;
      this.y = y;
      this.i = i;
      this.r = 1;
      this.ri = r;
      this.lw = 2;
      this.a = rand(0, 360);
      this.rad = this.a * Math.PI / 180;
      this.a1 = rand(0, 360);
      this.rad1 = this.a1 * Math.PI / 180;
      this.ga = Math.random();
      this.c = colors[rand(0, colors.length - 1)];
    };

    Shape.prototype.draw = function () {
      var ctx = this.ctx;
      ctx.save();
      ctx.strokeStyle = style.white;
      ctx.fillStyle = this.c;
      ctx.lineWidth = this.lw;
      ctx.translate(this.x, this.y);
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0