js实现canvas图案炫光动画效果代码
代码语言:html
所属分类:动画
代码描述:js实现canvas图案炫光动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { padding: 0; margin: 0; overflow: hidden; } </style> <script> window.console = window.console || function(t) {}; </script> <script> if (document.location.search.match(/type=embed/gi)) { window.parent.postMessage("resize", "*"); } </script> </head> <body > <script > // Referenced / https://tomari.org/main/java/kyokusen/top.html // Thank you so much. var W, M, c, C, WW, WH, CW, CH, depth, angle, length, startX, startY, pos, mx, my, radian, animationId; var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }; var makeCanvas = function () { document. getElementsByTagName("body")[0]. appendChild(document.createElement("canvas")); }; var initialize = function () { W = window; M = Math; c = document.getElementsByTagName("canvas")[0]; C = c.getContext("2d"); WW = c.width = M.floor(W.innerWidth); WH = c.height = M.floor(W.innerHeight); CW = WW / 2; CH = WH / 2; depth = 5; length = 15; angle = 0; radian = 0; startX = CW - length * 31 / 2; startY = CH - length * 31 / 2; mx = 0; my = 0; pos = []; c.style.background = 'black'; fractal(90, depth); }; var getCoordinate = function () { var rad = angle * Math.PI / 180; var nx = M.cos(rad) * length + startX; var ny = M.sin(rad) * length + startY; var middlex = M.cos(rad) * (length / 2) + startX; var middley = M.sin(rad) * (length / 2) + startY; var dx = nx - CW; var dy = ny - CH; var dist = M.sqrt(dx * dx + dy * dy) * 0.01; var atan = M.atan2(dy, dx); pos.push([startX, startY, nx, ny, dist, atan, middlex, middley]); startX = nx; startY = ny; }; var turn = function (increaseNumber) { angle += increaseN.........完整代码请登录后点击上方下载按钮下载查看
网友评论0