Draw All Types And Styles Of Lines Using DDA Algorithm In C Graphics
Linestyle program using DDA Line Drawing Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define round(a) (a+0.5)
int gdriver=DETECT, gmode;
int dotted_dash[8]={1, 1, 0, 1, 0, 1, 1, 0};
int dotted[8]={1, 0, 1, 0, 1, 0, 1, 0};
int dash[8]={1, 1, 0, 0, 1, 1, 0, 0};
int solid[8]={1, 1, 1, 1, 1, 1, 1, 1};
int value;
void dda(int xa, int ya, int xb, int yb, int a[]);
void main()
{
do{
clrscr();
initgraph(&gdriver, &gmode, "C:\\Turboc3\\BGI");
printf("\n**********************************\n");
printf("\nPress 1 for Solid Line");
printf("\nPress 2 for Dotted Line");
printf("\nPress 3 for Dash Line");
printf("\nPress 4 for Dotted Dash Line");
printf("\nPress 5 for Exit from the program\n");
printf("\n**********************************\n");
printf("\nEnter your Choice : ");
scanf("%d",&value);
switch(value){
case 1: dda(200, 200, 350, 200, solid);
dda(200, 200, 200, 300, solid);
dda(200, 200, 350, 300, solid);
dda(350, 200, 200, 300, solid);
break;
case 2: dda(200, 200, 350, 200, dotted);
dda(200, 200, 200, 300, dotted);
dda(200, 200, 350, 300, dotted);
dda(350, 200, 200, 300, dotted);
break;
case 3: dda(200, 200, 350, 200, dash);
dda(200, 200, 200, 300, dash);
dda(200, 200, 350, 300, dash);
dda(350, 200, 200, 300, dash);
break;
case 4: dda(200, 200, 350, 200, dotted_dash);
dda(200, 200, 200, 300, dotted_dash);
dda(200, 200, 350, 300, dotted_dash);
dda(350, 200, 200, 300, dotted_dash);
break;
case 5: printf("Exit");
break;
default :printf("\nKindly enter valid choice!!");
}
getch();
}
while(value!=5);
}
void dda(int xa, int ya, int xb, int yb, int a[])
{
float x, y, xincr, yincr;
int dy, dx, steps, i, j=0;
dx=xb-xa;
dy=yb-ya;
x=xa;
y=ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xincr=dx/(float)steps;
yincr=dy/(float)steps;
putpixel(round(x), round(y), 5);
j=0;
for(i=0;i<steps;i++)
{
x+=xincr;
y+=yincr;
if(a[j]==1)
putpixel(round(x), round(y), 5);
j++;
if(j==7)
j=0;
}
}
Print your name using the bitmap method in C graphics
Thickline program in C graphics
Comment your views on this Article :)
No comments
Comment your views on this article