Press "Enter" to skip to content

月度归档: 2021 年 12 月

canvas 让物体围绕自己中心点旋转

 canvas的旋转(rotate)是绕画布的左上角(0,0)开始旋转的,所以直接旋转无法得到想要的效果。   旋转的步骤:     1. 将(0, 0)偏移到物体的中心: ctx.translate(centerX, centerY);     2. 执行旋转: ctx.rotate(deg * Math.PI / 180)     3.偏移到物体中心负值: ctx.translate(-cen…

1 Comment