常州网络公司鼎豪网络网站建设,wordpress回复旧版本,武进网站建设咨询,wordpress打包主题查看专栏目录 canvas示例教程100专栏#xff0c;提供canvas的基础知识#xff0c;高级动画#xff0c;相关应用扩展等信息。canvas作为html的一部分#xff0c;是图像图标地图可视化的一个重要的基础#xff0c;学好了canvas#xff0c;在其他的一些应用上将会起到非常重…
查看专栏目录 canvas示例教程100专栏提供canvas的基础知识高级动画相关应用扩展等信息。canvas作为html的一部分是图像图标地图可视化的一个重要的基础学好了canvas在其他的一些应用上将会起到非常重要的帮助。 文章目录 示例效果图示例源代码共109行canvas基本属性canvas基础方法 如何使用canvas绘制网格线呢方法其实很简单就是绘制一些等距间隔的横线和竖线形成一个网格。通常在地图的绘制当中会用到下面是大剑师的一个示例供参考
示例效果图 示例源代码共109行 /*
* Author: 大剑师兰特xiaozhuanlan还是大剑师兰特CSDN
* 此源代码版权归大剑师兰特所有可供学习或商业项目中借鉴未经授权不得重复地发表到博客、论坛问答git等公共空间或网站中。
* Email: 2909222303qq.com
* weixin: gis-dajianshi
* First published in CSDN
* First published time: 2024-01-02
*/
templatediv classdjs_containerdiv classtoph3canvas绘制网格线/h3div大剑师兰特, 还是大剑师兰特gis-dajianshi/divh4el-button typeprimary sizemini clickdraw()绘制/el-button/h4/divdiv classdajianshi canvas iddajianshi refmycanvas width980 height490/canvas/div/div
/template
scriptexport default {data() {return {ctx: null,canvas: null,}},mounted() {this.setCanvas()},methods: {setCanvas() {this.canvas document.getElementById(dajianshi);if (!this.canvas.getContext) return;this.ctx this.canvas.getContext(2d);},draw() {this.drawGrid(this.ctx, 0, 0, 50, 980, 490, 50, orange);},// 参数说明:// ctx:画布// x1:起始x位置// y1:起始y位置// step1:横向间隔// x2:终止x位置// y2:终止y位置// step1:竖向间隔// color:颜色值 drawGrid(ctx, x1, y1, step1, x2, y2, step2, color) {ctx.save();ctx.lineWidth 0.5;ctx.strokeStyle color;ctx.fillStyle color;let x, y;// 画竖线for (x x1; x x2; x step1) {ctx.beginPath();ctx.moveTo(x, y1);ctx.lineTo(x, y2);ctx.stroke();ctx.closePath();}// 画横线for(yy1;yy2;ystep2){ctx.beginPath();ctx.moveTo(x1, y);ctx.lineTo(x2, y);ctx.stroke();ctx.closePath();} ctx.restore();}}}
/scriptstyle scoped.djs_container {width: 1000px;height: 680px;margin: 50px auto;border: 1px solid green;position: relative;}.top {margin: 0 auto 0px;padding: 10px 0;background: #333;color: #fff;}.dajianshi {margin: 5px auto 0;border: 1px solid #ccc;width: 980px;height: 490px;background-color: #f9f9f9;}
/style
canvas基本属性
属性属性属性canvasfillStylefilterfontglobalAlphaglobalCompositeOperationheightlineCaplineDashOffsetlineJoinlineWidthmiterLimitshadowBlurshadowColorshadowOffsetXshadowOffsetYstrokeStyletextAligntextBaselinewidth
canvas基础方法
方法方法方法arc()arcTo()addColorStop()beginPath()bezierCurveTo()clearRect()clip()close()closePath()createImageData()createLinearGradient()createPattern()createRadialGradient()drawFocusIfNeeded()drawImage()ellipse()fill()fillRect()fillText()getImageData()getLineDash()isPointInPath()isPointInStroke()lineTo()measureText()moveTo()putImageData()quadraticCurveTo()rect()restore()rotate()save()scale()setLineDash()setTransform()stroke()strokeRect()strokeText()transform()translate()