C

Tuesday, 30 October 2018

Write a C++ program of DDA Line Drawing Algorithm..

#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
void main( )
{
       float x,y,x1,y1,x2,y2,dx,dy,step;
       int i,gd=DETECT,gm;

     initgraph(&gd,&gm,"c:\\turboc3\\bgi");

      printf("\nEnter the value of x1 and y1 : ");
      scanf("%f%f",&x1,&y1);
      printf("Enter the value of x2 and y2: ");
      scanf("%f%f",&x2,&y2);

    dx=abs(x2-x1);
    dy=abs(y2-y1);

    if(dx>=dy)
            step=dx;
    else
           step=dy;

    dx=dx/step;
    dy=dy/step;

    x=x1;
    y=y1;

    i=1;
    while(i<=step)
    {
           putpixel(x,y,WHITE);
           x=x+dx;
           y=y+dy;
           i=i+1;
           delay(100);
    }

getch();
        closegraph();
}

No comments:

Post a Comment

Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...