?
Solved

Making text fade away...

Posted on 1998-07-29
7
Medium Priority
?
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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 100 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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