home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / melt.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-10  |  5KB  |  226 lines

  1.   /* Fichier clock.dark.c                */
  2. /* Module appele par le programme principal    */
  3. /* pour effectuer un effet defini..appele par    */
  4. /* loadseg                    */
  5. #include    <exec/types.h>
  6. #include    <exec/ports.h>
  7. #include    <graphics/display.h>
  8. #include    <graphics/gfxbase.h>
  9. #include    <intuition/intuition.h>
  10. #include    <hardware/custom.h>
  11. #include    <math.h>
  12. #include    "/includes/struct.h"
  13. #include    "/includes/tom_gadget.h"
  14.  
  15. extern    struct my_data    *p_info;
  16. extern    struct    appel_proc    *p_data_proc;
  17. extern    struct    GfxBase    *GfxBase;
  18. int    compt,duree;
  19.  
  20. char    *p_text_info="Melt\n\nBased on a Program From ???\nAdapted and Modified!\n";
  21.  
  22. struct    Screen    *scr;
  23. struct    RastPort *rp;
  24.  
  25. UBYTE         *TypeLabels[] = {
  26.     "Type1",
  27.     "Type2",
  28.     "Type3",
  29.     "Aleatoire",
  30.     0l };
  31.  
  32. struct    tom_gadget    my_gadg[]={
  33.     {"Ty_pe",    MX,    167,14,17,40,0, 0,0,0,(char *)TypeLabels},
  34.     {"_Tempo",    SLIDER,    100,60,100,10,100,50,200,0,0},
  35.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}};
  36.  
  37.  
  38.     /* Random(ULONG MaxValue):
  39.      *
  40.      *    Simple random number generation routine.
  41.      */
  42. #ifndef custom
  43. #define custom (*(struct Custom *)0xDFF000)
  44. #endif    /* custom */
  45.  
  46.  
  47. ULONG __regargs
  48. Random(ULONG MaxValue)
  49. {
  50.     STATIC ULONG RandomSeed = 0xDEAD0123;
  51.  
  52.     RandomSeed = RandomSeed * custom . vhposr + 0xE153766F;
  53.  
  54.     return(RandomSeed % MaxValue);
  55. }
  56.  
  57.  
  58. void    melt(int    valy)
  59. {
  60.     int    x, y,            /* start positions         */
  61.         dx, dy,            /* offsets                 */
  62.         u, v;            /* size                    */
  63.     int    TempA[32];        /* temp buffer             */
  64.     char    mask;            /* bit-plane mask for blitter    */
  65.  
  66.     while((tst_end()==FALSE)&&(compt++<duree)) {
  67.       WaitTOF();
  68.       for(mask=1; mask<+(1<<(scr->BitMap.Depth))-1; mask*=2) {
  69.         u = RangeRand(scr->Width - 3) + 1;
  70.         v = RangeRand(scr->Height - 3) + 1;
  71.         x = RangeRand(scr->Width - 1 - u) + 1;
  72.         y = RangeRand(scr->Height - 2 - v) + 1; 
  73.         dx = RangeRand(3) - 1;
  74.         dy = RangeRand(3) - valy;  /* also try dy = RangeRand(3) - 1;  */
  75.  
  76.         BltBitMap(rp->BitMap, x, y,
  77.                   rp->BitMap, x+dx, y+dy,
  78.                   u, v, 0x0c0, mask, TempA);
  79.       }     /* end of for mask */
  80.  
  81.     }     /* end of FOREVER */
  82. }     /* end of melt */
  83.  
  84. void    get_uv(int    *u,int *v)
  85. {
  86.         *u = RangeRand(scr->Width*2/3 ) + 3;
  87.         *v = RangeRand(scr->Height*2/3) + 3;
  88. }
  89. void    fade_out()
  90. {
  91.  
  92.     int    color,cr,cg,cb,i,j;
  93.     UWORD    save[32];
  94.  
  95.     for(j=0;(j<(1<<scr->BitMap.Depth))&&(j<32);j++){
  96.     save[j]=GetRGB4(scr->ViewPort.ColorMap,j);
  97.     }
  98.     for(i=15;(i!=0)&&(tst_end()==FALSE);i--){
  99.     Delay(5);
  100.     WaitTOF();
  101.     for(j=0;j<(1<<scr->BitMap.Depth);j++){
  102.         color=save[j];
  103.         cr=(color&0xf00)>>8;
  104.         cg=(color&0xf0)>>4;
  105.         cb=color&0xf;
  106.     
  107.         cr=(cr*i)>>4;
  108.         cg=(cg*i)>>4;
  109.         cb=(cb*i)>>4;
  110.         SetRGB4(&(scr->ViewPort),j,cr,cg,cb);
  111.     }
  112.    }
  113.     if(tst_end()==FALSE){
  114.       fade_out();
  115.      }
  116.  
  117. }
  118.  
  119. void    melt2()
  120. {
  121.     int    x, y,            /* start positions         */
  122.         dx, dy,            /* offsets                 */
  123.         u, v;            /* size                    */
  124.     int    TempA[32];        /* temp buffer             */
  125.     char    mask;            /* bit-plane mask for blitter    */
  126.  
  127.         SetAPen(rp,0);
  128.     Move(rp,0,0);
  129.     Draw(rp,0,scr->Height-1);
  130.     Draw(rp,scr->Width-1,scr->Height-1);
  131.     Draw(rp,scr->Width-1,0);
  132.     Draw(rp,0,0);
  133.  
  134.     while((tst_end()==FALSE)&&(compt++<duree)) {
  135.       WaitTOF();
  136.         get_uv(&u,&v);
  137.         x = 0;
  138.         y = 0; 
  139.         dx = RangeRand(3) ;
  140.         dy = RangeRand(3) ;  /* also try dy = RangeRand(3) - 1;  */
  141.  
  142.         BltBitMap(rp->BitMap, x, y,
  143.                   rp->BitMap, x+dx, y+dy,
  144.                   u, v, 0x0c0, 0xff, TempA);
  145.         
  146.         get_uv(&u,&v);
  147.         x = scr->Width-u;
  148.         y = 0
  149.         dx = - RangeRand(3);
  150.         dy = RangeRand(3);  /* also try dy = RangeRand(3) - 1;  */
  151.  
  152.         BltBitMap(rp->BitMap, x, y,
  153.                   rp->BitMap, x+dx, y+dy,
  154.                   u, v, 0x0c0, 0xff, TempA);
  155.  
  156.         get_uv(&u,&v);
  157.         x = 0
  158.         y = scr->Height-v;
  159.         dx = RangeRand(3);
  160.         dy = - RangeRand(3);  /* also try dy = RangeRand(3) - 1;  */
  161.  
  162.         BltBitMap(rp->BitMap, x, y,
  163.                   rp->BitMap, x+dx, y+dy,
  164.                   u, v, 0x0c0, 0xff, TempA);
  165.  
  166.         get_uv(&u,&v);
  167.         x = scr->Width-u;
  168.         y = scr->Height-v;
  169.         dx = - RangeRand(3);
  170.         dy = - RangeRand(3);  /* also try dy = RangeRand(3) - 1;  */
  171.  
  172.         BltBitMap(rp->BitMap, x, y,
  173.                   rp->BitMap, x+dx, y+dy,
  174.                   u, v, 0x0c0, 0xff, TempA);
  175.  
  176.  
  177.     }     /* end of FOREVER */
  178. }     /* end of melt */
  179.  
  180.  
  181. /* Put here your own code */
  182. /* But don't remember     */
  183.  
  184. void    __saveds    dark()
  185. {
  186.     int    effet;
  187.     rp=p_data_proc->rp;
  188.     scr=p_data_proc->s;
  189.  
  190.     FreeSprite (0);
  191.     GfxBase->SpriteReserved|=1;
  192.     effet=my_gadg[0].value;
  193.     while(tst_end()==FALSE){
  194.         compt=0;
  195.         duree=2*my_gadg[1].value;
  196.  
  197.         if(my_gadg[0].value==3){
  198.             effet=rand()%3;
  199.         }else{
  200.             effet=my_gadg[0].value;
  201.         }
  202.  
  203.         switch(effet){
  204.             case 0:    
  205.                 melt2();
  206.                 break;
  207.             case 1:    
  208.                 melt(0);
  209.                 break;
  210.             case 2:    
  211.                 melt(1);
  212.                 break;
  213.         }
  214.         fade_out();
  215.     }
  216.  
  217. }
  218.  
  219. void    proc_init()
  220. {
  221.     p_data_proc->type_screen=SCR_GIVEN;
  222. }
  223. void    proc_end()
  224. {
  225. }
  226.