Practical No.
Name :- Ambatkar Atharv Uday
Roll no. :- 23CO007
Batch :- A
#include <iostream>
#include <graphics.h>
#include <math.h>
using namespace std;
void circle_1(int xc, int yc, int r) {
int x = 0;
int y = r;
int s = 3 - 2 * r;
while (x <= y) {
putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);
if (s< 0) {
s+= 4 * x + 6;
} else {
s+= 4 * (x - y) + 10;
y--;
x++;
void line_DDA(int x1, int y1, int x2, int y2) {
int dx = x2 - x1;
int dy = y2 - y1;
int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
float x_inc = dx / (float)steps;
float y_inc = dy / (float)steps;
float x = x1;
float y = y1;
for (int i= 0; i<= steps; i++) {
putpixel(round(x), round(y), WHITE);
x+= x_inc;
y+=y_inc;
}
int main() {
int xc, yc, r;
cout << "Enter coordinates of circle and radius : ";
cin >>xc;
cin>>yc;
cin>>r;
// To draw first big circle
circle_1(xc, yc, r);
// To Draw the equilateral triangle inside the circle by coordinates of line
int x1 = xc, y1 = yc - r;
int x2 = xc - r * sqrt(3) / 2, y2 = yc + r / 2;
int x3 = xc + r * sqrt(3) / 2, y3 = yc + r / 2;
line_DDA(x1, y1, x2, y2);
line_DDA (x2, y2, x3, y3);
line_DDA (x3, y3, x1, y1);
circle_1(xc, yc, r / 2); //To draw small circle inside the first big one
getch();
closegraph();
return 0;