Amazon banner

Thursday, 30 August 2012

C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON

/* C PROGRAM TO DEMONSTRATE GRAPHICS GAME PRESS ME BUTTON  */ 
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR     */

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

union REGS i, o;
int left = 265, top = 250;

void initialize_graphics_mode() {
  int gd = DETECT, gm, error;

  initgraph( & gd, & gm, "C:/TC/BGI");

  error = graphresult();

  if (error != grOk) {
    perror("Error ");
    printf("Press any key to exit...\n");
    getch();
    exit(EXIT_FAILURE);
  }
}

void showmouseptr() {
  i.x.ax = 1;
  int86(0x33, & i, & o);
}

void hidemouseptr() {
  i.x.ax = 2;
  int86(0x33, & i, & o);
}

void getmousepos(int * x, int * y) {
  i.x.ax = 3;
  int86(0x33, & i, & o);

  * x = o.x.cx;
  * y = o.x.dx;
}

void draw_bar() {
  hidemouseptr();
  setfillstyle(SOLID_FILL, CYAN);
  bar(190, 180, 450, 350);
  showmouseptr();
}

void draw_button(int x, int y) {
  hidemouseptr();
  setfillstyle(SOLID_FILL, MAGENTA);
  bar(x, y, x + 100, y + 30);
  moveto(x + 5, y);
  setcolor(YELLOW);
  outtext("Press me");
  showmouseptr();
}

void draw() {
  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
  outtextxy(155, 451, "www.programmingsimplified.com");
  setcolor(BLUE);
  rectangle(0, 0, 639, 450);
  setcolor(RED);
  outtextxy(160, 25, "Try to press the \"Press me\" button");
  outtextxy(210, 50, "Press escape key to exit");
  setfillstyle(XHATCH_FILL, GREEN);
  setcolor(BLUE);
  bar(1, 1, 75, 449);
  bar(565, 1, 638, 449);
  showmouseptr();
  draw_bar();
  draw_button(left, top);
}

void initialize() {
  initialize_graphics_mode();

  if (!initmouse()) {
    closegraph();
    printf("Unable to initialize the mouse");
    printf("Press any key to exit...\n");
    getch();
    exit(EXIT_SUCCESS);
  }

  draw();
}

int initmouse() {
  i.x.ax = 0;
  int86(0x33, & i, & o);
  return (o.x.ax);
}

void get_input() {
  int x, y;

  while (1) {
    getmousepos( & x, & y);

    /* mouse pointer in left of button */

    if (x >= (left - 3) && y >= (top - 3) && y <= (top + 30 + 3) && x < left) {
      draw_bar();
      left = left + 4;

      if (left > 350)
        left = 190;

      draw_button(left, top);
    }

    /* mouse pointer in right of button */
    else if (x <= (left + 100 + 3) && y >= (top - 3) && y <= (top + 30 + 3) && x > (left + 100)) {
      draw_bar();
      left = left - 4;

      if (left < 190)
        left = 350;

      draw_button(left, top);
    }

    /* mouse pointer above button */
    else if (x > (left - 3) && y >= (top - 3) && y < (top) && x <= (left + 100 + 3)) {
      draw_bar();
      top = top + 4;

      if (top > 320)
        top = 180;

      draw_button(left, top);
    }

    /* mouse pointer below button */
    else if (x > (left - 3) && y > (top + 30) && y <= (top + 30 + 3) && x <= (left + 100 + 3)) {
      draw_bar();
      top = top - 4;

      if (top < 180)
        top = 320;

      draw_button(left, top);
    }

    if (kbhit()) {
      if (getkey() == 1)
        exit(EXIT_SUCCESS);
    }
  }
}

int getkey() {
  i.h.ah = 0;
  int86(22, & i, & o);

  return (o.h.ah);
}

main() {
  initialize();

  get_input();
  return 0;
}

C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS


/* C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS             */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR  */

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

