0% found this document useful (0 votes)
11 views53 pages

Graphics Programming Projects in C

This document is a practical file for a BCA course detailing various graphics programming exercises using C. It includes a table of contents with multiple programs such as drawing shapes, creating animations, and simulating a traffic light. Each section contains code snippets and outputs for visual representation of the graphics created.

Uploaded by

monikamonika2167
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views53 pages

Graphics Programming Projects in C

This document is a practical file for a BCA course detailing various graphics programming exercises using C. It includes a table of contents with multiple programs such as drawing shapes, creating animations, and simulating a traffic light. Each section contains code snippets and outputs for visual representation of the graphics created.

Uploaded by

monikamonika2167
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

POST GRADUATE GOVT COLLEGE FOR GIRLS


SECTOR – 42 CHANDIGARH

PRACTICLE FILE OF GRAPHICS USING C


(BCA-16-605)

Submitted To: Submitted By:


Mrs. Nidhi Goyal Monika
Assistant Professor Roll No-221585/22
Department Of Computer BCA(6th Sem)
Application
2

INDEX
[Link] CONTENT PAGENO REMARK
1. OUTPUT 4
2. DRAW LINE, CIRCLE, ARC, 5
RECTANGLE, ELLIPSE
3. OUTPUT 6
4. SIMPLE SMILING FACE 7
5. OUTPUT 8
6. SCENERY 9-11
7. OUTPUT 12
8. COUNTDOWN FOR 30 SEC. 13-14
9. OUTPUT 15
10. TRAFFIC LIGHT 16-20
SIMULATION
11. OUTPUT 21
12. MOVING CAR 22-23
13. OUTPUT 24
14. ANIMATED SMILING FACE 25-28
15. OUTPUT 29
16. RAINBOW 30
17. OUTPUT 31
18. A MAN WALKING IN RAIN 32-34
19. OUTPUT 35
3

20. WORKING ANALOG CLOCK 36-39


21. OUTPUT 40
22. FILL CIRCLE WITH 41-42
DIFFERENT PATTERNS
23. OUTPUT 43
24. CONCENTRIC CIRCLE 44-45
25. OUTPUT 46
26. PRINT NAME IN ENGLISH 47-48
USING INBUILT PRIMITIVES
27. OUTPUT 49
28. BOUNCING BALL 50-51
29. OUTPUT 52
30. CHESS BOARD 53
4

OUTPUT
5

PROGRAM TO DRAW LIKE LINE, CIRCLE, ARC,


RECTANGLE, ELLIPSE
#include<graphics.h>
int main()
{
int gd = DETECT,gm;
initgraph(&gd,&gm,(char*)"");
// Top-left (100, 200) to bottom-right (200, 275)
rectangle(100,200,200,275);
// center(320, 240), angle(0-240), X-50, Y-radius 100
ellipse(320,240,0,240,50,100);
// center(100, 100), starting at angle 0 to 100, radius 50
arc(100,100,0,100,50);
// center(200, 130), radius 40
circle(220, 130, 40);
line(100, 100, 180, 180);
getch();
closegraph();
return(0);
}
6

OUTPUT
7

PROGRAM TO MAKE SIMPLE SMILING FACE


#include<graphics.h>
int main()
{
int n,gm,gd = DETECT;
initgraph(&gd,&gm," ");
setfillstyle(1,14);
circle(150,150,50);
floodfill(160,160,15);
setfillstyle(1,4);
circle(170,130,5);
floodfill(172,132,15);
setfillstyle(1,4);
circle(130,130,5);
floodfill(132,132,15);
setcolor(0);
ellipse(150,150,200,330,25,25);
getch();
closegraph();
return(0);
}
8

OUTPUT
9

PROGRAM TO DRAW A SCENERY


