#include<stdio.
h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
// Function to draw a line using DDA algorithm
void drawline(int x1, int y1, int x2, int y2);
void plotCirclePoints(int xc, int yc, int x, int y);
void drawCircle(int xc, int yc, int r);
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
drawCircle(300,130,100);
drawCircle(300,130,95);
drawCircle(300,130,2);
drawline(250,218,250,410);
drawline(350,218,350,410);
drawline(300,230,300,350);
drawCircle(300,360,10);
drawline(220,410,380,410);
drawline(220,430,380,430);
drawline(220,410,220,430);
drawline(380,410,380,430);
drawline(305,130,360,130);
drawline(300,125,300,95);
outtextxy(300,200,"6");
outtextxy(370,130,"3");
outtextxy(230,130,"9");
outtextxy(298,50,"12");
// Fill colors into shapes
setfillstyle(SOLID_FILL, BROWN);
floodfill(397,130, WHITE); // Circle
setfillstyle(SOLID_FILL,RED);
floodfill(305,340,WHITE);
setfillstyle(SOLID_FILL, CYAN);
floodfill(270,413,WHITE);
setfillstyle(SOLID_FILL, 13);
floodfill(380,130,WHITE);
getch();
closegraph();
}
// Function to draw a line using DDA algorithm
void drawline(int x1, int y1, int x2, int y2) {
float x, y, xinc, yinc, dx, dy;
int steps, i;
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xinc = dx / steps;
yinc = dy / steps;
x = x1;
y = y1;
for (i = 0; i <= steps; i++) {
putpixel(x, y, WHITE); // Use WHITE for boundaries
x += xinc;
y += yinc;
}
}
void drawCircle(int xc, int yc, int r) {
int x = 0;
int y = r;
int p = 1 - r; // Initial decision parameter
// Plot the initial points
plotCirclePoints(xc, yc, x, y);
while (x < y) {
x++;
if (p < 0) {
p = p + 2 * x + 1;
} else {
y--;
p = p + 2 * x - 2 * y + 1;
}
// Plot the points for the current x and y
plotCirclePoints(xc, yc, x, y);
}
}
// Function to plot points of the circle in all octants
void plotCirclePoints(int xc, int yc, int x, int y) {
putpixel(xc + x, yc + y, WHITE); // Octant 1
putpixel(xc - x, yc + y, WHITE); // Octant 2
putpixel(xc + x, yc - y, WHITE); // Octant 3
putpixel(xc - x, yc - y, WHITE); // Octant 4
putpixel(xc + y, yc + x, WHITE); // Octant 5
putpixel(xc - y, yc + x, WHITE); // Octant 6
putpixel(xc + y, yc - x, WHITE); // Octant 7
putpixel(xc - y, yc - x, WHITE); // Octant 8
}