main() {
  int gd = DETECT, gm, midx, midy;

  initgraph( & gd, & gm, "C:/TC/BGI");

  midx = getmaxx() / 2;
  midy = getmaxy() / 2;

  setcolor(RED);
  settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
  settextjustify(CENTER_TEXT, CENTER_TEXT);
  outtextxy(midx, midy - 10, "Traffic Light Simulation");
  outtextxy(midx, midy + 10, "Press any key to start");
  getch();
  cleardevice();
  setcolor(WHITE);
  settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy - 50, 22);
  setfillstyle(SOLID_FILL, RED);
  floodfill(midx, midy - 50, WHITE);
  setcolor(BLUE);
  outtextxy(midx, midy - 50, "STOP");
  delay(2000);
  graphdefaults();
  cleardevice();
  setcolor(WHITE);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy, 20);
  setfillstyle(SOLID_FILL, YELLOW);
  floodfill(midx, midy, WHITE);
  setcolor(BLUE);
  outtextxy(midx - 18, midy - 3, "READY");

  delay(2000);
  cleardevice();
  setcolor(WHITE);
  rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
  circle(midx, midy + 50, 22);
  setfillstyle(SOLID_FILL, GREEN);
  floodfill(midx, midy + 50, WHITE);
  setcolor(BLUE);
  outtextxy(midx - 7, midy + 48, "GO");
  setcolor(RED);
  settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
  outtextxy(midx - 150, midy + 100, "Press any key to exit...");

  getch();
  closegraph();
  return 0;
}

C PROGRAM TO DESIGN A MOVING WHEEL


/* C PROGRAM TO  DESIGN  A MOVING WHEEL                 */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR  */

#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>

int xc = 50, yc = 200, r = 35;
int x[15], y[15];
void drawcircles() {
  setcolor(YELLOW);
  circle(xc, yc, r);
  circle(xc, yc, r + 5);
}
void main() {
  double angle = 0, theta;
  int i, a;
  int gd = DETECT, gm;
  initgraph( & gd, & gm, "C:\TC\BGI");
  a = xc + r;
  while (!kbhit()) {
    while (a <= 630) {
      theta = M_PI * angle / 180;
      cleardevice();
      drawcircles();
      for (i = 0; i < 18; i++) {
        theta = M_PI * angle / 180;
        x[i] = xc + r * cos(theta);
        y[i] = yc + r * sin(theta);
        angle += 20;
        line(xc, yc, x[i], y[i]);
      }
      angle += 2;
      xc += 2;
      a = xc + r;
      delay(50);
    }
    xc = 50;
    r = 35;
    a = xc + r;
  }
  getch();
  closegraph();
}

C PROGRAM TO DRAW SPIRAL DESIGN



/* C PROGRAM TO DRAW SPIRAL DESIGN *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/


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

void main()
{
int r=5,n,i,x,y;
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "C:/TC/BGI");

setcolor(YELLOW);
printf("ENTER THE NUMBER OF RINGS IN THE SPIRAL MODEL\n");
scanf("%d",&n);
printf("Enter the origin point of the spiral");
scanf("%d%d",&x,&y);
clrscr();
for(i=0;i<n;i++)
{        delay(50);
arc(x,y,0,180,r=r+2);
arc(x+2,y,180,360,r=r+2);
}
getch();
closegraph();
}

C PROGRAM CREATE CIRCLES DESIGN




/* C PROGRAM CREATE CIRCLES DESIGN */

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/


#include<graphics.h>
#include<conio.h>
#include<dos.h>

main()
{
   int gd = DETECT, gm, x, y, color, angle = 0;
   struct arccoordstype a, b;

   initgraph(&gd, &gm, "C:/TC/BGI");
   delay(2000);

   while(angle<=360)
   {
      setcolor(BLACK);
      arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);
      setcolor(RED);
      getarccoords(&a);
      circle(a.xstart,a.ystart,25);
      setcolor(BLACK);
      arc(getmaxx()/2,getmaxy()/2,angle,angle+2,150);
      getarccoords(&a);
      setcolor(GREEN);
      circle(a.xstart,a.ystart,25);
      angle = angle+5;
      delay(50);
   }

   getch();
   closegraph();
   return 0;
}

C PROGRAM TO DEMONSTRATE BRICK GAME