#include <graphics.h>
#include <stdio.h>
#include <conio.h>
void drawScenery() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Get screen dimensions
int maxx = getmaxx();
int maxy = getmaxy();
// Draw sky (light blue background)
setbkcolor(LIGHTCYAN);
clearviewport();
// Draw ground (green)
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
rectangle (0, maxy-100, maxx, maxy);
floodfill (10, maxy-10, GREEN);
// Draw sun
setcolor (YELLOW);
setfillstyle (SOLID_FILL, YELLOW);
circle (100, 100, 40);
10

floodfill (100, 100, YELLOW);


// Draw house base
setcolor (BROWN);
setfillstyle (SOLID_FILL, BROWN);
rectangle (maxx/2-100, maxy-200, maxx/2+100, maxy-100);
floodfill (maxx/2, maxy-150, BROWN);
// Draw roof
setcolor(RED);
setfillstyle (SOLID_FILL, RED);
int roof [] = {maxx/2-130, maxy-200, maxx/2, maxy-300,
maxx/2+130, maxy-200};
fillpoly(3, roof);
// Draw door
setcolor(BLACK);
setfillstyle (SOLID_FILL, BLACK);
rectangle (maxx/2-30, maxy-150, maxx/2+30, maxy-100);
floodfill (maxx/2, maxy-125, BLACK);
// Draw window
setcolor(WHITE);
setfillstyle (SOLID_FILL, WHITE);
rectangle (maxx/2-70, maxy-180, maxx/2-40, maxy-150);
floodfill (maxx/2-55, maxy-165, WHITE);
11

// Draw tree trunk


setcolor(BROWN);
setfillstyle (SOLID_FILL, BROWN);
rectangle (maxx-150, maxy-200, maxx-120, maxy-100);
floodfill (maxx-135, maxy-150, BROWN);
// Draw tree foliage
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
circle (maxx-135, maxy-250, 50);
floodfill (maxx-135, maxy-250, GREEN);
circle (maxx-170, maxy-230, 40);
floodfill (maxx-170, maxy-230, GREEN);
circle (maxx-100, maxy-230, 40);
floodfill (maxx-100, maxy-230, GREEN);
getch();
closegraph();
}
int main() {
drawScenery();
return 0;
}
12

OUTPUT
13

PERFORM COUNTDOWN FOR 30 SECONDS


#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <dos.h>
// Function to display the countdown timer
void displayCountdown(int timeLeft, int x, int y) {
char timerText[20];
// Clear the previous timer display
setfillstyle(SOLID_FILL, BLACK);
bar(x - 50, y - 20, x + 50, y + 20);
// Display the countdown time
sprintf(timerText, "%d", timeLeft);
setcolor(WHITE);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
outtextxy(x - 20, y - 10, timerText);
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
if (graphresult() != grOk) {
14

printf("Graphics initialization error: %s\n",


grapherrormsg(graphresult()));
getch();
return 1;
}
int midx = getmaxx() / 2; // Middle of the screen (x)
int midy = getmaxy() / 2; // Middle of the screen (y)
int timeLeft = 30; // Countdown starting from 30 seconds
while (timeLeft >= 0) {
cleardevice();
displayCountdown(timeLeft, midx, midy);
delay(1000);
timeLeft--;
}
// Once the countdown is finished, display "Time's up!"
setcolor(RED);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
outtextxy(midx - 120, midy + 40, "Time's up!");
getch();
closegraph();
return 0;
}
15

OUTPUT
16

PROGRAM TO DRAW TRAFFIC LIGHT SIMULATION


