gpt4 book ai didi

javascript - CANVAS 接收绘图点位置 - HTML5 Canvas

转载 作者:行者123 更新时间:2023-11-28 03:51:35 25 4
gpt4 key购买 nike

绘图停止后,我需要从 Canvas 接收绘图已结束的位置在 Canvas 中是否可以接收绘图点坐标?

circle

        Number.prototype.toRad = function () { return this * Math.PI / 180; }
var num = 0;
var qwerty = function(){
setTimeout(function(){
num++;
drawOnCanvas7(num);
if(num<=70){
qwerty();
}
}, 100);
}
qwerty();
function drawOnCanvas7(v){
v = parseInt(v);
v = v>100?100:v<=0?0:v;
var onePrc = 360/100;
v = v * onePrc;
var canvas2 = document.getElementById('tutorial-7');
canvas2.width = 210;
canvas2.height = 210;
var ctx = canvas2.getContext("2d");
if(ctx){
ctx.lineWidth = 5;
ctx.strokeStyle = "black";
ctx.save();
ctx.strokeStyle = "yellow";
ctx.beginPath();
ctx.arc(105, 105, 100, (0).toRad(), (v).toRad());
ctx.stroke();
}
}
canvas { 

display:block;
}
<canvas id="tutorial-7" width="100" height="100" style="transform:rotate(-90deg)">
Ваш браузер не поддерживает CANVAS
</canvas>

最佳答案

您可以将结果坐标保存在变量中,如下所示:

function drawOnCanvas7(v){
v = parseInt(v);
v = v>100?100:v<=0?0:v;
var onePrc = 360/100;
v = v * onePrc;
var canvas2 = document.getElementById('tutorial-7');
canvas2.width = 210;
canvas2.height = 210;
var ctx = canvas2.getContext("2d");
var x_end = 105 + Math.cos((v).toRad()) * 100;
var y_end = 105 + Math.sin((0).toRad()) * 100;
if(ctx){
ctx.lineWidth = 5;
ctx.strokeStyle = "black";
ctx.save();
ctx.strokeStyle = "yellow";
ctx.beginPath();
ctx.arc(105, 105, 100, (0).toRad(), (v).toRad());
ctx.stroke();
}
}

关于javascript - CANVAS 接收绘图点位置 - HTML5 Canvas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47956007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com