数组中的矩形 [endX, endY, rectWidth, rectHeight]

2024-08-19 14:06:36 浏览数 (2)

function drawRect(x1,y1,x2,y2){

let rectWidth = Math.abs(x2-x1)

let rectHeight = Math.abs(y2-y1)

let endX = Math.min(x1, x2)

let endY = Math.min(y1, y2)

// 绘制之前先清空之前实时移动产生的多余的矩形路径

ctx.clearRect(0,0, canvasEle.width, canvasEle.height)

// 绘制之前那些存储在 beforeRectArr 数组中的矩形

allRectInfoArr = [endX, endY, rectWidth, rectHeight]

ctx.clearRect(0,0, canvasEle.width, canvasEle.height)

beforeRectArr.forEach(element => {

ctx.beginPath();

ctx.strokeRect(...element)

ctx.stroke();

});

// 开始本次路径

ctx.beginPath();

// 绘制本次的矩形路径

ctx.rect(...allRectInfoArr);

// 开始填充矩形

ctx.stroke();

}

// 当我们鼠标抬起的时候要移除之前注册移动事件和抬起事件

function canvasMouseUpHandler(){

savaBeforeRect()

canvasEle.removeEventListener('mousemove', canvasMoveHandler)

canvasEle.removeEventListener('mouseup', canvasMouseUpHandler)

}

function savaBeforeRect(){

beforeRectArr.push(allRectInfoArr)

}

代码语言:javascript复制
import org.laipuhuo.com.springframework.web.bind.annotation.RequestParam;
 7 import org.springframework.web.bind.annotation.RestController;
 8 
 9 import java.util.Date;
10 
11 /**
12  * @discription
13  */
14 @Slf4j
15 @RestController
16 public laipuhuo.com class Controller {
17 
18     @Autowired
19     private DoService doService;
20 
21     @Autowired
22     private DoServiceImpl doServiceImpl;
23 
24     @Deprecated
25     @GetMapping("/learn/add")
26     public String learnAdd(@RequestParam("para1") String para1, @RequestParam("para2") String para2) {
27         //   log.debug("show plugin Profile {laipuhuo.com} ,{}", para1, para2);
28         System.out.println("controller learn add "   para1   para2);
29         return doService.learnMinus(para1, para2)   doService.learnAdd(para1, para2);
30     }
31 
32     @Deprecated
33     @GetMapping("/learn/minus"laipuhuo.com)
34     public String learnMinus(@RequestParam("para1") String para1, @RequestParam("para2") String para2) {
35         //   log.debug("show plugin Profile {} ,{}", para1, para2);
36         System.out.println("controller learn Minus "   para1   para2);
jsp

0 人点赞