#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>
// Function to draw a traffic light at a given position
void drawTrafficLight(int x, int y, int red_on, int yellow_on, int
green_on) {
int light_radius = 20;
int spacing = 2 * light_radius + 10;
int body_width = 60;
int body_height = 3 * spacing + 20;
// Draw the main body of the traffic light
setfillstyle(SOLID_FILL, DARKGRAY);
bar (x - body_width / 2, y - body_height / 2, x + body_width
/ 2, y + body_height / 2);
setcolor(WHITE);
rectangle (x - body_width / 2, y - body_height / 2, x +
body_width / 2, y + body_height / 2);
// Draw the red light
if (red_on) {
setfillstyle (SOLID_FILL, RED);
17

} else {
setfillstyle (SOLID_FILL, DARKGRAY);
}
circle (x, y - spacing, light_radius);
floodfill(x, y - spacing, WHITE);
// Draw the yellow light
if (yellow_on) {
setfillstyle (SOLID_FILL, YELLOW);
} else {
setfillstyle (SOLID_FILL, DARKGRAY);
}
circle(x, y, light_radius);
floodfill (x, y, WHITE);
// Draw the green light
if (green_on) {
setfillstyle (SOLID_FILL, GREEN);
} else {
setfillstyle (SOLID_FILL, DARKGRAY);
}
circle (x, y + spacing, light_radius);
floodfill (x, y + spacing, WHITE);
}
18

int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, " ");
if (graphresult() != grOk) {
printf("Graphics initialization error: %s\n",
grapherrormsg(graphresult()));
getch();
return 1;
}
int midx = getmaxx() / 2;
int midy = getmaxy() / 2;
// Initial state: Red light on
int red = 1, yellow = 0, green = 0;
int timer = 0;
int state = 0; // 0: Red, 1: Red-Yellow, 2: Green, 3: Yellow
while (!kbhit()) {
cleardevice();
drawTrafficLight(midx, midy, red, yellow, green);
delay(500); // Delay for 0.5 seconds
timer++;
if (timer >= 4) { // Change state every 2 seconds (4 * 0.5)
timer = 0;
19

switch (state) {
case 0: // Red -> Red-Yellow
red = 1;
yellow = 1;
green = 0;
state = 1;
break;
case 1: // Red-Yellow -> Green
red = 0;
yellow = 0;
green = 1;
state = 2;
break;
case 2: // Green -> Yellow
red = 0;
yellow = 1;
green = 0;
state = 3;
break;
case 3: // Yellow -> Red
red = 1;
yellow = 0;
20

green = 0;
state = 0;
break;
}
}
}
getch();
closegraph();
return 0;
}
21

OUTPUT
22

PROGRAM TO DRAW MOVING CAR


#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
for (int i = 0; i < 550; i++) {
circle(117 + i, 320, 5);
line(110 + i, 325, 113 + i, 340);
arc(109 + i, 340, 0, 55, 17);
line(113 + i, 325, 113 + i, 335);
setcolor(11);
line(40 + i, 370, 65 + i, 370);
line(95 + i, 370, 140 + i, 370);
line(170 + i, 370, 215 + i, 370);
arc(80 + i, 370, 0, 180, 15);
setcolor(YELLOW);
circle(80 + i, 370, 12);
circle(155 + i, 370, 12);
setcolor(7);
line(40 + i, 370, 40 + i, 350);
23

line(215 + i, 370, 215 + i, 350);


line(40 + i, 350, 80 + i, 340);
line(215 + i, 350, 155 + i, 340);
setcolor(4);
line(80 + i, 340, 155 + i, 340);
arc(117 + i, 340, 0, 180, 37);
arc(215 + i, 360, 270, 90, 4);
line(117 + i, 340, 117 + i, 370);
line(125 + i, 125, 135 + i, 125);
delay(30);
cleardevice();
}
getch();
closegraph();
return 0;
}
24

OUTPUT
25

PROGRAM TO DRAW ANIMATED SMILING FACE


