Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Mosaic effect

This thread is locked; no one can reply to it. rss feed Print
Mosaic effect
ngiacomelli
Member #5,114
October 2004

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?

Onewing
Member #6,152
August 2005
avatar

No idea, but here's how I would take a stab at it (changing a graphic to mosaic)

1) Define how your mosaic pieces should look. Typically, a single piece is dark on the border and the same color elsewhere (the middle).
2) Define how big your pieces are (could be passed into the function that does the dirty work)
3) Move along the graphic and group any pixels that are close in color (what that means is questionable) to form your mosaic pieces
4) Change each group to the average color (any pixel not this color in the group force to this color)
5) Output all your mosaic pieces

Of course, there's plenty of gotcha's in the above algorithm, but I did say, "no idea" at the beginning of the post.

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 this thread.

Hope I've been of some help...

------------
Solo-Games.org | My Tech Blog: The Digital Helm

X-G
Member #856
December 2000
avatar

What kind of mosaic are we talking here? If you mean the pixelation thing, that should be very straightforward.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

kentl
Member #2,905
November 2002

Or do you mean something a bit more advanced?
{"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"}Mosaic1.JPG

CGamesPlay
Member #2,559
July 2002
avatar

Or do you want a real collage-style mosaic?

Metapixel

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kris Asick
Member #1,424
July 2001

Here's some mock-up code I just wrote. There's probably much more efficient ways to do this, but since I've never done this before I figured this was the simplest method:

1void Bitmap2Mosaic (BITMAP *bitmap, int xpixel, int ypixel)
2{
3 // xpixel and ypixel define the size of each pixel in the mosaic.
4 
5 int xp = xpixel - 1;
6 int yp = ypixel - 1;
7 int c;
8 int z, zz;
9 
10 if (bitmap == NULL) return;
11 
12 for (z = 0; z < bitmap->w; z += xpixel)
13 for (zz = 0; zz < bitmap->h; zz += ypixel)
14 {
15 c = getpixel(bitmap,z,zz);
16 rectfill(bitmap,z,zz,z+xp,zz+yp,c);
17 }
18}

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

Presuming that's the effect you want. I've heard people call trails left by objects a mosaic effect. If that's 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're going for.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: