0

I have a project using a particle engine in Java Swing. These particles use an image instead of a basic shape (the image is entirely black with a transparent background), and they share the image so memory is low. With the image (a BufferedImage) being shared, how could I have the particles have different colors?

I can make it work if I create a copy of a preloaded image and change the black to the color I want, but then each particle has its own image and it takes up a ton of memory.

Worst case scenario I'll probably switch to LWJGL or TWL, but I already have a lot of content in the program that was made prior to the particle engine that I would need to remake :/.

Audiocrow
  • 65
  • 5
  • Should each particle have a different color? Or will there be, for example, 10000 particles with 10 colors in total? If each should have its own color, then it might become a bit tricky. Maybe you could provide the image by uploading it here. – Marco13 Aug 03 '14 at 00:24
  • For example, the model cited in this [answer](http://stackoverflow.com/a/24488837/230513) to your previous question uses just six colored images for an arbitrary number of particles. – trashgod Aug 03 '14 at 00:26
  • You should try to expand your requirements to get the best answer. Did you investigate the Java 2D LookupOp filter? You should be able to apply the filter to the image portion you wish to render on the fly. – javajon Aug 03 '14 at 00:53
  • @trashgod right now, with no color, they are sharing the single image as a flyweight pattern. I suppose I could limit the color variation, but storing 10 images per 1 image I originally needed just for color still seems excessive to me. And to javajon: even with a LookupOp filter it still looks like I'd need to store the filtered-image-result on the particles themselves. With a large amount of particles that would still be as much of a problem :/ – Audiocrow Aug 03 '14 at 10:25
  • I think @javajon meant that you could `filter()` a single image at render time; self-time `paintComponent()` to see. – trashgod Aug 03 '14 at 13:25
  • @javajon as far as what I've been able to figure out, LookupOp doesn't work on indexed images which is what my buffered images will always be since they're loaded from a file. :/ – Audiocrow Aug 04 '14 at 18:14

0 Answers0