| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- Page({
- data:{
- sf:0
- },
- onLoad() {
- const query = wx.createSelectorQuery()
- query.select('#myCanvas')
- .fields({
- node: true,
- size: true
- })
- .exec((res) => {
- const canvas = res[0].node
- canvas.width = res[0].width
- canvas.height = res[0].height
- const ctx = canvas.getContext('2d');
- // 缩放率=》实际隧道宽度1264,后台有传?
- // 为居中减少宽度10
- const cw = res[0].width-10
- const sw = cw / 1264
- this.setData({
- sf:sw
- })
- /** 炮孔示意图 start */
- // 画弧=>需要后台传每个圆弧的半径+起始弧度
- ctx.beginPath()
- ctx.arc(...this.drawArc(632,cw,Math.PI,2*Math.PI))
- ctx.stroke()
- ctx.beginPath()
- ctx.arc(...this.drawArc(400,cw,Math.PI,2*Math.PI))
- ctx.stroke()
- // 画炮孔=》后台传坐标
- ctx.beginPath()
- ctx.arc(...this.drawPi(0,632))
- ctx.stroke()
- ctx.beginPath()
- ctx.arc(...this.drawPi(632,632))
- ctx.stroke()
- ctx.beginPath()
- ctx.arc(...this.drawPi(1264,632))
- ctx.stroke()
- ctx.beginPath()
- ctx.arc(...this.drawPi(500,632))
- ctx.stroke()
-
- ctx.beginPath()
- ctx.arc(...this.drawPi(500,500))
- ctx.stroke()
- // 直线=》后台传坐标
- ctx.moveTo(...this.drawLine(500,632))
- ctx.lineTo(...this.drawLine(500,500))
- ctx.stroke()
- /** 炮孔示意图 end */
- /** 炮孔俯视图 start*/
- ctx.moveTo(...this.drawLine(50,800))
- ctx.lineTo(...this.drawLine(65,1100))
- ctx.stroke()
- ctx.moveTo(...this.drawLine(200,800))
- ctx.lineTo(...this.drawLine(200,1100))
- ctx.stroke()
- ctx.moveTo(...this.drawLine(300,800))
- ctx.lineTo(...this.drawLine(300,1100))
- ctx.stroke()
- ctx.moveTo(...this.drawLine(400,800))
- ctx.lineTo(...this.drawLine(400,1100))
- ctx.stroke()
- ctx.moveTo(...this.drawLine(700,800))
- ctx.lineTo(...this.drawLine(500,1100))
- ctx.stroke()
- ctx.moveTo(...this.drawLine(50,1100))
- ctx.lineTo(...this.drawLine(1200,1100))
- ctx.stroke()
- })
- },
- /**
- * 画圆弧s
- * @param {*} arcR 圆弧实际半径
- * @param {*} cw canvas 宽度
- * @param {*} sPi 起始弧度
- * @param {*} ePi 终止弧度
- */
- drawArc(arcR,cw,sPi,ePi){
- // 缩放倍数
- const sw =this.data.sf * arcR
- const arc = [cw/2+5,cw/2+5,sw,sPi,ePi]
- return arc
- },
- /**
- * 炮孔
- * @param {*} x 实际坐标
- * @param {*} y 实际坐标
- * @param {*} r 炮孔半径默认2
- */
- drawPi(x,y,r=2){
- // 缩放倍数
- const sw =this.data.sf
- const arc = [x*sw+5, y*sw+5, r, 0, 2 * Math.PI]
- return arc
- },
- /**
- * 直线
- * @param {*} x 实际坐标
- * @param {*} y 实际坐标
- */
- drawLine(x,y){
- // 缩放倍数
- const sw =this.data.sf
- const arc = [x*sw+5, y*sw+5]
- return arc
- }
- })
|