生长背景动画效果
代码语言:html
所属分类:背景
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> substrate travel</title> <style> canvas, body{ padding: 0; margin: 0; overflow: hidden; } </style> </head> <body translate="no"> <script src='http://repo.bfw.wiki/bfwrepo/js/dat.gui.min.js'></script> <script> var width, height; var step = 0; var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var bg = [256, 256, 256]; document.getElementsByTagName('body')[0].appendChild(canvas); ctrl = { // spring: 0.35, // ease: 0.84, // strokeMax: 10, chanceToSplit: 0.2, num: 50, max: 1500, // alpha: 1, fade: 0.3, draw: true, clear: function () {removeTravelers(), clear(ctx);} }; var numAngles = 6; var angles = []; for (var i = 0; i < numAngles; i++) { angles.push(Math.PI * 2 / numAngles * i - Math.PI / 2); } document.onmousedown = function (e) { // var a = Math.random() * Math.PI * 2 var a = angles[Math.floor(Math.random() * angles.length)]; var s = 3; var vx = Math.cos(a) * s; var vy = Math.sin(a) * s; addTraveler(e.pageX, e.pageY, vx, vy); }; var gui = new dat.GUI(); gui.add(ctrl, 'num', 0, 150).step(1); gui.add(ctrl, 'max', 1, 3000).step(1); gui.add(ctrl, 'chanceToSplit', 0, 1); // gui.add(ctrl, 'ease', 0, 1); // gui.add(ctrl, 'alpha', 0, 1); // gui.add(ctrl, 'strokeMax', 1, 50).step(1); // gui.add(ctrl, 'strokeMin', 0, 50).step(1); gui.add(ctrl, 'fade', 0, 1).step(0.1); gui.add(ctrl, 'draw'); gui.add(ctrl, 'clear'); gui.closed = true; window.addEventListener('resize', setup); setup(); function setup() { canvas.width = width = window.innerWidth; canvas.height = height = window.innerHeight; ctx.beginPath(); ctx.rect(0, 0, width, height); ctx.fillStyle = `rgba(${bg[0]}, ${bg[1]}, ${bg[2]}, ${1})`; ctx.fill(); } function Traveler(ctx, x, y, vx, vy) { this.x = x; this.y = y; this.x1 = x; this.y1 = y; this.vx = vx; this.vy = vy; this.ctx = ctx; // this.p = Math.random() * 0.3 + 0.1 this.step = 0; this.active = true; this.draw = function () { if (this.active) { ctx.beginPath(); ctx.lineWidth = 0.8; ctx.strokeStyl.........完整代码请登录后点击上方下载按钮下载查看
网友评论0