【发布时间】:2018-12-18 21:04:11
【问题描述】:
我无法在 HTML Canvas 上的特定点 (250,250) 旋转一条线,我想知道人们是如何做到的。我查看了其他答案并尝试了它们,但它们并没有解决我的问题。
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
function circles(){
context.beginPath();
context.arc(250,250,6.35,0,2*Math.PI);
context.stroke();
}
function lines(){
var deg = 45;
context.beginPath();
context.moveTo(250,250);
context.lineTo(250,0);
context.stroke();
context.save();
context.rotate(deg * Math.PI / 180);
context.translate(20,-25);
// This is the line I want to rotate
context.beginPath();
context.moveTo(250,250);
context.lineTo(250,0);
context.stroke();
//
context.restore();
context.beginPath();
context.moveTo(0,250);
context.lineTo(500,250);
context.stroke();
}
circles();
lines();
【问题讨论】:
标签: javascript html canvas rotation html5-canvas