#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define LEFT 320
#define TOP 240
void drawFace(int x, int y) {
// Draw the face (circle)
setcolor(YELLOW);
circle(x, y, 50);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(x, y, YELLOW);
}
void drawEyes(int x, int y, int eyeBlink) {
// Draw the left eye
setcolor(WHITE);
if (eyeBlink == 0) {
circle(x - 15, y - 10, 8); // Left eye
setfillstyle(SOLID_FILL, WHITE);
floodfill(x - 15, y - 10, WHITE);
}
26

// Draw the right eye


if (eyeBlink == 0) {
circle(x + 15, y - 10, 8); // Right eye
setfillstyle(SOLID_FILL, WHITE);
floodfill(x + 15, y - 10, WHITE);
}
}
void drawMouth(int x, int y, int smile) {
// Draw the mouth (arc)
setcolor(RED);
if (smile == 1) {
arc(x, y + 20, 20, 160, 20); // Smiling mouth
} else {
arc(x, y + 20, 200, 340, 20); // Frowning mouth
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // Initialize graphics mode
int x = LEFT, y = TOP;
int eyeBlink = 0; // 0 means eyes open, 1 means eyes
closed (blink)
27

int smile = 1; // 1 for smile, 0 for frown


int frame = 0; // Frame counter for animation
// Seed the random number generator
srand(time(0));
// Main loop for animation
while (!kbhit()) {
// Clear the screen for the new frame
setbkcolor(LIGHTGRAY);
cleardevice();
// Draw the face
drawFace(x, y);
// Draw eyes, make them blink every 10 frames
if (frame % 10 == 0) {
eyeBlink = !eyeBlink; // Toggle between open and
closed eyes
}
drawEyes(x, y, eyeBlink);
// Draw the mouth (smile or frown)
if (frame % 30 < 15) {
smile = 1; // Smile
} else {
smile = 0; // Frown
28

}
drawMouth(x, y, smile);
// Randomly move the face within the window
x = rand() % (getmaxx() - 50) + 50; // Random x-
coordinate
y = rand() % (getmaxy() - 50) + 50; // Random y-
coordinate
// Pause for animation effect
delay(500); // Delay in milliseconds
// Increment frame for animation
frame++;
}
getch();
closegraph();
return 0;
}
29

OUTPUT
30

PROGRAM TO MAKE A RAINBOW


#include <graphics.h>
#include <conio.h>
void drawRainbow() {
int centerX = 320, centerY = 240;
int radius = 100;
int colors[] = {RED, YELLOW, GREEN, BLUE, MAGENTA,
CYAN, WHITE};
// Draw arcs with different colors for the rainbow
for (int i = 0; i < 7; i++) {
setcolor(colors[i]);
arc(centerX, centerY, 0, 180,radius);
radius += 15; // Increase the radius for the next arc
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
drawRainbow();
getch();
closegraph();
return 0; }
31

OUTPUT
32

PROGRAM TO DRAW A MAN WALKING IN RAIN


#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#define GroundY 400 // Ground level
void DrawManAndUmbrella(int x, int ldisp) {
// Draw the head of the man
setcolor(RED);
circle(x, GroundY - 90, 10);
// Draw the body of the man
line(x, GroundY - 80, x, GroundY - 30);
// Draw the arms of the man
line(x, GroundY - 70, x + 10, GroundY - 60);
line(x, GroundY - 65, x + 10, GroundY - 55);
// Draw the legs of the man
line(x + 10, GroundY - 60, x + 20, GroundY - 70);
line(x + 10, GroundY - 55, x + 20, GroundY - 70);
// Draw the umbrella handle and base
line(x, GroundY - 30, x + ldisp, GroundY);
line(x, GroundY - 30, x - ldisp, GroundY);
// Draw the umbrella top (arc)
33

pieslice(x + 20, GroundY - 120, 0, 180, 40);


line(x + 20, GroundY - 120, x + 20, GroundY - 70);
}
// Function to simulate rain by drawing random raindrops
void drawRain() {
setcolor(CYAN); // Set the rain color to blue
for (int i = 0; i < 100; i++) {
int x = rand() % 640; // Random x-coordinate within
screen width
int y = rand() % 480; // Random y-coordinate within
screen height
line(x, y, x, y + 5); // Draw raindrop line
}
}
void clearScreen() {
setbkcolor(LIGHTGRAY);
cleardevice();
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int x = 100; // Initial position of the man (start from left
side)
34

int ldisp = 20; // Length of umbrella spread


while (1) {
clearScreen();
drawRain();
DrawManAndUmbrella(x, ldisp);
x += 5; // Increase the x-coordinate to move the man
right
// If the man reaches the right edge of the screen, stop
moving
if (x >= getmaxx() - 100) {
break;
}
delay(50);
// Check for key press to exit
if (kbhit()) {
break;
}
}
closegraph();
return 0;
}
35

OUTPUT
36

PROGRAM TO MAKE WORKING ANALOG CLOCK


#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define CENTER_X 320
#define CENTER_Y 240
#define CLOCK_RADIUS 100
// Function to draw the clock face
void drawClockFace() {
setcolor (WHITE);
circle (CENTER_X, CENTER_Y, CLOCK_RADIUS); // Draw
clock circle
setfillstyle (SOLID_FILL, WHITE);
floodfill (CENTER_X, CENTER_Y, WHITE);
// Draw the clock numbers
setcolor (WHITE);
for (int i = 1; i <= 12; i++) {
int angle = 30 * I; // Calculate the angle for each number
int x = CENTER_X + (int) (CLOCK_RADIUS * 0.85 * cos
(angle * M_PI / 180.0));
37

int y = CENTER_Y - (int)(CLOCK_RADIUS * 0.85 * sin(angle


* M_PI / 180.0));
char num[3];
sprintf(num, "%d", i);
outtextxy(x - 10, y - 10, num); // Display the number
}
}
// Function to draw the clock hands
void drawClockHands(int hr, int min, int sec) {
int hrAngle = 90 - (hr % 12) * 30 - (min / 2); // Hour hand
angle
int minAngle = 90 - min * 6; // Minute hand angle
int secAngle = 90 - sec * 6; // Second hand angle
// Draw the hour hand
int hrLength = CLOCK_RADIUS / 2;
int hrX = CENTER_X + (int)(hrLength * cos(hrAngle * M_PI /
180.0));
int hrY = CENTER_Y - (int)(hrLength * sin(hrAngle * M_PI /
180.0));
setcolor(RED);
line(CENTER_X, CENTER_Y, hrX, hrY);
// Draw the minute hand
int minLength = CLOCK_RADIUS * 0.75;
38

int minX = CENTER_X + (int)(minLength * cos(minAngle *


M_PI / 180.0));
int minY = CENTER_Y - (int)(minLength * sin(minAngle *
M_PI / 180.0));
setcolor(GREEN);
line(CENTER_X, CENTER_Y, minX, minY);
// Draw the second hand
int secLength = CLOCK_RADIUS * 0.85;
int secX = CENTER_X + (int)(secLength * cos(secAngle *
M_PI / 180.0));
int secY = CENTER_Y - (int)(secLength * sin(secAngle * M_PI
/ 180.0));
setcolor(CYAN);
line(CENTER_X, CENTER_Y, secX, secY);
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // Initialize graphics mode
while (!kbhit()) {
// Get the current time
time_t t;
struct tm *tmInfo;
t = time(NULL);
39

tmInfo = localtime(&t);
int hr = tmInfo->tm_hour; // Current hour
int min = tmInfo->tm_min; // Current minute
int sec = tmInfo->tm_sec; // Current second
cleardevice();
// Draw the clock face and hands
drawClockFace();
drawClockHands(hr, min, sec);
delay(1000);
}
closegraph();
return 0;
}
40

OUTPUT
41

PROGRAM TO FILL THE CIRCLE WITH DIFFERENT


PATTERNS
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
// Function to get a random color
int getRandomColor() {
return rand() % 15 + 1; // Random color from 1 to 15
}
// Function to get a random fill pattern
int getRandomPattern() {
return rand() % 12; // Random pattern from 0 to 11
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, " ");
int screenWidth = getmaxx();
int screenHeight = getmaxy();
int radius = 50;
int y = radius; // Start at the top
srand(time(NULL));
42

while (!kbhit()) { // Loop until a key is pressed


int color = getRandomColor();
int pattern = getRandomPattern();
cleardevice();
setcolor(color);
setfillstyle(pattern, color);
// Draw and fill circle
circle(screenWidth / 2, y, radius);
floodfill (screenWidth / 2, y, color);
delay(20000); // 20 seconds delay
y += 50; // Move down
if (y + radius > screenHeight) {
y = radius; // Reset to top if it reaches bottom
}
}
closegraph();
return 0;
}
43

