Solved

Making text fade away...

Posted on 1998-07-29
7
240 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 153
pagenation logic how it is working in my code 1 71
Setup GlassFish 4 35
What browser will run Java? 7 126
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

749 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