Line
Draw a line from point (x1, y1) to point (x2, y2) with a given stroke width and color.
Syntax
new line(x1, y1, x2, y2, stroke, stroke_width, linecap, dasharray);
Parameters
x1 | Number : x-coordinate of the starting point |
y1 | Number : y-coordinate of the starting point |
x2 | Number : x-coordinate of the ending point |
y2 | Number : y-coordinate of the ending point |
stroke | Color : stroke color of the line |
stroke_width | Number : stroke width of the line |
linecap | 'butt', 'round', 'square' : linecap of the line |
dasharray | Dasharray : A list of comma and/or white space separated lengths and percentages that specify the lengths of alternating dashes and gaps in line. ex: "5 3 2" |
Example
new line(30,30,30,150, "#695FE6", 15);
new line(60,30,60,150, "#695FE6", 15, "round");
new line(90,30,90,150, "#695FE6", 15, "square");
new line(120,30,120,150, "#695FE6", 15, "butt", "15 5 10 5");
new line(150,30,150,150, "#695FE6", 15, "butt", "10 10");
t=0;
function draw(){
clearCanvas();
new line((WIDTH/2)+100*(cos(t)), (HEIGHT/2)+100*(sin(t)),(WIDTH/2)-100*(cos(t)), (HEIGHT/2)-100*(sin(t)), "#695fe6", 10, "round");
t+=0.01;
requestAnimationFrame(draw);
}