Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Making text fade away...

What is a good way to give the appearance that a String of text is fading away?  How can I do this?
0
bjg
Asked:
bjg
  • 4
  • 2
1 Solution
 
shchukaCommented:
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
 
bjgAuthor Commented:
How do I find the inverse of the background?
0
 
bjgAuthor Commented:
Could you provide a small example of how to do this?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bjgAuthor Commented:
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
 
shchukaCommented:
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
 
bjgAuthor Commented:
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
 
imladrisCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now