canvas立体层次效果圆形背景效果
代码语言:html
所属分类:背景
代码描述:canvas立体层次效果圆形背景效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> body, html { margin: 0; } canvas { display: block; cursor: pointer; } </style> </head> <body translate="no"> <canvas id="canvas"></canvas> <script > /* Johan Karlsson, 2020 https://twitter.com/DonKarlssonSan MIT License, see Details View */ let canvas; let ctx; let w, h; function setup() { canvas = document.querySelector("#canvas"); ctx = canvas.getContext("2d"); resize(); window.addEventListener("resize", () => { resize(); draw(); }); canvas.addEventListener("click", draw); } function resize() { w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight; } function draw() { ctx.fillRect(0, 0, w, h); ctx.strokeStyle = "white"; ctx.shadowColor = "black"; ctx.shadowOffsetX = 8; ctx.shadowOffsetY = 8; ctx.shadowBlur = 20; let size = Math.random() * 80 + 20; let positions = getPositions(size); drawRects(positions, size); } function getPositions(size) { let positions = []; positions.push({ x: w / 2, y: h / 2, color: "hsl(220, 60%, 50%)", angle: 0 }); let randomAngleOffset = Math.random() * 360; let nrOfCircles = Math.max(w, h) * 0.7 / size; for(let circle = 0; circle < nrOfCircles; circle++) { let r = (circle + 1) * size; let points = r * 8 / size; let deltaAngle = Math.PI * 2 / points; let offsetAngle = Math.random() * Math.PI; for(let angle = 0; angle < Math.PI * 2; angle += deltaAngle) { let hue = angle / Math.PI / 2 * 360 + randomAngleOffset; let l = Math.random() * 40 + 30; let color = `hsl(${hue}.........完整代码请登录后点击上方下载按钮下载查看
网友评论0