简体   繁体   English

画布绘制到不画线

[英]Canvas Draw To is not drawing line

I have built a function in javascript to draw to and from set points on the canvas. 我已经在javascript中建立了一个函数,可以在画布上的设定点之间来回绘制。 All of my points work correctly expect c. 我的所有观点都能正常工作c。 If I try to draw a line from any point to c it does not work. 如果我试图从任意点到c画一条线,那是行不通的。

Javascript Java脚本

var a = {x:0, y:0};
var b = {x:350, y:0};
var c = {x:0, y:350};
var d = {x:350, y:350};
var e = {x:100, y:100};
var f = {x:100, y:250};
var g = {x:250, y:250};
var h = {x:250, y:100};

function drawLine(a, b)
{
ctx.beginPath();
ctx.moveTo(a.x,a.y);
ctx.lineTo(b.x,b.y);
ctx.stroke();
}
drawLine(d, c);

Why do all points work expect c???? 为什么所有积分都期望c?

From this, I am guessing the width and the height of the canvas is 350. 由此,我猜测画布的宽度和高度为350。

Assuming that, they are working. 假设,他们正在工作。 Its just being drawn on the border. 它只是在边界上绘制。 You're trying to go from {x:0, y:350} to {x:350, y:350} . 您正在尝试从{x:0, y:350}转到{x:350, y:350} Notice how the y for both is 350 . 请注意,两者的y均为350 This means it will draw from the bottom,left corner to the bottom,right corner, exactly staying at y : 350 , which is the border. 这意味着它将从画bottom,left角落的bottom,right角球,正好住在y : 350 ,这是边界。 So therefore you will not be able to see it. 因此,您将无法看到它。

Try changing var c = {x:0, y:350}; 尝试更改var c = {x:0, y:350}; to var c = {x:0+5, y:350-5}; var c = {x:0+5, y:350-5}; , leaving it at {x:5, y:345} . ,将其保留在{x:5, y:345} And you will notice that for point c the lines now show, but very very close to the border. 您会注意到,对于c点,线现在显示了,但非常靠近边界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM