jquery实现canvas逼真树木变化效果代码
代码语言:html
所属分类:其他
代码描述:jquery实现canvas逼真树木变化效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { width: 100%; height: 100%; } #sky { width: 100%; height: 100%; } canvas { position: absolute; top: 0; left: 0; } </style> </head> <body> <!-- partial:index.partial.html --> <div id='sky' class='linearBg'></div> <canvas id="mycanvas"></canvas> <!-- partial --> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script> var drawTree = function (ctx, startX, startY, length, angle, depth, branchWidth) { var rand = Math.random, newLength, newAngle, newDepth, maxBranch = 3, endX, endY, maxAngle = 2 * Math.PI / 4, subBranches, lenShrink; ctx.beginPath(); ctx.moveTo(startX, startY); endX = startX + length * Math.cos(angle); endY = startY + length * Math.sin(angle); ctx.lineCap = 'round'; ctx.lineWidth = branchWidth; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0