// macros for simplicity
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
/*
** drawLine
**
** Draw a line from vertex (x0,y0) to vertex (x1,y1) using
** the midpoint line algorithm, implemented using OpenGL.
**
*/
void drawLine( GLint x0, GLint y0, GLint x1, GLint y1 ) {GLint dE, dNE, x, y, d, dx, dy;
// check if we need to switch the points
if( x0 > x1 ) {
x0 = x0 + x1;
x1 = x0 - x1;
x0 = x0 - x1;
y0 = y0 + y1;
y1 = y0 - y1;
y0 = y0 - y1;}
// calculate deltas
dy = y1 - y0; dx = x1 - x0;
// special cases
if( dx -1 - diag down-right
glBegin(GL_POINTS);
for( x = x0, y = y0; x <= x1; x++, y-- ) {
glVertex2i(x,y);}
glEnd();}else { // general cases
// midpoint algorithm
if( abs(dy) < dx ) { // small slope
dE = 2 * abs(dy);
dNE = 2 * (abs(dy) - dx);
d = dE - dx;
glBegin(GL_POINTS);
for( x = x0, y = y0; x <= x1; x++ ) {
glVertex2i(x,y);
if( d <= 0 ) {
d+= dE;}else {
y += (dy>0?1:-1);
d += dNE;}}// for x = x0 to x1
glEnd();}else { // large slope
dE = 2 * dx;
dNE = 2 * (dx - abs(dy));
d = dE - abs(dy);
glBegin(GL_POINTS);
for( x = x0, y = y0; (y0 < y1 && y <= y1)
(y0 > y1 && y >= y1); y+=(y0 < y1?1:-1) ) {
glVertex2i(x,y);
if( d <= 0) { x ++;
d+= dE; }else { d += dNE; }}// for y = y0 to y1
glEnd();}}
}// drawLine()
draw a line chart.
In code, you'd actually do something like so: '\n'. Actually, the ASCII code of the Line Feed is 10 (0A hex), and the code of the Carriage Return is 13 (0D hex).
They aren't used.
the diagram shows that u cant because that a half turn
compiler is a software translator used in ProgrammingLanguage: C,C++, Java etc ). This used for to translate High level language to Machine independent language. Interpreter is used to translate source code to machine code by line by line.