Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html画布笔划创建较粗的线条_Html_Canvas_Stroke - Fatal编程技术网

html画布笔划创建较粗的线条

html画布笔划创建较粗的线条,html,canvas,stroke,Html,Canvas,Stroke,这是我第一次使用stackoverflow请求帮助,所以如果我做错了什么,请告诉我。我不是以英语为母语的人,所以希望你能理解我的问题 我打算创建一个网页,可以画线。没有什么大问题。但是,我意识到每次使用stroke()绘制新线时,前面的线都会变粗。这个问题能解决吗 <html> <body> <div id="coord"></div> <canvas id="Maintheme" height="800" width="1000">&

这是我第一次使用stackoverflow请求帮助,所以如果我做错了什么,请告诉我。我不是以英语为母语的人,所以希望你能理解我的问题

我打算创建一个网页,可以画线。没有什么大问题。但是,我意识到每次使用stroke()绘制新线时,前面的线都会变粗。这个问题能解决吗

<html>
<body>
<div id="coord"></div>
<canvas id="Maintheme" height="800" width="1000"></canvas>
</body>
<script>
var canvas=document.getElementById("Maintheme");
var context=canvas.getContext('2d');
var coordinates;
var Xcoor;
var Ycoor;
var lineboolean=false;
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
canvas.addEventListener('mousemove',function(evt){
coordinates=evt.clientX+" "+evt.clientY;
Xcoor=evt.clientX;
Ycoor=evt.clientY;
document.getElementById("coord").innerHTML=coordinates;})
canvas.addEventListener('click',function(){
if (lineboolean==false){
context.moveTo(Xcoor,Ycoor);
lineboolean=true;
}
else{
context.lineTo(Xcoor,Ycoor);
context.stroke();
lineboolean=false;
}
})
</script>
</html>

var canvas=document.getElementById(“主主题”);
var context=canvas.getContext('2d');
var坐标;
var Xcoor;
var Ycoor;
var lineboolean=false;
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
canvas.addEventListener('mousemove',函数(evt){
坐标=evt.clientX+“”+evt.clientY;
Xcoor=evt.clientX;
Ycoor=evt.clientY;
document.getElementById(“coord”).innerHTML=coordinates;})
canvas.addEventListener('click',function(){
if(lineboolean==false){
moveTo(Xcoor,Ycoor);
lineboolean=true;
}
否则{
lineTo(Xcoor,Ycoor);
stroke();
lineboolean=false;
}
})

必须以context.beginPath()开始每一组新的path命令。否则,自上次beginPath之后的所有先前路径命令将与最新命令一起重新绘制。