Particle Engine Physics

I am programming a particle engine for the heck of it in Java just to have for future games. I have it at the point where it can handle a decent amount of particles, have multiple gravity wells and toggle ground gravity…

What I would like to do is add a method to see if there are many particles close together make their colors kind of gradient outwards almost like magma.
Also if you can think of a way to make the particles react to eachother such as stacking up in a heap on the ground instead of all going into a flat line.

Help is appreciated, thanks cMp

I haven’t made a particle engine by myself before but I think you are looking for additive blending.

Yes thats what I am thinking, but I am not sure how to do this

Any ideas? Also if it helps I am rendering it using Graphics but I am not sure if I should convert it to BufferedImage for performance

Sorry that I can’t help you more but I dug up a few posts:
http://www.java-gaming.org/index.php?topic=19891.0

Although if I recall correctly this sort of blending is not very possible in Java2D…

Here check this video out, this guy did this in just java the only difference is he renders his in a buffered image

http://www.youtube.com/watch?v=_F8lbnTR6ew]

This is exactly what I am aiming for

That guy did post the source - http://pastebin.com/raw.php?i=DSVWBUzy

It appears he’s using this for blending:

public int additiveColor(int c1, int c2){ // my additive color blender
        
        int red = (c1 & 0x00ff0000) + (c2 & 0x00ff0000);
        int grn = (c1 & 0x0000ff00) + (c2 & 0x0000ff00);
        int blu = (c1 & 0x000000ff) + (c2 & 0x000000ff);
        
        if( red > 0x00ff0000 )
            red = 0x00ff0000;
        
        if( grn > 0x0000ff00 )
            grn = 0x0000ff00;
        
        if( blu > 0x000000ff )
            blu = 0x000000ff;
        
        return 0xff000000 + red + grn + blu;
    }

yes I saw that but which variables would I plug in?

Ok he posted on a video this:

In my newest version, which is simpler/better than this one I set every pixel on the screen as a zero, and then add one where every particle is. So if 8 particles are overlapping a pixel, the BufferedImage stores a value of 8. The cap is 10, so if more than 10 pixels are overlapping, the value is 10. Then what I do is iterate through the entire BufferedImage, and for every single pixel, the value is mapped to a gradient stored in an array of colors. So the color when value is 3 is = gradient[3];

Can anyone think of a way to do this with Graphics2D? I have played around with it for a while to no avail

Right so my last post didnt get a lot of answers at all so I am posting another one BUT its on something else, not colors. I was wondering what the best way would be to make the particles “stack” in piles like sand? When gravity is enabled I would like the particles to fall in a pile instead of all falling flat on the ground?
Thanks, cMp

Topics merged for asking the same question twice :point:

I really need help with these two things, I have been trying for about 3 and a half hours with no progress :frowning:

You do realize 3.5 hours on 2 problems is nothing?

yes I do I have spent much more time on other things but this seems like such a simple thing to solve and I am starting to feel very stupid.

Pro tip #64: If you want help with code that isn’t working how you expect it to work, then showing that code is very helpful.

This does two things for us, the ones helping you. First it shows us what you have already, what you still need to implement, and exposes any logic errors you may have. Second, and in my opinion the most important, showing us your progress proves that you are actually working on solving the issue on your own, and are not just posting in hopes of free copy-paste code.

Pro tip #128: Avoid at all cost the Double-Post-of-Doom :wink:

On a personal aside; expecting a lot of answers to a vague question over the course of 3 hours is a little unreasonable, given that this community if comprised of individuals from all over the World.

Edit: I don’t sugar coat anything :slight_smile:

For this you need to assign a size (box or radius) to the particles, and have some collision checking implemented. I think though that the idea of particles was just to have a very simple something which computes efficiently. By adding size and collision detection your particles become real objects and either you’ll have to implement a quite efficient collision detections strategy or face a notable slowdown.

IMO keep particles simple. If you need something more detailed, it’s not particles anymore and needs different approaches.