Showing posts with label Computer Graphics. Show all posts
Showing posts with label Computer Graphics. Show all posts

Thursday, April 14, 2011

C implementation of Bresenham's Line Drawing Algorithm

Hello friends,following is the another program from Computer Graphics subject for Bresenham's Line Drawing Algorithm .Screenshoots shown are taken by running the programs in virtual machine os.

PROGRAM CODE
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
int round(float x);
void bresenham(int x1,int y1,int x2,int y2,int color);
void main ()
{
clrscr();
int gd=DETECT,gm;
int x1,x2,y1,y2;
printf("\nEnter Starting Point(X1,Y1) :");
scanf("%d%d",&x1,&y1);
printf("\nEnter End Point(X2,Y2) :");
scanf("%d%d",&x2,&y2);
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");

C implementation of Midpoint Circle Drawing Algorithm

Similar to previous post, following is the program for Midpoint Circle Drawing Algorithm in C.


PROGRAM CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int gd=DETECT,gm,i,x,y,r,xmid,ymid;
float p;
void main()
{
clrscr();
printf("\nEnter radius of circle=");
scanf("%d",&r);
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=0;
y=r;
p=1.25-r;
do
{
xmid=getmaxx()/2;
ymid=getmaxy()/2;

C implementation of Midpoint Ellipse Drawing Algorithm

Hi friends ,this time I am posting a program for Midpoint Ellipse Drawing Algorithm in C implemented during my Computer Graphics studies.Note that the output or screenshot shown is REAL and taken using a Virtual Machine.Program written is very simple and can be understood easily.Anyways do leave a comment to us if you got any queries .

PROGRAM CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int gdriver=DETECT, gmode,i,x,y;
void main()
{
long d1,d2,rx,ry,rxsq,rysq,trxsq,trysq,dx,dy;
printf("\nPlease enter the x radius of the ellipse\n");
scanf("%ld",&rx);
printf("Please enter the y radius of the ellipse\n");
scanf("%ld",&ry);
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int xmid,ymid;
xmid=getmaxx()/2;
ymid=getmaxy()/2;
line(xmid+rx+10,ymid-ry,xmid+rx+10,ymid);
line(xmid,ymid-ry-10,xmid+rx,ymid-ry-10);
char ch[20];
sprintf(ch,"%c",17);
outtextxy(xmid,ymid-ry-13,ch);
sprintf(ch,"%c",16);
outtextxy(xmid+rx-6,ymid-ry-13,ch);
sprintf(ch,"%c",30);