Graphics Programs

30
zDDA Line Drawing Algorithm #include<stdio.h> #include<conio.h> #include<graphics.h> #include<ctype.h> #include<math.h> #include<stdlib.h> void draw(int x1,int y1,int x2,int y2); void main() { int x1,y1,x2,y2; int gdriver=DETECT,gmode,gerror; initgraph(&gdriver,&gmode,”c:\\tc\\bgi:”); printf(“\n Enter the x and y value for starting point:\n”); scanf(“%d%d”,&x1,&y1); printf(“\n Enter the x and y value for ending point:\n”); scanf(“%d%d”,&x2,&y2); printf(“\n The Line is shown below: \n”); draw(x1,y1,x2,y2); getch(); }

description

enjoy

Transcript of Graphics Programs

DDA Line Drawing Algorithm

zDDA Line Drawing Algorithm

#include

#include

#include

#include

#include

#include

void draw(int x1,int y1,int x2,int y2);

void main()

{

int x1,y1,x2,y2;

int gdriver=DETECT,gmode,gerror;

initgraph(&gdriver,&gmode,c:\\tc\\bgi:);

printf(\n Enter the x and y value for starting point:\n);

scanf(%d%d,&x1,&y1);

printf(\n Enter the x and y value for ending point:\n);

scanf(%d%d,&x2,&y2);

printf(\n The Line is shown below: \n);

draw(x1,y1,x2,y2);

getch();

}

void draw(int x1,int y1,int x2,int y2)

{

float x,y,xinc,yinc,dx,dy;

int k;

int step;

dx=x2-x1;

dy=y2-y1;

if(abs(dx)>abs(dy))

step=abs(dx);

else

step=abs(dy);

xinc=dx/step;

yinc=dy/step;

x=x1;

y=y1;

putpixel(x,y,1);

for(k=1;k= startangle && thetax){if(dendangle){temp=startangle;startangle=endangle;endangle=temp;}MidPointcircle(xc,yc,radius);xstart=xc+radius*cos(PI/180*startangle);ystart=yc-radius*sin(PI/180*startangle);xend=xc+radius*cos(PI/180*endangle);yend=yc-radius*sin(PI/180*endangle);line(xc,yc,xstart,ystart);line(xc,yc,xend,yend);getch();break;case 3: printf("\n Enter the center:");scanf("%d %d",&xc,&yc);printf("\n Enter the radius:");scanf("%d",&radius);printf("\n Enter the startangle:");scanf("%f",&startangle);printf("\n Enter the endangle:");scanf("%f",&endangle);cleardevice();if(startangle>endangle){temp=startangle;startangle=endangle;endangle=temp;}MidPointcircle(xc,yc,radius);getch();break; case 4: closegraph();}}while(choice!=4);

}

Mid-Point Circle Algorithm

More HYPERLINK "http://i.thiyagaraaj.com/tutorials/computer-graphics/basic-drawing-techniques/-midpoint-circle-algorithm" Information

#include#include#include

void main(){

int gd=DETECT,gm;int x,y,r;voidDrawcircle(int,int,int);printf("Enter the Mid points and Radious:");scanf("%d%d%d",&x,&y,&r);initgraph(&gd,&gm,"");Drawcircle(x,y,r);getch();closegraph();

}void Drawcircle(int x1,int y1,int r){

int x=0,y=r,p=1-r;void cliplot(int,int,int,int);cliplot(x1,y1,x,y);while(x