# Computer Graphics – 13. Line Drawing – Naive Cartesian Form

[wpdm_package id=’1242′]

**Sample Input** – Draw a line using the Naive Cartesain Form of line. Accept the end point of line using mouse clicks. Use ‘+’ and ‘-‘ to increase/decrease the width of line. Clear the screen using right click.

[sourcecode lang=”cpp”]

void draw_line(GLintPoint p1, GLintPoint p2){

int greater_x=((p1.x>p2.x)?p1.x:p2.x);

int lower_x=((p1.x<p2.x)?p1.x:p2.x);

for(int x=lower_x; x<=greater_x; x++){

int y=((x-p1.x)*((p2.y-p1.y)*1.0/(p2.x-p1.x)))+p1.y;

draw_dot(x,y);

}

}

[/sourcecode]

To compile the above program in ubuntu terminal –

# g++ -lGL -lGLU -lglut Line_Naive_Cartesian.cpp

# ./a.out