Solved

Making text fade away...

Posted on 1998-07-29
7
215 Views
Last Modified: 2010-03-30
What is a good way to give the appearance that a String of text is fading away?  How can I do this?
0
Comment
Question by:bjg
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1229056
One way of going about it would be to draw the text on something (canvas or whatever) with different color starting with the inverse of the background and going to the background.  A number of colors you need to go through is determined by how fast you want the text to fade away.
0
 

Author Comment

by:bjg
ID: 1229057
How do I find the inverse of the background?
0
 

Author Comment

by:bjg
ID: 1229058
Could you provide a small example of how to do this?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:bjg
ID: 1229059
How can I make this dynamic according to what color the text is, and what color the background is?  I don't want to hardcode anything in terms of colors.  I want it to all be dynamic depending on the colors being used.  How can I do this?
0
 
LVL 2

Expert Comment

by:shchuka
ID: 1229060
The easy way to figure out the inverse of a color is the following:

break the color into RGB components, say (red, green, blue) contain the values.  Then the inverse of the color is simply (255-red, 255-green, 255-blue).

Start up from here.
0
 

Author Comment

by:bjg
ID: 1229061
I am not sure if understand what you are trying to do though...I think what I am trying to do is I want to fade the Color of the graphics so that it eventually is the same color as the background of the Canvas.  So how would you do this with what you proposed?  Could you provide an example?
0
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 1229062
OK, how about this:

You can get the foreground and background colours for any component, witht the getBackground and getForeground methods. Establish the total difference for each of the three colour components, i.e. if frg is a Color object representing the foreground colour and bkg for the bkg:

int reddif=frg.getRed()-bkg.getRed();

now reddif (and blue- and greendiff) represent the amounts you have to subtract from their foreground components to make them equal to the background ones. Now supposing you want to fade in 20 steps, for any step you would change the foreground colour to:

new Color(frg.getRed()-(reddif*i)/20,frg.getGreen()-(greendiff*i)/20,
        frg.getBlue()-(bluediff*i)/20);

and redraw the text. Simply redraw the text repeatedly in an animation loop.

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now