Saturday, 9 August 2014

Hardware program to implement the filling of a rectangle with a click

This is a hardware program to implement the filling of a rectangle on a click. If you have any doubts, please let me know. 

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

int main(void)
{
    clrscr();
   int gdriver = DETECT, gmode;
   int left, top, right, bottom,c,poly[8],x,y;
   union REGS in,out;
   initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi ");
   left = getmaxx() / 2 - 50;
   top = getmaxy() / 2 - 50;
   right = getmaxx() / 2 + 50;
   bottom = getmaxy() / 2 + 50;
   rectangle(left,top,right,bottom);
   in.x.ax=7;
   in.x.cx=left;
   in.x.dx=right;
   int86(0x33,&in,&out);
   in.x.ax=8;
   in.x.cx=top;
   in.x.dx=bottom;
   int86(0x33,&in,&out);
   in.x.ax=1;
   int86(0x33,&in,&out);
    poly[0]=left;
    poly[1]=top;
    poly[2]=left+100;
    poly[3]=top;
    poly[4]=right;
    poly[5]=bottom;
    poly[6]=right-100;
    poly[7]=bottom;
    printf("BUTTON STATUS");
    while(!kbhit())
    {
      in.x.ax=3;
      int86(0x33,&in,&out);
      c=out.x.bx;
      gotoxy(2,2);
      switch(c)
      {
      case 0:
                 break;
      case 1:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,15);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nLEFT  PRESS");
                 break;
      case 2:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,0);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nRIGHT PRESS");
                 break;
      }
      gotoxy(2,4);
      printf("\nPress any key to exit");
    }
    in.x.ax=0;
    int86(0x33,&in,&out);
    getch();
    closegraph();
    return 0;
}





No comments:

Post a Comment