1#include <graphics.h>2#include <stdlib.h>3#include <stdio.h>4#include <conio.h>5#include <time.h>6#include <cmath>7 8 inttile=1;9 intboard[ -][ -];Ten intcolor[ -] ={Black,green,blue,cyan,red,yellow,white,lightmagenta, One Lightred,lightcyan,lightgreen,lightblue,darkgray,lightgray,brown,magenta}; A - voidChessboard (intTrintTcintDrintdcintsize) - { the if(size==1) - return; - intt=tile++; - ints=size/2; + if(Dr<tr+s && dc<tc+s) - Chessboard (TR, TC, DR, DC, s); + Else A { atboard[tr+s-1][tc+s-1]=T; -Chessboard (TR, TC, tr+s-1, tc+s-1, s); - } - if(Dr<tr+s && dc>=tc+s) -Chessboard (TR, tc+S, Dr, DC, s); - Else in { -board[tr+s-1][tc+s]=T; toChessboard (tr, tc+s, tr+s-1, tc+s, s); + } - if(Dr>=tr+s && dc<tc+s) theChessboard (tr+S, TC, DR, DC, s); * Else $ {Panax Notoginsengboard[tr+s][tc+s-1]=T; -Chessboard (Tr+s, TC, Tr+s, tc+s-1, s); the } + if(Dr>=tr+s && dc>=tc+s) AChessboard (Tr+s, tc+S, Dr, DC, s); the Else + { -board[tr+s][tc+s]=T; $Chessboard (Tr+s, Tc+s, Tr+s, tc+s, s); $ } - } - the voidMain () - {Wuyi inti,j; the intsize; - intindex_x,index_y; Wuprintf"Please enter the length of the checkerboard (must be a power of 2 k) \ n"); -scanf"%d",&size); Aboutprintf"Please enter the coordinates of the point to be overwritten in the checkerboard: \ n"); $scanf"%d%d",&index_x,&index_y); -Initgraph (640,640); -Chessboard (0,0, index_x,index_y,size); - Beginbatchdraw (); A ints=size*size; + for(intk=0; k<s;k++) the { -i=k/size; $j=k%size; theSetfillcolor (color[board[i][j]% the]); theSolidrectangle ( +*j, ( ++ +*i), ( ++ +*J), +*i); the } the Flushbatchdraw (); - Endbatchdraw (); in getch (); the closegraph (); the}
Board overlay (drawing version)