JavaScript,html5,canvas,画布,删除块区域
web前端-js教程
外卖平台源码2017,vscode常用的主题,ubuntu查看hba,tomcat下载中文乱码,安卓一定用sqlite吗,爬虫scray,crm客户管理系统php,长沙抖音seo培训,html静态个人网站模板,理财单页模板lzw
运行效果截图如下:学校教育网站php源码,ubuntu下安装vi,爬虫headers怎么使用,无限php,玉田优化seolzw
附:图中,黑色小方块即为删除掉的块区域url编码解码源码,vscode关闭后自动更新,ubuntu 只有 分区,tomcat400异常,excel爬虫json,php怎么传值给js,互联网seo优化排名靠前lzw
具体代码如下:index.html:
canvas.js:canvas中删除一块区域 #canvas { background:black; margin-top:100px; margin-left:200px; } cache = {}; var offsetX = 50, offsetY = 20; cache.context = dyl.createContext('canvas'); dyl.rect(dyl.createColor(), 150, 150, 200, 200, 0.5); for(var i=0; i<10; i++) { dyl.clearRect(150 + i*20, 150 + i*20, 20, 20); }
(function() { var dyl = {cache: {}}; dyl.setContext = function(context) { dyl.cache._context = context; return context; }; dyl.getDom = function(id) { return document.getElementById(id); }; dyl._getContext = function() { return dyl.cache._context; }; dyl.save = function() { var context = dyl._getContext(); context ? context.save() : void(0); }; dyl.restore = function() { var context = dyl._getContext(); context ? context.restore() : void(0); }; dyl.createContext = function(canvasID) { var canvas = this.getDom(canvasID); if(!canvas) { return null; } return dyl.setContext(canvas.getContext("2d")); }; dyl.createColor = function() { var color = "rgb("; color += Math.round(Math.random()*255); color += ","; color += Math.round(Math.random()*255); color += ","; color += Math.round(Math.random()*255); color += ")"; return color; }; dyl.addImg = function(img, x, y) { var context = dyl._getContext(); if(!img || !context) { return; } if(typeof img === "string") { var oImg = new Image(); oImg.src = img; oImg.onload = function() { context.drawImage(oImg, x, y); } return; } context.drawImage(img, x, y); }; dyl.rect = function(color, x, y, width, height, alpha) { var context = dyl._getContext(); if(!context) { return; } context.save(); context.fillStyle = color; context.globalAlpha = alpha ? alpha : 1; context.fillRect(x, y, width, height); context.restore(); }; dyl.circle = function(color, x, y, r, alpha) { var context = dyl._getContext(); context.save(); context.fillStyle = color; context.beginPath(); context.globalAlpha = alpha ? alpha : 1; context.arc(x, y, r, 0, 2*Math.PI); context.fill(); context.stroke(); }; dyl.clearRect = function(x, y, width, height) { var context = dyl._getContext(); if(!context) { return; } context.clearRect(x, y, width, height); }; dyl.scale = function(x, y) { var context = dyl._getContext(); if(!context) { return; } x = x ? x : 1; y = y ? y : 1; context.scale(x, y); }; if(!window.dyl) { window.dyl = dyl; }})();