Jump to content
  • Advertisement
Sign in to follow this  

Circle to 2D-array

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

If you intended to correct an error in the post then please contact us.

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.

int[,] CreateCircle(float radius)
{
//return a int matrix where 1 is a pixel part of the circle and 0 is outside the circle
}

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!