Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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
如何使用ctx html在线填充颜色?_Html_Html5 Canvas - Fatal编程技术网

如何使用ctx html在线填充颜色?

如何使用ctx html在线填充颜色?,html,html5-canvas,Html,Html5 Canvas,请检查此链接 . 我正在创建相同的图表,但所有的线条和几何形状都是动态的。线条中有黑色和红色的组合(看起来像条纹)想要相同的颜色。 我的代码 您需要在调用stroke方法之前创建路径: canvas = document.getElementById("canvas"); ctx = canvas.getContext("2d"); ctx.fillStyle = 'blue'; ctx.strokeStyle = 'blue'; //

请检查此链接 . 我正在创建相同的图表,但所有的线条和几何形状都是动态的。线条中有黑色和红色的组合(看起来像条纹)想要相同的颜色。 我的代码


您需要在调用stroke方法之前创建路径:

 canvas =     document.getElementById("canvas");
 ctx = canvas.getContext("2d");
 ctx.fillStyle = 'blue';
 ctx.strokeStyle = 'blue';
 //point 0, 0
 ctx.moveTo(0, 0);
 //to point 300, 150
 ctx.lineTo(300, 150);
 ctx.closePath();

 ctx.stroke();
 ctx.fill();
您可以更改线宽并添加阴影。看看我的项目:


如果这些评论对你有帮助,请在我的答案中投票

您需要在调用stroke方法之前创建路径:

 canvas =     document.getElementById("canvas");
 ctx = canvas.getContext("2d");
 ctx.fillStyle = 'blue';
 ctx.strokeStyle = 'blue';
 //point 0, 0
 ctx.moveTo(0, 0);
 //to point 300, 150
 ctx.lineTo(300, 150);
 ctx.closePath();

 ctx.stroke();
 ctx.fill();
您可以更改线宽并添加阴影。看看我的项目:


如果这些评论对你有帮助,请在我的答案中投票

> P>你可能想考虑创建一个模式。您可以从图像或屏幕外画布创建它。下面是第二种方法的快速演示:


画布中关于模式创建的更多信息:

你可能想考虑创建一个模式。您可以从图像或屏幕外画布创建它。下面是第二种方法的快速演示:


关于在html画布中创建图案的更多信息:

非常感谢我想这样做,但面临另一个问题在这种情况下,在某些位置它不起作用。你能给我更多的细节吗?我不确定我understood@AkshayBhardwaj希望我能理解你的意思。我迭代我的示例,以使模式在所有行位置都工作。我在代码中写了一些注释来解释这一点,我将对此进行检查。。我想这会对我的银行起作用,正是我想要的,但在这个案件中,面临着另一个问题,在某个职位上,它不起作用,你能给我更多的细节吗?我不确定我understood@AkshayBhardwaj希望我能理解你的意思。我迭代我的示例,以使模式在所有行位置都工作。我在代码中写了一些注释来解释这一点,我将对此进行检查。。我想这对我有用在这个位置上它不起作用在这个位置上它不起作用