Created
February 28, 2016 18:45
-
-
Save kp96/604ed7d23b21846b6519 to your computer and use it in GitHub Desktop.
Cirlce Drawing using Midpoint Algorithm
This file contains 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, "Midpoint Circle Drawing"); | |
int xc = 320, yc = 240; //co-ordinates | |
int r = 30; // radius | |
int p = 1 - r; //initial decision | |
int y = r; | |
for(int x = 0; x <= y; x++) { | |
if(p <= 0) { | |
p = p + 2 * x + 3; | |
} | |
else { | |
y = y - 1; | |
p = p + 2 * (x - y) + 5; | |
} | |
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