• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Nice 2D graphics?

 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm looking to create a nice-looking display for a Game of Life application I wrote... currently it looks like this:



but I want it to look like this:



Any suggestions of how to do this? Especially would like nice lighting effects, and preferably with a 2D API since I've never done anything in 3D. Is the built-in Java 2D at all useable? I've looked at PulpCore briefly, but I think that's mainly for applets rather than desktop apps.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java 2D is certainly useable, it is hardware-accelerated, it's very well suited to do nice, smooth animations.

It can do double-buffering (or even use more than 2 buffers) for that. That means that you have two buffers to draw on in your application: one that is shown on screen, the other one is what your program is actually drawing on. When you're done drawing the next frame of the animation, you swap the two buffers (and then start drawing the next frame on the one that's now hidden).

There are several libraries for 3D graphics. There is for example jMonkeyEngine which is an impressive 3D graphics engine, with which you can relatively easy make great looking 3D graphics. Another one is LWJGL, which also provides you with OpenGL 3D graphics, OpenAL 3D sound and other things.
 
Ranch Hand
Posts: 143
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The target example has a black background and white circles painted on it. It also seems to have partially transparent "glows" that can overlap.

You example seems to have a white background and blue squares painted on it.

The biggest hurdle seems to me to be figuring out how to make glowing effects. You can probably figure out for yourself how to do the black background and paint circles instead of squares. You should look into how to use colors that have "alpha" values, such as RGBA format where the "alpha" is the degree of transparency. Also, there are possibilities such as using GradientPaint or RadialGradientPaint (and the gradients can apply to alpha as well as R, G, or B).

Here's the link for Color. Be sure and check out the info there on transparency (alpha settings) and try applying it to Paint objects.

So, paint the background black, pop on a larger circle with the desired "glow" transparent color, then put a smaller white circle over that. That might get you 80% of the way to what you want.
 
Luigi Plinge
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. The RadialGradientPaint class looks interesting - I might have a closer look at what it can do.

I already coded a Gaussian blur demo that works:


I found a useful site on producing bloom effects: http://kalogirou.net/2006/05/20/how-to-do-good-bloom-for-hdr-rendering/

Also some interesting pages on image filters in Java: http://www.jhlabs.com/ip/index.html

Applying full Gaussian blurs in real time is computationally demanding (and inefficient), so I'll look at pre-computing the LED images. If I only want to display 1 size and a restricted colour palette I could just render those images in a paint package, but the problem becomes less interesting. I'd like to be able to scale to any resolution without a high performance penalty, and also have freedom to easily change colours.

Also I'll probably implement a mirror effect for the surface the panel is sitting on, which shouldn't be too hard.

Here is a demo in PulpCore (click the moons for reflection and other effects) - surprising there is such a good API for applets but nothing similar AFAIK for normal Swing apps (maybe JavaFX was supposed to fill this niche?). Maybe I should program this as an applet, but I don't suppose those will be hardware accelerated?
 
Saloon Keeper
Posts: 15725
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can generate an image once when the window resizes, and then you can simply render that image with alpha compositing.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic