Fade effect in text mode... 
Author Message
 Fade effect in text mode...

Hi all!

   How can i make a fade effect with screen 0 ???


Tue, 24 Nov 1998 03:00:00 GMT  
 Fade effect in text mode...


> Hi all!

>    How can i make a fade effect with screen 0 ???

>      Thanx
>      ;^)
>    fred

  In order to use a fade in text mode, you have to use the OUT command to
change the palette, since you can't use PALETTE in text mode.
  When you use OUT, you can use 256k (262,144) colors in ANY screen mode,
provided that your hardware supports it.  In text mode, and most of the
other screen modes, you can only use 16 of these colors at a time.
  I'll try to explain the process as simply as possible, but it's hard to
understand at first.  First, you have to know what color number that you
want to change.  SCREEN 0 has colors 0 through 15.  Say you used the
following program:

        SCREEN 0
        PRINT "When making a fade, it is important to remember"
        PRINT "which color number to change."
        PRINT "Now a fade..."

  The default color for screen 0 is 7 (light gray), so we have to change
color 7.  First, we have to prepare the computer to change the color
value.  We do this with the following line of code:

        OUT &H3C8, 7
  Replace 7 with the color value you want to change.  Now, we have to
change the actual color values.  There are three color values: Red,
Green, and Blue.  Since we want the screen to eventually fade to black,
we have to change these values to increasingly lower numbers.  Lower
values for Red, Green, and Blue make the color darker, and higher values
lighten the color.

  Changing the color values gets tricky because we have to do it in three
statements (one statement for Red, Green and Blue) that are EXACTLY THE
SAME.  Let me explain.  If I wanted to set the Red, Green and Blue color
values of color 7 to 0 (making the color black), I would use the
following code:

                OUT &H3C8, 7 'Remember this from earlier?
                OUT &H3C9, 0 'Set the RED value
                OUT &H3C9, 0 'Set the GREEN value
                OUT &H3C9, 0 'Finally, set the BLUE value

  You have to use OUT &H3C9, value (where value is the new color value)
three times.  The first time you are setting the new RED value, the
second time the GREEN value, and finally the BLUE value.  You have to
remember that they are always set in this order.  You will end up with a
wrong color if you accidentally put the blue value in the green
  Lets focus on value (in the command OUT &H3C9, value).  Value is the
new number of that color value.  The number must be between 0 and 63.  If
you set the Red, Green, and Blue values all to 0, you would get black,
and if you set the R, G, and B values all to 63, you would get white.  
You have to find the precise color values to use.  More on that later.

  Now we come to the actual fading.  In order to to a successful
fade-to-black, we have to set the color values (Red, Green, and Blue) of
the chosen color to increasingly lower numbers, until R, G, and B are all
set to 0.  The default values (the value set by DOS when the computer
starts) of the Red, Green, and Blue attributes in color 7 are all 42 (42
is 2/3 of 63, the maximum amount, so the color is basically 2/3 white).  
Since we know the values of all the color attributes, we could use
something like this:

        FOR I%= 42 TO 0 STEP -1
                OUT &H3C8, 7
                OUT &H3C9, I%
                OUT &H3C9, I%
                OUT &H3C9, I%
                WAIT &H3DA, 8
        NEXT I%

  This provides us with a nice fade.  The WAIT &H3DA, 8 statement waits
for the computers vertical retrace.  This is the same on every computer.
This statment makes sure that we get a nice smooth fade on any computer
we run it on.  
  But what if we don't know the color value?  We can't just guess and
hope we get the right color for our fade.  There is a way to get the
values of the color attributes.  Lets say we want to see what the values
of the attributes (Red, Green, and Blue) in color 7 are, just to be sure
(we can also use this with any other color).  We would use the following
        OUT &H3C7, 7
        RED = INP(&H3C9)
        GRN = INP(&H3C9)
        BLU = INP(&H3C9)

  OUT &H3C7, 7 tells the computer that we are going to do something with
color number 7.  Then, we store the Red, Green, and Blue values in RED,
GRN, and BLU for future use.
  Let's put together an improved fade based on what we just learned:

        FOR I% = 63 TO 0 STEP -1
        OUT &H3C7, 7
        RED = INP(&H3C9)
        GRN = INP(&H3C9)
        BLU = INP(&H3C9)  
        IF RED > 0 THEN RED = RED - 1
        IF GRN > 0 THEN GRN = GRN - 1
        IF BLU > 0 THEN BLU = BLU - 1
        OUT &H3C8, 7
        OUT &H3C9, RED
        OUT &H3C9, GRN
        OUT &H3C9, BLU
        WAIT &H3DA, 8
        NEXT I%

  Using this code, you could fade any of the colors by just changing all
references to color 7 to whatever color you want to change (do not,
however, change the 7 in &H3C7).  
  There is one downside to this whole procedure, in all screen modes
except 13, you can only change colors 0-7 with this routine.

  Now, one last example.  Lets make a program that fades all colors from
0-7 to black.

        FOR J%=63 TO 0 STEP -1
        FOR I%=0 TO 7
        OUT &H3C7, I%
        RED = INP(&H3C9)
        GRN = INP(&H3C9)
        BLU = INP(&H3C9)
        IF RED > 0 THEN RED = RED - 1
        IF GRN > 0 THEN GRN = GRN - 1
        IF BLU > 0 THEN BLU = BLU - 1
        OUT &H3C8, I%
        OUT &H3C9, RED
        OUT &H3C9, GRN
        OUT &H3C9, BLU
        NEXT I%
        NEXT J%

  Well, I hope this helps you has much as it's helped me.  Happy


Very funny Scotty!
Now beam down my clothes!

                Capt. James T. Kirk

Tue, 01 Dec 1998 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Fade-in, Fade-out effect

2. create a fade effect or any other effect like morph between two open forms

3. Fading in Text Mode

4. Fade Out Opacity Effect

5. Please help: Fade Effect for picturebox in Visual Basic .NET

6. Screen effects: fades, wipes, dissolves etc

7. How to obtain a fade effect?

8. How To: Fade effect title bar

9. Make a Picture fade effect

10. Mode independent palette fade routine?

11. Mode independent palette fade routine?

12. Mode independent palette fade routine?


Powered by phpBB® Forum Software