Draws a straight line between two points.
Use stroke() to color a line and strokeWeight() to change it's thickness. A line cannot be filled, therefore the fill() function will not affect the color of a line.
The default stroke() color is black and the default strokeWeight() is 1.
line(10, 50, 100, 75);
Draw a two lane road.
// Draw a two lane road.
strokeWeight(15);
line(0, 0, 400, 400);
stroke("yellow");
strokeWeight(1);
line(0, 0, 400, 400);
Draw a tic-tac-toe board.
// Draw a tic-tac-toe board. strokeWeight(10); line(133, 0, 133, 400); line(266, 0, 266, 400); line(0, 133, 400, 133); line(0, 266, 400, 266);
Are the 4 lines straight?
// Are the 4 lines straight?
noFill();
for (var i = 5; i < 20; i++) {
ellipse(200, 200, 20*i, 20*i);
}
strokeWeight(5);
line(200, 0, 400, 200);
line(400, 200, 200, 400);
line(200, 400, 0, 200);
line(0, 200, 200, 0);
line(x1, y1, x2, y2)
| Name | Type | Required? | Description |
|---|---|---|---|
| x1 | Number | The x-location in pixels of the first endpoint of the line. Should be a number from 0 to 400, but negative numbers will start the line to the left of the display and numbers greater than 400 will start the line to the right of the display (possibly unseen). | |
| y1 | Number | The y-location in pixels of the first endpoint of the line. Should be a number from 0 to 400, but negative numbers will start the line above the display and numbers greater than 400 will start the line below the display (possibly unseen). | |
| x2 | Number | The x-location in pixels of the second endpoint of the line. Should be a number from 0 to 400, but negative numbers will start the line to the left of the display and numbers greater than 400 will start the line to the right of the display (possibly unseen). | |
| y2 | Number | The y-location in pixels of the second endpoint of the line. Should be a number from 0 to 400, but negative numbers will start the line above the display and numbers greater than 400 will start the line below the display (possibly unseen). |
No return value. Outputs to the display only.
noStroke() hasn't been called, and where you're trying to draw the line fits within the coordinates of the display (400 x 400).strokeWeight() and stroke().Found a bug in the documentation? Let us know at documentation@code.org