processing Drawing Basic Shapes Drawing a Line


Example

Processing provides a method named line() to draw a line on the screen. This code draws a white 10 pixel line on black background.

void setup() {
    size(500, 500);
    background(0);
    stroke(255);
    strokeWeight(10);
}

void draw() {
    line(0, 0, 500, 500);
}

The signature of method line() is this.

line(x1, y1, x2, y2);

x1 and y1 is a coordinate of the starting point. x2 and y2 is a coordinate of the ending point.

Method stroke() is used to specify the color of the line you will draw.

Method strokeWeight() is used to specify the thickness of the line you will draw. (in pixels)