0
我在畫布上畫了一個圓,並在邊框附近放置了一個圖像。現在我絕對沒有想法..我想拖動圖片周圍的圖像,但箭頭圖像的頂部應該始終在邊框上。 例如:我從九點鐘的頂部向左拖動箭頭。現在箭頭圖像需要旋轉90度。拖動在圓形內移動圖像(圓形移動)
http://jsfiddle.net/L5twk3ak/1/
canvas = document.getElementById('test');
var context = canvas.getContext("2d");
var points = [];
var radius = 55;
imageBG = new Image();
imageBG.onload = function() {context.drawImage(imageBG, 148, 100, 15, 15);};
imageBG.src = 'https://www.nanamee.com/upload/images/5945/5945_p.jpg';
for(var degree = 0; degree < 360; degree++)
{
\t var radians = degree * Math.PI/179;
\t var x = 150 + radius * Math.cos(radians);
\t var y = 150 + radius * Math.sin(radians);
\t points.push({x : x, y : y});
}
context.beginPath();
context.moveTo(points[0].x + 4, points[0].y + 4)
for(var i = 1; i < points.length; i++)
{
\t var pt = points[i];
\t \t \t
\t context.lineTo(pt.x + 4, pt.y + 4);
}
context.strokeStyle = "black";
context.lineWidth = 1;
context.stroke(); \t
context.closePath();
<canvas id="test" width="400" height="400">Your browser does not support the HTML5 canvas tag.</canvas>
我不明白的是:爲什麼你沒有這樣做:http://jsfiddle.net/L5twk3ak/2/(使用簡單的** arc **);你的代碼在哪裏聽畫布內的鼠標位置?你的拖曳活動在哪裏?數學在哪裏? – 2015-01-04 14:55:20