• Have Any Question?
  • contact@eitworld.com

Setlinestyle() Function





setlinestyle() is a function which is used to draw the line of different- different styles. Turbo C compiler provides five line styles that are solid, dotted, center, dashed and user defined. These all five line styles are already enumerated in graphics.h header file as given below:

enum line_styles

{

SOLID_LINE,

DOTTED_LINE,

CENTER_LINE,

DASHED_LINE,

USERBIT_LINE

};

Declaration

void setlinestyle( int type, unsigned pattern, int thickness );
  • setlinestyle() function contains three parameters type, pattern and thickness. First parameter contains the type of line like solid, dashed or dotted etc.
  • Second parameter is applicable only when type of line is user defined.
  • Third parameter specifies the thickness of the line it takes values 1 (line thickness of one pixel (normal)) or 3 (line thickness of three pixels (thick)
  • For better understanding go through the program:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd = DETECT, gm, i ;

char arr[100];

initgraph(&gd, &gm, ” “);

sprintf(arr,”Here are the five line styles enumerated in graphics.h header file:”);

outtextxy(2,10,arr);

for ( i = 0 ; i < 5 ; i++ )

{

setlinestyle(i,0,1);

if(i==0)

{

sprintf(arr,”(1).”);

outtextxy(60,50,arr);

line(100,40,300,40);

sprintf(arr,”line syle : solid”);

outtextxy(100,60,arr);

}

if(i==1)

{

sprintf(arr,”(2).”);

outtextxy(60,110,arr);

line(100,100,300,100);

sprintf(arr,”line syle : Dotted”);

outtextxy(100,120,arr);

}

if(i==2)

{

sprintf(arr,”(3).”);

outtextxy(60,170,arr);

line(100,160,300,160);

sprintf(arr,”line syle : center line(alternating dashes and dots)”);

outtextxy(100,180,arr);

}

if(i==3)

{

sprintf(arr,”(4).”);

outtextxy(60,230,arr);

line(100,220,300,220);

sprintf(arr,”line syle : Dashed”);

outtextxy(100,240,arr);

}

if(i==4)

{

sprintf(arr,”(5).”);

outtextxy(60,290,arr);

setlinestyle(i,15,1);

line(100,280,300,280);

sprintf(arr,”line syle : User-defined”);

outtextxy(100,300,arr);

}

}

getch();

closegraph();

}

Above program will draw different- different line styles that are already enumerated in graphics.h header file. The ouput of the above program shown below:

Output

c graphics



Real Time Web Analytics