/* C PROGRAM TO DEMONSTRATE BRICK GAME *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

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

int getkey();

void main()
{

int gd,gm;
gd=DETECT;
initgraph(&gd,&gm,"C:/TC/BGI");
cleardevice();

int ar,xc,yc,xr=0,yr=195,a=1,b=1,c=0,are;
void *bu,*buf;
int X=0,Y=0,s,area1;
void *buff1;

rectangle(0,0,50,25);
setfillstyle(6,6);
floodfill(2,2,15);
ar=imagesize(0,0,50,25);
bu=malloc(ar);
getimage(0,0,50,25,bu);
putimage(0,0,bu,XOR_PUT);
rectangle(0,0,50,25);
setfillstyle(6,8);
floodfill(2,2,15);
are=imagesize(0,0,50,25);
buf=malloc(are);
getimage(0,0,50,25,buf);
putimage(0,0,buf,XOR_PUT);
for(int j=0;j<180;j+=27)
 for(int i=0;i<600;i+=52)
  putimage(0+i,27+j,bu,XOR_PUT);
putimage(0,27,bu,XOR_PUT);
putimage(572,27,bu,XOR_PUT);
putimage(0,27,buf,XOR_PUT);
putimage(572,27,buf,XOR_PUT);

setcolor(3);
rectangle(80,445,159,452);
setfillstyle(1,1);
floodfill(82,447,3);
area1=imagesize(80,445,159,452);
buff1=malloc(area1);
getimage(80,445,159,452,buff1);

setcolor(4);
line(0,479,640,479);

    int area,x=325,y=325,ch,xdirn=-1,ydirn=-1,step;
    int maxx,maxy;
    void *buff;

    setcolor(WHITE);
    setfillstyle(SOLID_FILL,RED);
    circle(350,350,5);
    floodfill(350,350,WHITE);

    area=imagesize(345,345,355,355);
    buff=malloc(area);
    getimage(345,345,355,355,buff);
    putimage(345,345,buff,XOR_PUT);


  while (1)
  {
    putimage(x, y, buff, XOR_PUT);
    delay(15);
    putimage(x, y, buff, XOR_PUT);

    x=x+(xdirn*2);
    y=y+(ydirn*3);

    if ( x + 10 - 1 > 640 )
     {
       xdirn*=-1;
       x = 640 - 10 + 1;
     }
    if (x < 0)
     {
       xdirn*=-1;
       x = 0;
     }
    if ( y + 10 - 1 > 470 )
     {

       cleardevice();
       outtextxy(200,200,"Sorry! You loose the game.");
       outtextxy(250,240,"Try Again!!!");
       gotoxy(30,8);
       cout<<"Total Score : ";
       delay(5000);
       getch();
       goto tt;
     }
    if(c==1020)
    {
       outtextxy(180,200,"Congrats! You have finished the game.");
       gotoxy(30,8);
       cout<<"Total Score : ";
       delay(5000);
       getch();
       goto tt;
     }

    if ( getpixel(x,y)==1 )
     {
       sound(500);
       delay(15);
       nosound();
       ydirn*=-1;
     }
    if (getpixel(x,y)==6)
     {
       sound(100);
       delay(50);
       nosound();
       ydirn*=-1;
       xc=x;
       yc=y;
       a=xc/52;
       b=(yc/27);
       xr=a*52;
       yr=b*27;
       putimage(xr,yr,bu,XOR_PUT);
       c+=10;
     }
    if (getpixel(x,y)==8)
     {
       sound(800);
       delay(200);
       nosound();
       ydirn*=-1;
       xc=x;
       yc=y;
       a=xc/52;
       b=(yc/27);
       xr=a*52;
       yr=b*27;
       putimage(xr,yr,buf,XOR_PUT);
       c+=100;
     }
    if( y < 0 )
     {
      ydirn*=-1;
      y=0;
     }
    gotoxy(65,1);
    cout<<"SCORE : ";

if(kbhit())
{
 s=getkey();
 if(s!=1)
 {
   if(X>480)
    {
X=480;
putimage(160+X,445+Y,buff1,XOR_PUT);
    }
   if(X<-80)
    {
X=-80;
putimage(80+X,445+Y,buff1,XOR_PUT);
    }
   putimage(80+X,445+Y,buff1,XOR_PUT);

   if(s==75)
X+=-40;

   if(s==77)
X+=40;
   putimage(80+X,445+Y,buff1,XOR_PUT);

  }
  if(s==1)
  {
tt: free(bu);
    free(buff);
    free(buff1);
    closegraph();
    exit(0);
  }
 }
}
free(bu);
free(buff);
free(buff1);
closegraph();
}

int getkey()
{
union REGS j,o;
j.h.ah=0;
int86(22,&j,&o);
return(o.h.ah);
}

C PROGRAM TO DEMONSTRATE A MOVING FISH





/* C PROGRAM TO DEMONSTRATE A MOVING FISH *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/#include<stdio.h>

#include<time.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>

void main()
{
int gd=DETECT,gm;
int x=10,y=200,x1=675,y1=380;
int stangle=35,endangle=140,radius=90;

initgraph(&gd,&gm,"C:/TC/BGI");

while(!kbhit())
{
cleardevice();
setbkcolor(BLACK);

if(x<640)
{
x+=5;
y+=1;
arc(x,y,stangle,endangle+35,radius);
arc(x,y-110,190,323,radius+2);
circle(x+40,y-60,5);
line(x-90,y-90,x-90,y-8);
}
else
{
x1-=5;
y1-=1;
arc(x1,y1,stangle-30,endangle+4,radius);
arc(x1,y1-110,217,350,radius+2);
circle(x1-40,y1-60,5);
line(x1+90,y1-90,x1+90,y1-10);
}
setcolor(YELLOW);
delay(90);
}
closegraph();
}

C PROGRAM TO DEMONSTRATE 3D REFLECTION



/* C PROGRAM TO DEMONSTRATE 3D REFLECTION *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

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

#define ORG -50

double face1[5][2] = {
   { 250, 125 },
   { 350, 125 },
   { 350, 225 },
   { 250, 225 },
   { 250, 125 }
          };

double face2[5][2] = {
   { 250+ORG, 125-ORG },
   { 350+ORG, 125-ORG },
   { 350+ORG, 225-ORG },
   { 250+ORG, 225-ORG },
   { 250+ORG, 125-ORG }
          };

double angle = 5.0 * M_PI / 180;
double midx1, midy1, midx2, midy2;

void rotate (void)
{
    int i;
    for (i=0; i<5; i++)
    {
double xnew, ynew;

xnew = midx1 + (face1[i][0] - midx1) * cos (angle) -
      (face1[i][1] - midy1) * sin (angle);
ynew = midy1 + (face1[i][0] - midx1) * sin (angle) +
(face1[i][1] - midy1) * cos (angle);

face1[i][0] = xnew;
face1[i][1] = ynew;

xnew = midx2 + (face2[i][0] - midx2) * cos (angle) -
(face2[i][1] - midy2) * sin (angle);
ynew = midy2 + (face2[i][0] - midx2) * sin (angle) +
(face2[i][1] - midy2) * cos (angle);

face2[i][0] = xnew;
face2[i][1] = ynew;
    }

    cleardevice();

    for (i=0; i<4; i++)
    {
setcolor(7);
line (face1[i][0], face1[i][1], face1[i+1][0], face1[i+1][1]);
setcolor(8);
line (face2[i][0], face2[i][1], face2[i+1][0], face2[i+1][1]);
setcolor(9);
line (face1[i][0], face1[i][1], face2[i][0], face2[i][1]);
    }

    delay (125);
}

void main()
{
    int gd = DETECT, gm;

    midx1 = (face1[0][0] + face1[1][0]) / 2.0;
    midy1 = (face1[1][1] + face1[2][1]) / 2.0;
    midx2 = (face2[0][0] + face2[1][0]) / 2.0;
    midy2 = (face2[1][1] + face2[2][1]) / 2.0;

    initgraph (&gd, &gm, "..\\bgi");

    while (!kbhit())
rotate();

    closegraph();
}

Friday, 17 August 2012

C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION

/* C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3],poly2[30];
int x=0,y=0,p,i,j,k,xc,yc,ch;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;

setcolor(1);
setbkcolor(15);
setfillstyle(6,3);

printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter cordinate point x%d and y%d : ",j+1,j+1);

scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];


for(i=0;i<p*2;i+=2)
{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];

}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];

fillpoly(p+1,poly2);

line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);


printf("\n Shearing of : \n 1. x \n 2. y \n 3. Both\n enter choice : ");
scanf("%d",&ch);
if(ch==1)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
}
if(ch==2)
{
printf("\n Enter y shear value : ");
scanf("%d",&y);
}
if(ch==3)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
printf("\n Enter y shear value : ");
scanf("%d",&y);
}


j=0;
for(i=0;i<p;i++)
{
 a[i][0]=poly[j];
 a[i][1]=poly[++j];
 a[i][2]=1;
 ++j;
}

if(ch==1)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }
    b[1][0]=x;

}
else if(ch==2)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }
    b[0][1]=y;

}
else if(ch==3)
{
    for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
     {
       b[i][j]=0;
       if(i==j)
       {
       b[i][j]=1;
       }
     }
    }

    b[1][0]=x;
    b[0][1]=y;

}
for(i=0;i<p;i++)
{

   for(j=0;j<3;j++)
   {
   c[i][j]=0;
     for(k=0;k<3;k++)
     {
 c[i][j]=c[i][j]+a[i][k]*b[k][j];
     }
   }

 }
printf("\n\n\n\n\n\t After Shearing : ");


for(i=0,j=0;i<p;i++,j+=2)
{
poly[j]  =xc+c[i][0];
poly[j+1]=yc-c[i][1];
}
poly[j]  =poly[0];
poly[j+1]=poly[1];

setfillstyle(9,2);
fillpoly(p+1,poly);

getch();
closegraph();
}





C PROGRAM TO DEMONSTRATE TRANSLATION TRANSFORMATION

/* C PROGRAM TO DEMONSTRATE TRANSLATION TRANSFORMATION*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3];
int x,y,p,i,j,k;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
setcolor(1);
setbkcolor(15);
setfillstyle(6,3);
printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter co-ordinate point x%d and y%d : ",j+1,j+1);

scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];

fillpoly(p+1,poly);
putpixel(150,150,RED);

printf("\n Enter Translation factor x and y");
scanf("%d%d",&x,&y);

j=0;
for(i=0;i<p;i++)
{
 a[i][0]=poly[j];
 a[i][1]=poly[++j];
 a[i][2]=1;
 ++j;
}

for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
   b[i][j]=0;
   if(i==j)
   b[i][j]=1;
 }
}
b[2][0]=x;
b[2][1]=y;



for(i=0;i<p;i++)
{

   for(j=0;j<3;j++)
   {
   c[i][j]=0;
     for(k=0;k<3;k++)
     {
 c[i][j]=c[i][j]+a[i][k]*b[k][j];
     }
   }

 }
printf("\n\n\n\n\n\t After scaling : ");

for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("\t %d",c[i][j]);
}
}


for(i=0,j=0;i<p;i++,j+=2)
{
poly[j]  =c[i][0];
poly[j+1]=c[i][1];
}
poly[j]  =poly[0];
poly[j+1]=poly[1];

setfillstyle(9,2);
fillpoly(p+1,poly);

getch();
closegraph();
}



C PROGRAM TO DRAW CIRCLE IN FOURTH QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM

/* C PROGRAM TO DRAW CIRCLE IN FOURTH QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi=0,yi,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;

   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);

   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   yi=-r;    // Assign radius to yi
   di=2*(1-r);             // Value for delta
   putpixel(xc,yc,RED);
   while(yi<=limit)
     {
 putpixel(xc+xi,yc-yi,RED);           // Putpixel
 delay(50);
 if(di<0)
 {
    d1=(2*di)+(2*yi)-1;
    if(d1<=0)
    {
       xi=xi+1;
       di=di+2*xi+1;            //Mh value
    }
    else
    {
       xi=xi+1;
       yi=yi+1;
       di=di+2*xi+2*yi+2;       //Md value
    }
 }
 else
 {
    if(di>0)
    {
       d2=2*di-2*xi-1;
       if(d2<=0)
       {
    xi=xi+1;
    yi=yi+1;
    di=di+2*xi+2*yi+2;    //Md value
       }
       else
       {
    yi=yi+1;
    di=di+2*yi-1;         // Mv value
       }
    }
    else
    {
       if(di==0)
       {
    xi=xi+1;
    yi=yi+1;
    di=di+2*xi+2*yi+2;    // Md value
       }
    }
 }
     }                                  //While ends
     getch();
     closegraph();
     }



C PROGRAM TO DRAW CIRCLE IN FOURTH QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM

/* C PROGRAM TO DRAW CIRCLE IN FOURTH QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi,yi=0,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;


   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);

   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   xi=r;    // Assign radius to xi
   di=2*(1-r);             // Value for delta

   putpixel(xc,yc,RED);
   while(xi>=limit)
     {
 putpixel(xc+xi,yc-yi,RED);           // Putpixel
 delay(50);
 if(di<0)
 {
    d1=(2*di)+(2*xi)-1;
    if(d1<=0)
    {
       yi=yi-1;
       di=di-2*yi+1;            //Mv value
    }
    else
    {
       xi=xi-1;
       yi=yi-1;
       di=di-2*xi-2*yi+2;       //Md value
    }
 }
 else
 {
    if(di>0)
    {
       d2=2*di+2*yi-1;
       if(d2<=0)
       {
    xi=xi-1;
    yi=yi-1;
    di=di-2*xi-2*yi+2;    //Md value
       }
       else
       {
    xi=xi-1;
    di=di-2*xi+1;         // Mh value
       }
    }
    else
    {
       if(di==0)
       {
    xi=xi-1;
    yi=yi-1;
    di=di-2*xi-2*yi+2;    // Md value
       }
    }
 }
     }                                  //While ends
     getch();
     closegraph();

     }






C PROGRAM TO DRAW CIRCLE IN THIRD QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM

/* C PROGRAM TO DRAW CIRCLE IN THIRD QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/

* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi,yi=0,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;

   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);

   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   xi=-r;                   // Assign radius to xi
   di=2*(1-r);             // Value for delta
   putpixel(xc,yc,RED);
   while(xi<=limit)
     {
 putpixel(xc+xi,yc-yi,RED);           // Putpixel
 delay(50);
 if(di<0)
 {
    d1=(2*di)-(2*yi)-1;
    if(d1<=0)
    {
         yi=yi-1;
         di=di-2*yi+1;            //Mv value
    }
    else
    {
         xi=xi+1;
        yi=yi-1;
        di=di+2*xi-2*yi+2;       //Md value
    }
 }
 else
 {
    if(di>0)
    {
       d2=2*di-2*xi-1;
       if(d2<=0)
       {
          xi=xi+1;
         yi=yi-1;
         di=di+2*xi-2*yi+2;     //Md value
       }
       else
       {
    xi=xi+1;
    di=di+2*xi+1;         // Mh value
       }
    }
    else
    {
       if(di==0)
       {
    xi=xi+1;
          yi=yi-1;
          di=di+2*xi-2*yi+2;     // Md value
       }
    }
 }
     }       //While ends
     getch();
     closegraph();
     }







C PROGRAM TO DRAW CIRCLE IN THIRD QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM

/* C PROGRAM TO DRAW CIRCLE IN THIRD QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi=0,yi,di,limit=0,r,d1,d2,xc,yc;
   clrscr();
   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;
   setcolor(2);
   setbkcolor(15);
   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);
   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);
   yi=-r;    // Assign radius to yi
   di=2*(1-r);             // Value for delta
   putpixel(xc,yc,RED);
   while(yi<=limit)
     {
 putpixel(xc+xi,yc-yi,RED);           // Putpixel
 delay(50);
 if(di<0)
 {
    d1=(2*di)-(2*yi)-1;
    if(d1<=0)
    {
       xi=xi-1;
       di=di-2*xi+1;            //Mh value
    }
    else
    {
       xi=xi-1;
       yi=yi+1;
       di=di-2*xi+2*yi+2;       //Md value
    }
 }
 else
 {
    if(di>0)
    {
       d2=2*di+2*xi-1;
       if(d2<=0)
       {
    xi=xi-1;
    yi=yi+1;
    di=di-2*xi+2*yi+2;    //Md value
       }
       else
       {
    yi=yi+1;
    di=di+2*yi+1;         // Mv value
       }
    }
    else
    {
       if(di==0)
       {
    xi=xi-1;
    yi=yi+1;
    di=di-2*xi+2*yi+2;    // Md value
       }
    }
 }
     }                                  //While ends
     getch();
     closegraph();
     }






 

C PROGRAM TO DRAW CIRCLE IN SECOND QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM

/* C PROGRAM TO DRAW CIRCLE IN SECOND QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/


/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi=0,yi,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;

   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);

   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   yi=r;    // Assign radius to yi
   di=2*(1-r);             // Value for delta
   putpixel(xc,yc,RED);
   while(yi>=limit)
     {
 putpixel(xc+xi,yc-yi,RED);           // Putpixel
 delay(50);
 if(di<0)
 {
    d1=(2*di)+(2*yi)-1;
    if(d1<=0)
    {
       xi=xi-1;
       di=di-2*xi+1;            //Mh value
    }
    else
    {
       xi=xi-1;
       yi=yi-1;
       di=di-2*xi-2*yi+2;       //Md value
    }
 }
 else
 {
    if(di>0)
    {
       d2=2*di+2*xi-1;
       if(d2<=0)
       {
    xi=xi-1;
    yi=yi-1;
    di=di-2*xi-2*yi+2;    //Md value
       }
       else
       {
    yi=yi-1;
    di=di-2*yi+1;         // Mv value
       }
    }
    else
    {
       if(di==0)
       {
    xi=xi-1;
    yi=yi-1;
    di=di-2*xi-2*yi+2;    // Md value
       }
    }
 }
     }                                  //While ends
     getch();
     closegraph();
     }







Thursday, 16 August 2012

C PROGRAM TO DRAW CIRCLE IN SECOND QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM


/* C PROGRAM TO DRAW CIRCLE IN SECOND QUADRANT IN CLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/


/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi,yi=0,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;

   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);

   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   xi=-r;  // Assign radius to xi
   di=2*(1-r);             // Value for delta

   putpixel(xc,yc,RED);
   while(xi<=limit)
     {
putpixel(xc+xi,yc-yi,RED);           // Putpixel
delay(50);
if(di<0)
{
  d1=(2*di)-(2*yi)-1;
  if(d1<=0)
  {
     yi=yi+1;
     di=di+2*yi+1;            //Mv value
  }
  else
  {
     xi=xi+1;
     yi=yi+1;
     di=di+2*xi+2*yi+2;       //Md value
  }
}
else
{
  if(di>0)
  {
     d2=2*di-2*yi-1;
     if(d2<=0)
     {
 xi=xi+1;
 yi=yi+1;
 di=di+2*xi+2*yi+2;    //Md value
     }
     else
     {
 xi=xi+1;
 di=di+2*xi+1;         // Mh value
     }
  }
  else
  {
     if(di==0)
     {
 xi=xi+1;
 yi=yi+1;
 di=di+2*xi+2*yi+2;    // Md value
     }
  }
}
     }                                  //While ends
     getch();
     closegraph();
     }




C PROGRAM TO DRAW CIRCLE IN FIRST QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM


/* C PROGRAM TO DRAW CIRCLE IN FIRST QUADRANT IN ANTICLOCKWISE DIRECTION USING BRESENHAM'S CIRCLE DRAWING ALGORITHM*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
   // Request auto detection
   int gdriver = DETECT, gmode;
   int xi,yi=0,di,limit=0,r,d1,d2,xc,yc;
   clrscr();

   // Initialize graphics mode
   initgraph(&gdriver, &gmode,"C:\TC\BGI");
   xc=getmaxx()/2;
   yc=getmaxy()/2;

   setcolor(2);
   setbkcolor(15);

   // Get radius value
   printf("\n\n\t Enter the radius :");
   scanf("%d",&r);
   
   line(0,yc,xc*2,yc);
   line(xc,0,xc,yc*2);

   xi=r;                   // Assign radius to xi

   di=2*(1-r);             // Value for delta

   putpixel(xc,yc,RED);
   while(xi>=limit)
     {
putpixel(xc+xi,yc-yi,RED);           // Putpixel
delay(50);
if(di<0)
{
  d1=(2*di)+(2*xi)-1;
  if(d1<=0)
  {
 yi=yi+1;
 di=di+2*yi+1;            //Mv value
  }
  else
  {
 xi=xi-1;
 yi=yi+1;
 di=di-2*xi+2*yi+2;       //Md value
  }
}
else
{
  if(di>0)
  {
     d2=2*di-2*yi-1;
     if(d2<=0)
     {
 xi=xi-1;
 yi=yi+1;
 di=di-2*xi+2*yi+2;     //Md value
     }
     else
     {
 xi=xi-1;
 di=di-2*xi+1;         // Mh value
     }
  }
  else
  {
     if(di==0)
     {
 xi=xi-1;
 yi=yi+1;
 di=di-2*xi+2*yi+2;     // Md value
     }
  }
}
     }    //While ends
     getch();
     closegraph();
     }