Draw a Circle using Bresenham’s Circle Algorithm

On July 27, 2012, in Algorithms, Drawing, Shapes, by , Views : 13140




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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();
}
 
/****************************************************************************/
/***********                WWW.CGLABPROGRAMS.COM                 ***********/
/****************************************************************************/



Hope, it helps! :)



Tagged with:  

9 Responses to Draw a Circle using Bresenham’s Circle Algorithm

  1. PAGAR BHARATI says:

    nice………

  2. ujas says:

    it is complileb but can not run

  3. sameer says:

    thank u for this
    but can u give me program code for translating rotating scaling reflection sharing using matrix multiplication
    i done with polygon program using matrix multiplication
    but i don’t have any idea for circle
    and how to change filled color after transformation of object

  4. Nabanita says:

    good

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

  • Dipin Krishna

Archives

All entries, chronologically...

Read more:
Scaling_Scaled_Figure
2D Transformations: Scaling

kite
Flying Kite

ellipse
Ellipse using Mid-Point Algorithm

MinMaxClose