Home > Cpp Graphics > C++ Graphics – 04 – Circle program by Midpoint Algorithm

C++ Graphics – 04 – Circle program by Midpoint Algorithm

December 4, 2009 Leave a comment Go to comments

Circle program by Midpoint Algorithm.

This algorithm draws all eight octants simultaneously, starting from each cardinal direction (0°, 90°, 180°, 270°) and extends both ways to reach the nearest multiple of 45° (45°, 135°, 225°, 315°). You can determine where to stop because when y = x, you have reached 45°.

#include <graphics.h>
#include <conio.h>
#include <dos.h>

void CirclePoints(int x, int y){
	putpixel(x+320, y+240, WHITE);
	putpixel(y+320, x+240, WHITE);
	putpixel(y+320, -x+240, WHITE);
	putpixel(x+320, -y+240, WHITE);
	putpixel(-x+320, -y+240, WHITE);
	putpixel(-y+320, -x+240, WHITE);
	putpixel(-y+320, x+240, WHITE);
	putpixel(-x+320, y+240, WHITE);

void MidPointCircle(int r){
	int x = 0;
	int y = r;
	double d = 5.0/4.0 - r;
	CirclePoints(x, y);
	while(y > x){
		if(d < 0)
			d += 2.0 * x + 3.0;
			d += 2.0 * (x - y) + 5.0;
		CirclePoints(x, y);

void main(){
	int gd=DETECT, gm;
	initgraph(&gd, &gm, "\\tc");

Bresenham’s Circle algorithm is derived from the Midpoint Circle algorithm.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: