Commit ed556564d6e6636bd308543368a35a92d0991f09
1 parent
2867828d
画圆的方法封装
Showing
1 changed file
with
23 additions
and
0 deletions
utils/util.js
| ... | ... | @@ -322,6 +322,28 @@ function get_box_arr(num,x,y,sp,r){ |
| 322 | 322 | if(num==5) return [{x:x-2*sp-4*r,y:y},{x:x-sp-2*r,y:y},{x:x,y:y},{x:x+sp+2*r,y:y},{x:x+2*sp+4*r,y:y}]; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | +/** | |
| 326 | + * @param {Object} ctx 画图句柄 | |
| 327 | + * @param {Object} x x坐标 | |
| 328 | + * @param {Object} y y坐标 | |
| 329 | + * @param {Object} img 画的图片 | |
| 330 | + * @param {Object} color 边框的颜色 | |
| 331 | + */ | |
| 332 | + | |
| 333 | +function draw_circle(ctx,x,y,r,img,color,unit){ | |
| 334 | + ctx.save(); | |
| 335 | + ctx.beginPath(); //开始绘制 | |
| 336 | + ctx.arc(x,y,r,0,2 * Math.PI); | |
| 337 | + ctx.setLineWidth(4 * unit); | |
| 338 | + ctx.setStrokeStyle('red'); | |
| 339 | + ctx.setFillStyle("white"); | |
| 340 | + ctx.fill(); | |
| 341 | + ctx.clip(); | |
| 342 | + ctx.drawImage(img,x-r,y-r,2*r,2*r); | |
| 343 | + ctx.restore(); | |
| 344 | +} | |
| 345 | + | |
| 346 | + | |
| 325 | 347 | function null_promise(){ |
| 326 | 348 | var promise=new Promise(function(resolve, reject){ var ob={code:-1,data:null}; resolve(ob); }); return promise; |
| 327 | 349 | } |
| ... | ... | @@ -425,4 +447,5 @@ module.exports = { |
| 425 | 447 | draw_randon_rect:draw_randon_rect ,//画图画圆角矩形 |
| 426 | 448 | null_promise:null_promise,//返回空的promise |
| 427 | 449 | get_box_arr:get_box_arr,//返回圆的数组 |
| 450 | + draw_circle:draw_circle,//绘制圆 | |
| 428 | 451 | }; | ... | ... |