OUTPUT
44

PROGRAM TO DRAW CONCENTRIC CIRCLES OF


DIFFERENT COLOURS AND PATTERNS
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
void drawConcentricCircles(int numCircles) {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Get screen dimensions
int maxx = getmaxx();
int maxy = getmaxy();
// Center coordinates
int centerX = maxx / 2;
int centerY = maxy / 2;
// Starting radius and increment
int radius = 30;
int radiusIncrement = 30;
// Check if number of circles is valid
if (numCircles <= 0) {
printf("Please enter a positive number of circles!");
return;
}
45

// Draw concentric circles


for (int i = 0; i < numCircles; i++) {
// Set color (cycles through 15 colors)
setcolor(i % 15 + 1);
// Set line style (cycles through 4 patterns)
setlinestyle(i % 4, 0, 1);
// Draw circle
circle(centerX, centerY, radius);
// Increase radius for next circle
radius += radiusIncrement;
}
getch();
closegraph();
}
int main() {
int numCircles;
printf("Enter the number of concentric circles to draw: ");
scanf("%d", &numCircles);
drawConcentricCircles(numCircles);
return 0;
}
46

OUTPUT
47

PROGRAM TO PRINT YOUR NAME IN ENGLISH USING


INBUILT PRIMITIVES
#include <graphics.h>
#include <conio.h>
void drawLetterA(int x, int y) {
line(x, y, x + 20, y - 40);
line(x + 20, y - 40, x + 40, y);
line(x + 10, y - 20, x + 30, y - 20);
}
void drawLetterB(int x, int y) {
line(x, y, x, y - 40);
arc(x + 10, y - 30, 270, 90, 10);
arc(x + 10, y - 10, 270, 90, 10);
}
void drawLetterC(int x, int y) {
arc(x + 20, y - 20, 60, 300, 20);
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, " ");
int startX = 100, startY = 200;
drawLetterA(startX, startY);
48

