Created
February 28, 2016 18:22
-
-
Save kp96/c71676aa4560f06377f5 to your computer and use it in GitHub Desktop.
CirleDrawingAlgorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <graphics.h> | |
#include <math.h> | |
int max(int a, int b) {return a > b ? a : b;} | |
void draw_cirlce(int, int, int, int); | |
int main(int argc, char const *argv[]) | |
{ | |
int gd = DETECT, gm; | |
initgraph(&gd, &gm, "Bresenham Circle Drawing"); | |
int xc = 320, yc = 240; //co-ordinates | |
int r = 30; // radius | |
int d = 3 - 2 * r; //initial decision | |
int y = r; | |
for(int x = 0; x <= y; x++) { | |
if(d < 0) { | |
d = d + 4 * x + 6; | |
} | |
else { | |
y = y - 1; | |
d = d + 4 * (x - y) + 10; | |
} | |
draw_cirlce(xc, yc, x, y); | |
} | |
getch(); | |
} | |
void draw_cirlce(int xc, int yc, int x, int y) { | |
putpixel(xc+x,yc-y,1); | |
putpixel(xc-x,yc-y,2); | |
putpixel(xc+x,yc+y,3); | |
putpixel(xc-x,yc+y,4); | |
putpixel(xc+y,yc-x,5); | |
putpixel(xc-y,yc-x,6); | |
putpixel(xc+y,yc+x,7); | |
putpixel(xc-y,yc+x,8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment