<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Mosaic effect</title>
		<link>http://www.allegro.cc/forums/view/589317</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 30 Dec 2006 11:09:33 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would like to use a mosaic effect in my game, but am frankly at a loss as to how to implement such an effect. Has anyone implemented a mosaic effect before? Do you have any suggestions?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ngiacomelli)</author>
		<pubDate>Fri, 29 Dec 2006 04:08:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No idea, but here&#39;s how I would take a stab at it (changing a graphic to mosaic)</p><p>1)  Define how your mosaic pieces should look.  Typically, a single piece is dark on the border and the same color elsewhere (the middle). <br />2)  Define how big your pieces are (could be passed into the function that does the dirty work)<br />3)  Move along the graphic and group any pixels that are close in color (what that means is questionable) to form your mosaic pieces<br />4)  Change each group to the average color (any pixel not this color in the group force to this color)<br />5)  Output all your mosaic pieces</p><p>Of course, there&#39;s plenty of gotcha&#39;s in the above algorithm, but I did say, &quot;no idea&quot; at the beginning of the post.</p><p>Actually, I did the above method for a game I was making earlier this year called Cosmos.  Only, instead of grouping by color difference, I grouped by height difference.  To see the progress of that, you can look at the pictures in <a href="http://comp.uark.edu/~uagdc/phpBB2/viewtopic.php?t=132&amp;sid=f5df2f2fd0bb93689ec507d365ea15a7">this thread</a>.</p><p>Hope I&#39;ve been of some help...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Fri, 29 Dec 2006 04:19:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What kind of mosaic are we talking here? If you mean the pixelation thing, that should be very straightforward.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 29 Dec 2006 09:17:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or do you mean something a bit more advanced?<br /><span class="remote-thumbnail"><span class="json">{"name":"Mosaic1.JPG","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/c\/0c28df5b2a9d48e56986b0c53e88a7bd.jpg","w":300,"h":254,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/c\/0c28df5b2a9d48e56986b0c53e88a7bd"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/c/0c28df5b2a9d48e56986b0c53e88a7bd-240.jpg" alt="Mosaic1.JPG" width="240" height="203" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Fri, 29 Dec 2006 22:32:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or do you want a real collage-style mosaic?</p><p><a href="http://www.complang.tuwien.ac.at/schani/metapixel/">Metapixel</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Sat, 30 Dec 2006 07:50:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s some mock-up code I just wrote. There&#39;s probably much more efficient ways to do this, but since I&#39;ve never done this before I figured this was the simplest method:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">void</span> Bitmap2Mosaic <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bitmap, <span class="k1">int</span> xpixel, <span class="k1">int</span> ypixel<span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td>  <span class="c">// xpixel and ypixel define the size of each pixel in the mosaic.</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td>  <span class="k1">int</span> xp <span class="k3">=</span> xpixel <span class="k3">-</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>  <span class="k1">int</span> yp <span class="k3">=</span> ypixel <span class="k3">-</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>  <span class="k1">int</span> c<span class="k2">;</span></td></tr><tr><td class="number">8</td><td>  <span class="k1">int</span> z, zz<span class="k2">;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>  <span class="k1">if</span> <span class="k2">(</span>bitmap <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span> <span class="k1">return</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>  <span class="k1">for</span> <span class="k2">(</span>z <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> z <span class="k3">&lt;</span> bitmap-&gt;w<span class="k2">;</span> z <span class="k3">+</span><span class="k3">=</span> xpixel<span class="k2">)</span></td></tr><tr><td class="number">13</td><td>    <span class="k1">for</span> <span class="k2">(</span>zz <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> zz <span class="k3">&lt;</span> bitmap-&gt;h<span class="k2">;</span> zz <span class="k3">+</span><span class="k3">=</span> ypixel<span class="k2">)</span></td></tr><tr><td class="number">14</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">15</td><td>      c <span class="k3">=</span> <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a><span class="k2">(</span>bitmap,z,zz<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td>      <a href="http://www.allegro.cc/manual/rectfill" target="_blank"><span class="a">rectfill</span></a><span class="k2">(</span>bitmap,z,zz,z<span class="k3">+</span>xp,zz<span class="k3">+</span>yp,c<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">18</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

If your game only uses one colour depth you could make this routine a little faster by replacing getpixel() with one of the _getpixel() commands. Or another change could be to add a second bitmap reference to the prototype which would become the target bitmap. (And the first would be the source.)</p><p>Presuming that&#39;s the effect you want. I&#39;ve heard people call trails left by objects a mosaic effect. If <i>that&#39;s</i> what you mean then the process is obviously entirely different and can be done in a number of ways depending on exactly the effect you&#39;re going for.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Sat, 30 Dec 2006 11:09:33 +0000</pubDate>
	</item>
</rss>
