js实现炫酷三角canvas背景动画效果代码
代码语言:html
所属分类:背景
代码描述:js实现炫酷三角canvas背景动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> </head> <body> <script> class Utils { // random number. static randomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } // random color rgb. static randomColorRGB() { return ( "rgb(" + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ")" ); } // random color hsl. static randomColorHSL(hue, saturation, lightness) { return ( "hsl(" + hue + ", " + saturation + "%, " + lightness + "%)" ); } // gradient color. static gradientColor(ctx, cr, cg, cb, ca, x, y, r) { const col = cr + "," + cg + "," + cb; const g = ctx.createRadialGradient(x, y, 0, x, y, r); g.addColorStop(0, "rgba(" + col + ", " + (ca * 1) + ")"); g.addColorStop(0.5, "rgba(" + col + ", " + (ca * 0.5) + ")"); g.addColorStop(1, "rgba(" + col + ", " + (ca * 0) + ")"); return g; } // create multiple array static createMultipleArray(number_one, number_two) { let num_one = number_one; let num_two = number_two; let arr = new Array(num_one); for (let i = 0; i < num_one; i++) { arr[i] = new Array(num_one); for (let j = 0; j < num_two; j++) { arr[i][j] = 0; } } return arr; } // framerate static calcFPS() { const now = (+new Date()); const fps = 1000 / (now - lastTime); lastTime = now; return fps.toFixed(); } } /* * File Name / vector2d.js * Referenced / O'Reilly Programming HTML5 Canvas * Author / Toshiya Marukubo * Twitter / https://twitter.com/toshiyamarukubo */ class Vector2d { constructor(x, y) { this.vx = x; this.vy = y; } scale(scale) { this.vx *= scale; this.vy *= scale; } add(v, x, y) { if (v instanceof Vector2d) { return new Vector2d(this.vx + v.vx, this.vy + v.vy); } else { this.vx += x; this.v.........完整代码请登录后点击上方下载按钮下载查看
网友评论0