Q:

Write a C Program to Draw Circle using Bresenham’s Circle Algorithm

0

Write a C Program to Draw Circle using Bresenham’s Circle Algorithm. Here’s simple Program to Draw Circle using Bresenham’s Circle Algorithm in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C Program to Draw Circle using Bresenham’s Circle Algorithm which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 


SOURCE CODE : :

/*  C Program to Draw Circle using Bresenham’s Circle Algorithm  */

#include <stdio.h>
#include <dos.h>
#include <graphics.h>
void plotPoints(int cx, int cy, int x, int y) {
        putpixel(cx+x, cy+y, RED);
        putpixel(cx-x, cy+y, RED);
        putpixel(cx+x, cy-y, RED);
        putpixel(cx-x, cy-y, RED);
        putpixel(cx+y, cy+x, RED);
        putpixel(cx-y, cy+x, RED);
        putpixel(cx+y, cy-x, RED);
        putpixel(cx-y, cy-x, RED);
}
void main() {
        int cx, cy, x = 0, y, r, p;
        int gd = DETECT, gm;
        clrscr();
        printf("Enter the coordinates of centre of the circle: ");
        scanf("%d %d", &cx, &cy);
        printf("Enter radius of : ");
        scanf("%d", &r);
        y = r;
        p = 3 - 2 * r;
        initgraph(&gd, &gm, "");
        cleardevice();
        while (x < y) {
                plotPoints(cx, cy, x, y);
                x++;
                if (p < 0)
                                        p = p + 4 * x + 6; else {
                        y--;
                        p = p + 4 * (x - y) + 10;
                }
                plotPoints(cx, cy, x, y);
                delay(200);
        }
        getch();
}

Above is the source code for C Program to Draw Circle using Bresenham’s Circle Algorithm which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Graphic Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to perform 2D Transformations in... >>
<< Write a C Program to Draw a Circle using Mid-Point...