How can I create this effect?

BlitzMax Forums/BlitzMax Programming/How can I create this effect?

Drakim(Posted 2008) [#1]

I want to create this effect, where, we have circles that "merge" when they are close. I can see how it would be impossible with sprites, and that you would need to draw the image with code on the fly.

Don't know what else to put in the post. :o


ImaginaryHuman(Posted 2008) [#2]
I depends on whether you want the outline of the objects to be a smooth curve or whether, as in your diagram, you simply want to have the outline be removed if it intersects another circle. If you want a smooth curve, which your diagram does not show, then you want blobby objects/metaballs. See my tutorial in the tutorials forum.


Drakim(Posted 2008) [#3]
I see. Nice tutorial by the way, I loved it.

I actually only want the outline to be removed if it intersects. I have a game which involves a lot of bacteria, and it looks pretty ugly when a lot of bacteria are almost on top of each other, thus I want their edges to not overlap, but be merged.


tonyg(Posted 2008) [#4]
Can you find their intersection points and then Drawpoly between those using the same colour as the sprite? You'll get the same problem though with the inner circle. Alternatively, don't have the outline?


Drakim(Posted 2008) [#5]
Hm, yes, I'm starting to wonder if simply not having the outline would be the best option, and just using the proper BLEND to get the pale pink to merge.


jsp(Posted 2008) [#6]
When you draw the black outline first from both bacteria and then the pale pink on top it could simply hide the intersection underneath. But you need then two phases to draw, don't know if that works for you.


iprice(Posted 2008) [#7]
Here's a very simple example, that does what you want - just change the code to use Types and images etc.




ImaginaryHuman(Posted 2008) [#8]
It would be more efficient to do something computational based on the pixels.

If you are willing to indulge in some custom OpenGL or DX coding you could draw all of the larger circle parts as filled circles in an OR logic operation, then use the resulting image to create some kind of outline of those shapes, perhaps by jittering or something, and then finally draw the centers of the objects.


ziggy(Posted 2008) [#9]
Make layers. Draw borders first, then faces, etc. This would be the fastest way.


MGE(Posted 2008) [#10]
If it's only 2 sprites merging, then you could simply have a 3rd sprite image which you manipulate. I know...I cheat. :)


Drakim(Posted 2008) [#11]
Thanks guys, but I've decided to drop the outline for simplicity, and also it kinda looks better. DX


ImaginaryHuman(Posted 2008) [#12]
You could fake an outline by drawing all your objects at a slight offset in a light color, then at another offset in a dark color, and then finally draw the normal colored objects. That would create a basic embossing effect.


Warpy(Posted 2008) [#13]
I've wanted to be able to do this the proper algorithmic way for years, and yesterday I finally had a bout of inspiration!

Here's my code. It's pretty length, but to use it in your programs you can do with just copying everything above the example code, and the only bits you need to pay attention to are passing a list of circles to the intersectcircles function and doing whatever you want with the circle.draw method.




ziggy(Posted 2008) [#14]
Nice effect!
Here's the superstrict version with locals declared and the like



Warpy(Posted 2008) [#15]
thanks for that, ziggy


sswift(Posted 2008) [#16]
I don't think your girlfriend would like it if you did that.