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.

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

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

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.

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.

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.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org