Chess Board

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

int main(void)
{
   int gdriver = DETECT, gmode;
   int i,j;
   int poly[8];

   initgraph(&gdriver, &gmode, "c:\\TURBOC3\\BGI");

   /*First Square of Chess Board*/
   poly[0] = 100; /* 1st vertex */
   poly[1] = 100;
   poly[2] = 125; /* 2nd */
   poly[3] = 100;
   poly[4] = 125; /* 3rd */
   poly[5] = 125;
   poly[6] = 100;
   poly[7] = 125;

   setfillstyle(1, WHITE);
   rectangle(100,100,300,300);
   for(i=0;i<8;i++)
   {
    for(j=0;j<8;j++)
    {
     if((i+j)%2==1)
     {
      fillpoly(4,poly);
     }
     poly[0]=poly[0]+25;
     poly[2]=poly[2]+25;
     poly[4]=poly[4]+25;
     poly[6]=poly[6]+25;
    }
    poly[0]=100;
    poly[2]=125;
    poly[4]=125;
    poly[6]=100;
    poly[1]=poly[1]+25;
    poly[3]=poly[3]+25;
    poly[5]=poly[5]+25;
    poly[7]=poly[7]+25;
   }
   getch();
   closegraph();
   return 0;
}

Output:
chess

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s