Skip to main content

C program to implement DDA algorithm

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

#define round(a) ((int) (a+0.5))
void lineDDA(int xa,int ya,int xb,int yb);
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xa,ya,xb,yb;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "..\\bgi");

   lineDDA(0,0,640,480);
   lineDDA(640,0,0,480);
   lineDDA(320,0,320,480);
   lineDDA(0,240,640,240);

   getch();
   closegraph();
  
}

void lineDDA(int xa,int ya,int xb,int yb)
{
 int dx=xb-xa,dy=yb-ya,steps,k;
 float xinc,yinc,x=xa,y=ya;

 if(abs(dx)>abs(dy))
  steps=abs(dx);
 else
 steps=abs(dy);

 xinc=dx/(float) steps;
 yinc=dy/(float) steps;
 putpixel(round(x),round(y),5);
 for(k=0;k<steps;k++)
 {       x+=xinc;
  y+=yinc;
  putpixel(round(x),round(y),2);
 }
}


Comments

Popular posts from this blog

Use Case Diagram for Online Book Store

Occurrences of each letter of alphabet in the text

Program to print a table indicating the no. of occurrences of each letter of alphabet in the text entered as command line arguments. #include<iostream> #include<string> using namespace std; int main(int argc, char *argv[]) { string str=""; static int alphabet[26]; int x; cout<<"\n\n Command-Line Argument\n"; for(int i=0;i<argc;i++) { cout<<"\n "<<argv[i]; str+=argv[i]; } for(int i=0;i<str.length();i++) { if(str[i]>='A' && str[i]<='Z') { x=((int)str[i])-65; alphabet[x]++; } else if(str[i]>='a' && str[i]<='z') { x=((int)str[i])-97; alphabet[x]++; } } //Displaying No. of occurrences of each alphabets in the command line argument cout<<"\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n Alphabet No. of Occurrences\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; for(int i=0;i<26;i++)...

How to Run SQL Command Line in Oracle 10g

Step 1: Goto start button  then program menu. Step 2:  Expand Oracle.                             Step 3: Select “ Run SQL Command Line”. Step 4: Now type in SQLPlus command prompt following commands: - a)       Type   connect b)       Enter username as “ System” c)       Then, Enter password of your Oracle 10g               Step 5: Now execute your SQL commands. e.g. : -