Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1678 > unrolled thread

"fading" graphics using G

Started by"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
First post2011-04-27 15:34 +0000
Last post2011-04-27 15:34 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  "fading" graphics using G "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
    Re: "fading" graphics usi "visionset" <visionset@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
      Re: "fading" graphics usi "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000

#1678 — "fading" graphics using G

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
Subject"fading" graphics using G
Message-ID<46552116$0$4719$4c368faf@roadrunner.com>
  To: comp.lang.java.gui
Hello everyone,

I started a small Java program just as something fun to do. It simulates 
a sonar, like on a submarine.  Right now I'm at the point where I have 
multiple objects moving independently around the sonar screen with a 
rotating needle.  I keep track of the speed/location/etc. of each object 
which extends Thread.  The needle rotates around the screen in a way 
that lights up the part it just touched and the glow gradually fades 
away using a gradient that I created.  The objects on the screen only 
change location when the needle intersects them (using the intersects() 
method of java.awt.geom.Line2D.Double).

The problem is that at this point the objects "jump" to the new location 
because their last displayed location is still on the display.  I 
believe a real sonar works in such a way that all the objects that are 
detected gradually fade away and just before totally disappearing the 
needle lights them up again in their newest location.  I'm having 
trouble figuring out a way to get the object icon (just an oval right 
now drawn using fillOval()) and its label (drawn using drawString()) to 
gradually fade away.

The first problem I ran into was that the object stayed drawn on the 
sonar screen even when it had actually moved out of "range" of the 
sonar.  Later I realized that if it faded away like it is supposed to I 
wouldn't have to worry about drawing over top of the old location when 
it moved out of range because it would go away on its own and come back 
when it was back in range on the sonar.

Currently I'm saving the old location but painting the icon and text 
again using a transparent color obviously doesn't erase the painted 
object and text from its last location. I also can't actually paint over 
the existing icon/text with background colors because it is over top of 
the gradient from the needle glow fading away and I wouldn't be able to 
come up with the perfect pattern to paint over it to match the gradient 
at that location at a particular point in time.  I tried to paint all 
objects and labels before the sonar needle was painted with its gradient 
but in order to still see them through the gradient requires 
transparency on the gradient and that slows down the rendering 
tremendously, too much for it to be worth it. I have the gradient 
stretch the entire 360 degrees of the circle so there is no point on the 
sonar where there isn't a gradient. (It goes from yellow to green).

I've attempted to get the icon/text to fade away like I do the needle 
glow by setting up a loop and gradually increasing the transparency 
level but that doesn't seem to work even with just 1 object. I have a 
feeling I wouldn't be able to get it to work with multiple objects whose 
fade has to be independent anyway because the sonar needle would go over 
them at different times.

I'm running out of ideas on how to get this to work so I'm just fishing 
around for ideas at this point.

I tried to explain my program and my problem the best I could especially 
for those not familiar with a sonar device but if needed I can probably 
post the whole program this time (unlike my other posts about my other 
program) since the full program is just under 500 lines. Then anyone who 
wants to can test it to see what I'm talking about.

thanks for any ideas.

Brandon

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#1685 — Re: "fading" graphics usi

From"visionset" <visionset@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
SubjectRe: "fading" graphics usi
Message-ID<6qo5i.3750$BN6.366@newsfe6-gui.ntli.net>
In reply to#1678
  To: comp.lang.java.gui

"Brandon McCombs" <none@none.com> wrote in message 
news:46552116$0$4719$4c368faf@roadrunner.com...
> Hello everyone,
>
> I started a small Java program just as something fun to do. It simulates a 
> sonar, like on a submarine.  Right now I'm at the point where I have 
> multiple objects moving independently around the sonar screen with a 
> rotating needle.  I keep track of the speed/location/etc. of each object 
> which extends Thread.  The needle rotates around the screen in a way that 
> lights up the part it just touched and the glow gradually fades away using 
> a gradient that I created.  The objects on the screen only change location 
> when the needle intersects them (using the intersects() method of 
> java.awt.geom.Line2D.Double).
> ...

