Sunday, May 3, 2009

C Program for Bresenham Circle Drawing algorithm

# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>

void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;

initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();


printf("Enter the radius ");
scanf("%d",&r);


x=0;
y=r;
putpixel(xc+x,yc-y,1);

p=3-(2*r);

for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;

p=p+((4*(x-y)+10));
}

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);

}
getch();
closegraph();
}

21 comments:

Nameet Nayan said...

this code is working yaar.....thanks..

i want a program for "plot the sin(x),x is 0 to 2pi,using character '*'...if u get it plz mail me ...my id is namit.nayan@gmail.com

Angad said...

I am busy with my final year preps, so ill try to post the program here!

rick120 said...

and algorithm clipping circles???...please...

reckonme said...

thanks u so much dude....

Anonymous said...

yippyiiiiiiiiii i draw the circle

Anonymous said...

thnx dude.

Anonymous said...

Rohit:
How can intensity of a pixel be controlled ?
Suppose, if I want to assign 30% of any drawing color to a pixel, what should be the code?
How will I pick a shed of a color from color palette or look-up table through coding?
Please help me. mail me in the following e-mail id with answer:
rohitju50@yahoo.com

Anonymous said...

Thank You, you are superb...

murad khan said...

wow!! its work..............

maria said...

Hi

I am trying to compile this code in Visual Studio 2008 but an erro occurs
"fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory"

what is going worng? I cannot compile it to Visual Studio? Can I use another program to compile it

Thanks
Maria

Anonymous said...

The code is not working because of putpixel points are not correctly implemented

Manjesh P M said...

y=y; what this line meant for?

Ashwin said...

Perfect program (Y) works perfectly !

Unknown said...

I want the algorithm for this..

Anonymous said...

HAHAHAHAHAAH Supeb program guys.....keep doing...

Anonymous said...

Amazing work is done, Man! I also checked out another article on graphics program. Must check: <a href="http://www.codingalpha.com/bresenham-line-drawing-algorithm-c-program/>C Program For Bresenham Line Drawing Algorithm</a>.

Unknown said...

What is out put this program

Tutorialspoint said...

sap wm Online Training
SAP Tutorial sap wm Online Training
sap c4c Online Training
sap hana Online Training
SAP Lumira Online Training

Leona Knight said...

My name is Donald Boykins, I'm here to appreciate Dr Akhigbe for using his herbal medicine to cure my herpes virus. Is about 3 years and 6 months now I have been living with this virus and it have really really be a serious problem to me, I was so confused cause I have been taking several drugs to be cure but all of my effort was in vain, one morning was browsing through the internet then I saw several testimonies about Dr Akhigbe curing people from herpes virus and Immediately I contacted Dr Akhigbe on his email:  drrealakhigbe@gmail.com. I told him about my troubles and he told me that I must be cured. He gave me instructions and which I rightly followed, so he prepared a herbal medicine and sent it to me which I used for three weeks and I was cured totally everything was like a dream to me and my herpes was permanently gone. Dr Akhigbe God bless you and give you the power and wisdom for more cure, I don't know if there is any one out there suffering for herpes virus or any other of there diseases. DIABETES, CANCER, HIV/AIDS, HERPES, HEPATITIS A&B, HEART DISEASES, CHRONIC DISEASES,  YELLO FEVER, EPILEPSY, LUPUS, STRIKE, SPINAL CORD, ECZEMA, KIDNEY DISEASES, ACME, BACK PAIN,   DENGUE SCHIZOPHRENIA, POLIO,MULTIPLES SCLEROSIS, HIGH BLOOD PRESSURE, VAGINAL  DISCHARGETHYROID, ARTHRITIS, MENINGITIS.etcWhy don't you contact Doctor Akhigbe and be free from your diseases because he is very good and honest herbalist doctor, he is also know as the godfather of herbal root. Contact him now via his email:   drrealakhigbe@gmail.com         or whatsapp   him on     +2349010754824.         website https:drrealakhigbe.weebly.com.     

smith Morgan said...

HOW I GOT CURED OF HERPES DISEASE
I'm here to testify about what DR. OSO did for me. I have been suffering from (HERPES) disease for the past 5 years and had constant pain,especially inside my body. During the first year,I had faith in God that I would be healed someday. This disease started circulating all over my body and I have been taking treatment from my doctor, few weeks ago I came across a testimony of one lady on the internet testifying about a Man called DR. OSO on how he cured her from herpes disease. And she also gave the email address of this man and advised anybody to contact him for help for any kind of sickness that he would be of help.so I emailed him telling him about my (HERPES) he told me not to worry that i was going to be cured!! Well I never believed it,, well after all the procedures and remedies given to me by this man few weeks later i started experiencing changes all over me as DR. OSO assured me that I will be cured,after some time. I went to my doctor to confirm if I had finally healed Behold, it was TRUE,the test came out negative. So friends my advice is if you have such sickness or any other at all you can contact DR. OSO for help.

Email} drosohaberhome@gmail.com

WhatsApp /call +2348162084839

https://sites.google.com/view/drosohaberhome/

His blog pagehttps://drosohaberhome.blogspot.com

you can also email me for more information about DR oso via smithmorgan2777@gmail.com ALL THANK TO DR OSO

Carter Michael said...

Am here to let the whole world know that I was diagnose of herpes 3 years ago where all hope was lost and I had nothing to do about it,I just accepted the faith that one day I will cure of this disease and I just pray everyday for a helper and one day my sister introduce me to a herbal doctor man called Dr Aire that she saw him on internet well I contact him on his email,I was not fully convinced until he sent me the herbal medicine which he ask me to take for two weeks I took it with faith and i went for a retest in different hospitals and today am cured of this disease and am also using this medium to let all those having STD,like herpes and the rest not to give up,their is a man who can cure you,his name is Dr Aire . contact the great herbalist via his email; (drairehome@gmail.com) or /WhatsApp +2347036740271 ..............