Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <math.h>
- void safe_putpixel(int x, int y, int color) {
- putpixel(
- x < 0 ? 0 : x,
- y < 0 ? 0 : y,
- color);
- }
- void draw_circle(int x, int y, int radius) {
- int diameter = radius * 2;
- for (int i = 0; i < diameter; i++) {
- int xshift = sqrt(pow(radius, 2) - pow(i, 2));
- for (int j = 0; j < xshift; j++) {
- safe_putpixel(x + j, y - i, GREEN);
- safe_putpixel(x + j, y + i, GREEN);
- safe_putpixel(x + j - xshift, y - i, GREEN);
- safe_putpixel(x + j - xshift, y + i, GREEN);
- }
- }
- }
- int main() {
- int graphics_driver = DETECT;
- int gmode;
- initgraph(&graphics_driver, &gmode, "");
- draw_circle(0, 50, 10);
- getch();
- closegraph();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement