home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / code_examples / fade / fade.zoo / fade.c next >
C/C++ Source or Header  |  1989-06-15  |  2KB  |  84 lines

  1. #include    <exec/types.h>
  2. #include    <proto/graphics.h>
  3. #include    <proto/dos.h>
  4. #include    <graphics/view.h>
  5. #include    <intuition/intuition.h>
  6.  
  7. #define FindRed(value)    ((value >> 8) & 0xf)
  8. #define FindGreen(value)    ((value >> 4) & 0xf)
  9. #define FindBlue(value)    ( value       & 0xf)
  10. #define PAckColors(r,g,b)    (((r) << 8) | ((g) << 4) | (b))
  11.  
  12. void Fade(screen, destMap, delay, numcolors)
  13. struct Screen *screen;
  14. UWORD destMap[];
  15. BYTE delay;
  16. BYTE numcolors;
  17. {
  18.     UBYTE    CurrColors[32][3];
  19.     int        Subs[32][3];  
  20.     register int    x, y, z;
  21. /*    struct ViewPort *vp = &(screen->ViewPort); */
  22.     struct ColorMap *cm = (screen->ViewPort.ColorMap);
  23.     register UWORD    temp;
  24.  
  25. /*    Find differences                                        */
  26. /*    Copy current colors to 8 bit instead of 4 bit                */
  27.  
  28.     for (x = 0; x < numcolors; ++x)
  29.     {
  30.         temp = GetRGB4(cm,x);
  31.         Subs[x][0] = FindRed(temp) - FindRed(destMap[x]);
  32.         Subs[x][1] = FindGreen(temp) - FindGreen(destMap[x]);
  33.         Subs[x][2] = FindBlue(temp) - FindBlue(destMap[x]);
  34.         CurrColors[x][0] = ((FindRed(temp) << 4) & 0xf0);
  35.         CurrColors[x][1] = ((FindGreen(temp) << 4) & 0xf0);
  36.         CurrColors[x][2] = ((FindBlue(temp) << 4) & 0xf0);
  37. /*        printf("%d  %d %d %d, %d %d %d, %x\n", x, Subs[x][0],Subs[x][1],Subs[x][2],
  38.             CurrColors[x][0], CurrColors[x][1], CurrColors[x][2], temp); */
  39.     }    
  40.  
  41. /*    DO THE FADE!!   do the fade!!   (hehe..)                    */
  42.  
  43.     for (x = 0; x < numcolors; ++x)
  44.     {
  45.         for (y = 0; y < 3; ++y)
  46.         {
  47.             if (Subs[x][y] < 0)
  48.                 CurrColors[x][y] -= Subs[x][y];
  49.         }
  50.     }
  51.     
  52.     for (z = 0; z < 15; ++z)
  53.     {
  54. /*        printf("."); */
  55.         for (x = 0; x < numcolors; ++x)
  56.         {
  57.             for (y = 0; y < 3; ++y)
  58.             {
  59.                 CurrColors[x][y] -= Subs[x][y];
  60.             }
  61.             SetRGB4(&(screen->ViewPort),x,(CurrColors[x][0] >> 4) & 15,
  62.                                     (CurrColors[x][1] >> 4) & 15,
  63.                                     (CurrColors[x][2] >> 4) & 15);
  64.         }
  65.         Delay(delay);
  66.     }
  67. /*    printf("\n"); */
  68. }
  69.  
  70. void FadeToBlack(screen, delay, numcolors)
  71. struct Screen *screen;
  72. BYTE delay;
  73. BYTE numcolors;
  74. {
  75.     UWORD colormap[32] = {
  76.         0, 0, 0, 0, 0, 0, 0, 0,
  77.         0, 0, 0, 0, 0, 0, 0, 0,
  78.         0, 0, 0, 0, 0, 0, 0, 0,
  79.         0, 0, 0, 0, 0, 0, 0, 0 };
  80.     
  81.     Fade(screen, colormap, delay, numcolors);
  82. }
  83.  
  84.