<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>generating a pie chart</title>
		<link>http://www.allegro.cc/forums/view/608432</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 25 Sep 2011 02:15:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to generate a pie chart using only allegro 5 primitives. Each &quot;slice&quot; of the pie is a different color. I was going to make triangles for each slice then put a circle behind it to make it look rounded. But I&#39;m having trouble calculating the x and y positions of the triangles.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Sat, 24 Sep 2011 21:02:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I assume your slices store the percentage they have. So you can iterate over all the slices, multiply the percentage by 2*PI and you have the angle range. Then, just iterate over the slices and keep adding each range while using sin/cos*radius to get the y/x coordinates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sat, 24 Sep 2011 21:28:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608432/932073#target">shadyvillian</a> said:</div><div class="quote"><p>I was going to make triangles for each slice then put a circle behind it to make it look rounded</p></div></div><p>

I don&#39;t see how this could work, unless you&#39;re planning to have a very bumpy pie.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sat, 24 Sep 2011 21:55:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Untested:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">float</span> percentages<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span><span class="n">10</span>, <span class="n">20</span>, <span class="n">40</span>, <span class="n">30</span><span class="k2">}</span><span class="k2">;</span>
<span class="k1">size_t</span> num_pieces <span class="k3">=</span> <span class="n">4</span><span class="k2">;</span>
<span class="k1">float</span> cur_theta <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k1">float</span> cx <span class="k3">=</span> <span class="n">200</span>, cy <span class="k3">=</span> <span class="n">200</span>, r <span class="k3">=</span> <span class="n">100</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> colors<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span>...<span class="k2">}</span><span class="k2">;</span> 

<span class="k1">for</span><span class="k2">(</span><span class="k1">size_t</span> ii <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> ii <span class="k3">&lt;</span> num_pieces<span class="k2">;</span> ii<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">float</span> delta_theta <span class="k3">=</span> percentages<span class="k2">[</span>ii<span class="k2">]</span> <span class="k3">/</span> <span class="n">100</span>.<span class="n">0</span> <span class="k3">*</span> <span class="n">2</span>.<span class="n">0</span> <span class="k3">*</span> <a href="http://www.allegro.cc/manual/ALLEGRO_PI"><span class="a">ALLEGRO_PI</span></a><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_draw_arc"><span class="a">al_draw_arc</span></a><span class="k2">(</span>cx, cy, r <span class="k3">/</span> <span class="n">2</span>, cur_theta, delta_theta, color<span class="k2">[</span>ii<span class="k2">]</span>, r <span class="k3">/</span> <span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
    cur_theta <span class="k3">+</span><span class="k3">=</span> delta_theta<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

You can also swipe the <span class="source-code">al_draw_filled_pieslice</span> from the 5.1 branch, which you would use instead of the <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_arc"><span class="a">al_draw_arc</span></a></span>. One bonus of using <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_arc"><span class="a">al_draw_arc</span></a></span> here, though, is that you can make those ring charts instead of simple pie charts.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 24 Sep 2011 22:08:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">SiegeLord</a> said:</div><div class="quote"><p>You can also swipe the al_draw_filled_pieslice from the 5.1 branch</p></div></div><p>

Wheres the 5.1 branch?</p><p>EDIT: I think I found it but I&#39;m guessing I have to build it myself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Sat, 24 Sep 2011 23:45:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, the question to ask is why my solution isn&#39;t acceptable for you. It&#39;s only issue is that it draws 2x more polygons than it should. Either way, instead of building the entire 5.1 I&#39;d just go <a href="http://svn.tomasu.org/index.cgi/allegro/view/allegro/branches/5.1/addons/primitives/high_primitives.c">here</a> and copy-paste <span class="source-code">al_draw_filled_pieslice</span> for your own use.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 25 Sep 2011 00:15:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, I was just curious. I&#39;m testing it right now, but theres a bug my data analyzer so i need to get that working right to see what my results are. </p><p>EDIT:  ok I got it working everything looks good.<br />EDIT2: would anti-aliasing help the edge of the circle look smoother?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (shadyvillian)</author>
		<pubDate>Sun, 25 Sep 2011 02:15:38 +0000</pubDate>
	</item>
</rss>
