Circle to 2D-array

This topic is 2860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I want to remove the overlap between a 2D-array containing a circle and another 2D-array containing alpha values of a pictures. (Think an explosion in liero or worms)

But my problem is creating the circle 2D-array from a given radius. I've been looking into the midpoint circle algorithm a little bit, but I cant find any good hits on filled circles.

{
//return a int matrix where 1 is a pixel part of the circle and 0 is outside the circle
}

Share on other sites
Why can you not use the midpoint circle algorithm?

http://en.wikipedia....ircle_algorithm

taking the first source example, you get in each iteration:

 setPixel(x0 + x, y0 + y); setPixel(x0 - x, y0 + y); setPixel(x0 + x, y0 - y); setPixel(x0 - x, y0 - y); setPixel(x0 + y, y0 + x); setPixel(x0 - y, y0 + x); setPixel(x0 + y, y0 - x); setPixel(x0 - y, y0 - x); 

just replace with:

 for(ix = x0-x; ix<=x0+x; ix++) { setPixel(ix, y0 + y); setPixel(ix, y0 - y); } for(ix = x0-y; ix<=x0+y; ix++) { setPixel(ix, y0 + x); setPixel(ix, y0 - x); } 

and you can do the same with the improved version

Share on other sites
Shouldn't you use a sprite (possibly the alpha channel of the explosion image: opaque=destroyed, transparent=untouched, partly transparent=use a threshold to decide) instead of calculating circles over and over again at runtime? Sprites allow you to use any explosion shape, not only discs, and build complex explosions by compositing multiple particles.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 9