Commit efb8f64a810eddfa5274ae148717460c3b67f839

Authored by yvan.ni
1 parent 2b33e2ac

球的坐标位置的算法

Showing 1 changed file with 16 additions and 2 deletions
utils/util.js
@@ -304,10 +304,23 @@ function draw_randon_rect(ctx,x,y,r,w,h){ @@ -304,10 +304,23 @@ function draw_randon_rect(ctx,x,y,r,w,h){
304 ctx.lineTo(x, y + r) 304 ctx.lineTo(x, y + r)
305 ctx.lineTo(x + r, y) 305 ctx.lineTo(x + r, y)
306 // 这里是使用 fill 还是 stroke都可以,二选一即可,但是需要与上面对应 306 // 这里是使用 fill 还是 stroke都可以,二选一即可,但是需要与上面对应
307 - ctx.fill();  
308 - 307 + ctx.fill();
309 } 308 }
310 309
  310 +/**
  311 + * @param {Object} num 数量,最大5
  312 + * @param {Object} x 中心坐标
  313 + * @param {Object} y y中心坐标
  314 + * @param {Object} sp 圆的间隔
  315 + * @param {Object} r 圆的半径
  316 + */
  317 +function get_box_arr(num,x,y,sp,r){
  318 + if(num==1) return [{x:x,y:y}];
  319 + if(num==2) return [{x:x-sp/2-r,y:y},{x:x+sp/2+r,y:y}];
  320 + if(num==3) return [{x:x-sp-2*r,y:y},{x:x,y:y},{x:x+sp+2*r,y:y}];
  321 + if(num==4) return [{x:x-sp/2-r-sp-2*r,y:y},{x:x-sp/2-r,y:y},{x:x+sp/2+r,y:y},{x:x+sp/2+r+sp+2*r,y:y}];
  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 +}
311 324
312 function null_promise(){ 325 function null_promise(){
313 var promise=new Promise(function(resolve, reject){ var ob={code:-1,data:null}; resolve(ob); }); return promise; 326 var promise=new Promise(function(resolve, reject){ var ob={code:-1,data:null}; resolve(ob); }); return promise;
@@ -411,4 +424,5 @@ module.exports = { @@ -411,4 +424,5 @@ module.exports = {
411 getDistance:getDistance, //获取俩个经纬网度之间的距离 424 getDistance:getDistance, //获取俩个经纬网度之间的距离
412 draw_randon_rect:draw_randon_rect ,//画图画圆角矩形 425 draw_randon_rect:draw_randon_rect ,//画图画圆角矩形
413 null_promise:null_promise,//返回空的promise 426 null_promise:null_promise,//返回空的promise
  427 + get_box_arr:get_box_arr,//返回圆的数组
414 }; 428 };