The line function is used to draw lines on the screen.
A line is defined by two points - the starting location and the ending location. When drawing lines, you must give the coordinates of starting point and the ending point. For example this line of code draws a line from point (20,50) to point (300,450):
line(20, 50, 300, 450);
The color of the line (or drawing pen) must be defined before you draw the line. Using the stroke() command to change the color of the line. For example this line of code would change the color of the drawing pen to red:
stroke(255,0,0);
The weight or thickness of the line must also be defined. Use the strokeWeight() function to change the thickness of the line. For example tomake the line 20 pixels wide we would write this code:
strokeWeight (20);
Here’s a program that draws lines
X Box
size(400,400)
strokeWeight(4);
line(100,100,300,100);
line(300,100,300,300);
line(300,300,100,300);
line(100,300,100,100);
line(100,100,300,300);
line(100,300,300,100);
Type in this program and run it. You should see something like this:
Helpful Links
Processing Reference - line()
Processing Reference - stroke()
Processing Reference - strokeWeight()