I think you are on the right track with the transparency overlay.
I would paint a rectangle of eg new Color(1.0,1.0,1.0,alpha) over the icon.
also use a Swing Timer that starts when the icon is first created (needle 
pass over).
Then every actionPerformed will increase decrease the alpha.
You are going to need to repaint regularly perhaps by another timer purely 
for repainting.
If your app does other intensive stuff you will likely need to make some 
drawing optimisations
such as calling repaint(x,y,w,h) to only repaint the areas necessary, eg 
icons with attendent rectangles that are not fully opaque.  You would union 
together the rectangles to obtain the reapaint area.
Cache everything that is going to be painted.

Just some ideas,
HTH,
-- 
Mike W

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1693 — Re: "fading" graphics usi

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:34 +0000
SubjectRe: "fading" graphics usi
Message-ID<4657e17a$0$2384$4c368faf@roadrunner.com>
In reply to#1685
  To: comp.lang.java.gui
visionset wrote:
> "Brandon McCombs" <none@none.com> wrote in message 
> news:46552116$0$4719$4c368faf@roadrunner.com...
>> Hello everyone,
>>
>> I started a small Java program just as something fun to do. It simulates a 
>> sonar, like on a submarine.  Right now I'm at the point where I have 
>> multiple objects moving independently around the sonar screen with a 
>> rotating needle.  I keep track of the speed/location/etc. of each object 
>> which extends Thread.  The needle rotates around the screen in a way that 
>> lights up the part it just touched and the glow gradually fades away using 
>> a gradient that I created.  The objects on the screen only change location 
>> when the needle intersects them (using the intersects() method of 
>> java.awt.geom.Line2D.Double).
>> ...
> 
> I think you are on the right track with the transparency overlay.
> I would paint a rectangle of eg new Color(1.0,1.0,1.0,alpha) over the icon.
> also use a Swing Timer that starts when the icon is first created (needle 
> pass over).

Actually I already have a Timer that runs the entire time the program 
runs. It fires every 6 ms and does all the repainting by calling 
repaint() in actionPerformed(). Shortly after posting this I ended up 
fixing the problem in the code where the object wasn't disappearing when 
it moved out of range and I inadvertently laid the groundwork for fixing 
the fading of the objects. I had the revelation for fixing the fading 
while laying in bed later that night and tried it first thing Friday 
morning and got it working.

I had setup multiple "if" conditions for drawing or not drawing the 
objects.  As my last condition, which is encountered when the object is 
in range but isn't being intersected by the needle, I ended up 
creating/calling a variation of each object's display() method which 
draws the object with increasing transparency, in effect making it fade 
away. With each object tracking its own transparency I was able to make 
them all fade properly based on their distance from the needle.  The 
first condition, when the object is both in range and intersected by the 
needle, calls the primary variation of the object's display() method 
which will redraw the object and its label with 0 transparency thus 
making it appear again (as I timed the fading of each object so that the 
object totally disappears right before the needle rotates back around to 
intersect it again).

> Then every actionPerformed will increase decrease the alpha.
> You are going to need to repaint regularly perhaps by another timer purely 
> for repainting.

See above. I already had that in place. I have 1 timer that repaints 
everything in varying layers. The moving vehicles that are tracked on 
the sonar are in the top-most layer.

> If your app does other intensive stuff you will likely need to make some 
> drawing optimisations
> such as calling repaint(x,y,w,h) to only repaint the areas necessary, eg 
> icons with attendent rectangles that are not fully opaque.  You would union 
> together the rectangles to obtain the reapaint area.

Since I'm increasingly using more transparencies I'm going to have to 
think of ways to optimize it because it is using more and more CPU to 
run the program (mainly to repaint I believe). I'll look into your idea 
to see if I can get repainting only certain areas to work.

> Cache everything that is going to be painted.
> 
> Just some ideas,
> HTH,

thanks for your help Mike.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web