drawing a circle

Started by
4 comments, last by neon_prannock 19 years, 6 months ago
i am trying to draw a circle on the screen. when i first click the mouse that is the center of the circle and when i click the mouse again that is the size of the circle. i dont want to use any functions. cant realy figure out all the maths stuff. if anyone has working code. or any help would be greatful thanks in advance ructions
Advertisement
If you can figure all the circle drawing maths out then what are you asking? How to register the click? How to actually draw to a window? And what language are you using?

EDIT: Sorry, read cant as can. I really need to pay attention.
To draw a circle:Bresenham's circle drawing algorithm

To draw a circle in the way you are talking about here, you would have to find the distance between the two points that were clicked, then draw a circle with said radius. Use the distance equation ("distance = sqrt(x2 - x1)^2 + (y2 - y1)^2)") to calculate the distance between the two clicks.

I wouldn't worry about writing my own circle-drawing algorithm. Just use those that are provided with the API.

I use this code to draw a circle:

*******
0>a
Repeat
DrawPoint(x*cos(a),x*sin(a))
a+(PI/72)>a
until a=2(PI)
*******

You have to adapt the code to the language your using!

Before you put this code you have to set the cursor to the center of the circle. This code wil draw many points until the circle is formed. The "x" is how big is the circle. If you want to draw more or less points of the circle just change the "72", (+72>+points)(-72>-points).

I hope this code helps! ;-)
Web site > http://sergiosantos.info
Quote:Original post by neon_prannock
I use this code to draw a circle:

*******
0>a
Repeat
DrawPoint(x*cos(a),x*sin(a))
a+(PI/72)>a
until a=2(PI)
*******

You have to adapt the code to the language your using!

Before you put this code you have to set the cursor to the center of the circle. This code wil draw many points until the circle is formed. The "x" is how big is the circle. If you want to draw more or less points of the circle just change the "72", (+72>+points)(-72>-points).

I hope this code helps! ;-)


One problem with this method is that it is not based on pixels but angles. When drawing large circles you will end up with more of a dot-to-dot representation of a circle instead of an actual solid circle. You could solve this by drawing lines from one point to the next instead of just drawing dots. Another problem is that you will be doing far more calculations than necessary on small circles because you may very well end up filling in the same pixel more than once with this algorithm and because circles have symetry that can be exploited to reduce the number of multiplications to be done. You may also find that the edge of your circle is somewhat "dirty" because of loss of precision and rounding errors when convertinging a floating point result of your trig expressions to integers for use on the screen.
That's the only code I know to draw a circle without using a function. I prefer it because it is easier to understand, but I know it doesn't have many possibilities. And throught this code you can create an more complex code, depending on the case you want to use the circle.
Web site > http://sergiosantos.info

This topic is closed to new replies.

Advertisement