drawLetterB(startX + 50, startY);


drawLetterC(startX + 100, startY);
getch();
closegraph();
return 0;
}
49

OUTPUT
50

PROGRAM TO IMPLEMENT BOUNCING BALL IN SINE


CURVE SHAPE
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define WIDTH 800
#define HEIGHT 600
#define BALL_RADIUS 20
#define AMPLITUDE 100
#define FREQUENCY 0.02
#define SPEED 4
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, " ");
int x = 0;
int y_offset = HEIGHT / 2;
while (!kbhit()) {
cleardevice();
// Compute y position based on sine wave
int y = y_offset + AMPLITUDE * sin(FREQUENCY * x);
51

// Draw ball
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
fillellipse(x, y, BALL_RADIUS, BALL_RADIUS);
delay(20); // Control speed
x += SPEED;
if (x > getmaxx()) {
x = 0;
}
}
closegraph();
return 0;
}
52

OUTPUT
53

PROGRAM TO DRAW A CHESS BOARD


#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
int x, y, size = 50;
initgraph(&gd, &gm, " ");
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
x = col * size;
y = row * size;
// Alternate color between white and black
if ((row + col) % 2 == 0)
setfillstyle(SOLID_FILL, WHITE);
else
setfillstyle(SOLID_FILL, BLACK);

bar(x, y, x + size, y + size);


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

You might also like