# How can I Implement pie chart

how can I Implement pie chart with texture and I can control percent of pie chart?

Disclaimer: I have no experience in rendering pie charts.
Well, to render such things, you could use a line drawing algorithm and a circle drawing algorithm.
The way it would work is, for each pixel drawn in the circle, draw a line from that pixel to the center of the circle. That way, you would get a filled circle AND you could control the colors of different zones in the circle.
To control percentage, first find the circumference of the circle. Then, divide each percentage by that circumference. And you will get how much pixels of the circle must be drawn to represent that percentage.
Hope this helps.

You can use the Bresenham’s circle algorithm described here:

However, this wikipedia page does not have any implementations. If you are looking for that, try the French page(The C# implementation is in English).

And, for lines, SDL_RenderDrawLines should do the trick.

if SDL2 support render triangle with texture，this problem can be solve easily。

I had a play with the example in the french wikipedia page, just for drawing filled circles.
it doesn’t work too well if you’re using alpha, looks sort of cool though:

Because the dumb forum won’t let me post more than one image because I’m new, here’s a shot using full alpha:

Both those were using RenderDrawLine

I tried using RenderDrawPoint to see how that would look, but I get “No hardware accelerated renderers available” for that.

BTW @alittle, the Midpoint circle algorithm page that aasrv linked explains how to do arcs
Here,
I’m not in the mood to implement the math on it though.

in game，your solution is too Inefficiency。pie chart often used to show Skill Cooling of game