canvas实现自定义数字形状象形字效果代码
代码语言:html
所属分类:布局界面
代码描述:canvas实现自定义数字形状象形字效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body, html { margin: 0; overflow: hidden; } canvas { display: block; cursor: pointer; } </style> </head> <body > <canvas id="canvas"></canvas> <script > /* Johan Karlsson, 2022 https://twitter.com/DonKarlssonSan MIT License, see Details View Try resizing the window! Inspiration: https://en.wikipedia.org/wiki/Cistercian_numerals */ 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 drawSymbol(x0, y0, xstep, ystep, width, height, linesToDrawFactor) { const maxNr = 42; const minNr = (1 - y0 / h) * 15; //const nr = linesToDrawFactor * maxNr; const nr = randomInt(minNr, maxNr); for(let i = 0; i < nr; i++) { const x1 = randomInt(width) * xstep; const y1 = randomInt(height) * ystep; const x2 = x1 + randomInt(-1, 1) * xstep; const y2 = y1 + randomInt(-1, 1) * ystep; drawLine(x0+x1, y0+y1, x0+x2, y0+y2); } } function drawLine(x1, y1, x2, y2) { ctx.beginPath(); ctx.moveTo(x1, y1); ctx.line.........完整代码请登录后点击上方下载按钮下载查看
网友评论0