Turbo C - Using line and setlinestyle function
I have given here the graphics source code in Turbo C for line and setlinestyle function. line function is used to draw a line and will take 4 arguments x1, y1, x2, and y2. setlinestyle will take 3 arguments of which the first argument is used to specify the line styles - SOLID_LINE, DOTTED_LINE, CENTER_LINE, DASHED_LINE, USERBIT_LINE. The rand and randomize functions are used for animation.
Source Code
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
void main()
{
int i, grd, grm;
int x1, y1, x2, y2;
detectgraph(&grd,&grm);
initgraph(&grd, &grm, "");
while(!kbhit())
{
randomize();
setfillstyle(SOLID_FILL, BLUE);
bar(1,1,638,478);
setcolor(WHITE);
rectangle(0,0,639,479);
for(i = 0; i < 120; i++)
{
setcolor(rand() % 15);
setlinestyle(rand() % 4, 1, 1);
x1 = rand() % 639;
y1 = rand() % 479;
x2 = rand() % 639;
y2 = rand() % 479;
line(x1, y1, x2, y2);
delay(1);
}
}
getch();
closegraph();
}
Output
|