-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_raster.cpp
More file actions
37 lines (28 loc) · 784 Bytes
/
circle_raster.cpp
File metadata and controls
37 lines (28 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
void drawCircleRaster(int cx, int cy, int r, int color) {
int x = cx - r;
while (x <= cx + r) {
// Calculate y using circle equation: x² + y² = r²
double y = sqrt((double)(r * r) - (double)((x - cx) * (x - cx)));
// Plot upper and lower halves
putpixel(x, cy + (int)round(y), color);
putpixel(x, cy - (int)round(y), color);
x++;
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, (char*)"");
int cx, cy, r;
printf("Enter center (cx cy): ");
scanf("%d %d", &cx, &cy);
printf("Enter radius r: ");
scanf("%d", &r);
drawCircleRaster(cx, cy, r, WHITE);
getch();
closegraph();
return 0;
}