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

  1.  /* Fichier star.dark.c                */
  2. /* Module appele par le programme principal    */
  3. /* pour effectuer un effet defini..appele par    */
  4. /* loadseg                    */
  5.  
  6. #include <time.h>
  7. #include <math.h>
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <graphics/gfx.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <graphics/rastport.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/displayinfo.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include "/includes/struct.h"
  19. #include "/includes/tom_gadget.h"
  20.  
  21. char    *p_text_info="   Mistifiy\n\nBased on a Window's effect";
  22.  
  23. struct    RastPort    *rp;
  24. struct    Screen    *s;
  25. extern    struct    GfxBase    *GfxBase;
  26. #define    WIDTH    320
  27. #define    HEIGHT    256
  28.  
  29. #define    MAX_NB    4
  30.  
  31. UWORD  ScreenColors[] = {
  32.     0x000,
  33.     0xF00,
  34.     0x0F0,
  35.     0x00F,
  36.     0xFF0,
  37.     0xF90,
  38.     0xFA0,
  39.     0xFB0,
  40.     0xFC0,
  41.     0xFD0,
  42.     0xFE0,
  43.     0xFF0,
  44.     0xBF0,
  45.     0x8F0,
  46.     0x7D0,
  47.     0x5B0,
  48.     0x000,
  49.     0x490,
  50.     0x340,
  51.     0x555,
  52.     0x777,
  53.     0x999,
  54.     0xBBB,
  55.     0xDDD,
  56.     0xEEE,
  57.     0xFFF,
  58.     0xFCC,
  59.     0xFAA,
  60.     0xF88,
  61.     0xF66,
  62.     0xF44,
  63.     0xF22,
  64.     0x0FF };
  65.  
  66. #define    NB_PT    4
  67. #define NB_OLD    5
  68. #define MAX_SPEED 10
  69.  
  70. int    speed;
  71.  
  72. struct NewScreen   Screen = {
  73.     0, 0, WIDTH,HEIGHT, 2,0,1,NULL,CUSTOMSCREEN,NULL,NULL,NULL,NULL};
  74.  
  75. struct tom_gadget my_gadg[]={
  76.     {"_Numbers",SLIDER,    101,15,135,9,2, 1,MAX_NB-1,0,0},
  77.     {"_Speed",SLIDER,    101,30,135,9,6, 3,MAX_SPEED,0,0},
  78.         {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  79. };
  80.  
  81. typedef    struct    pt{
  82.     int    x,y;
  83.     int    old_x[NB_OLD],old_y[NB_OLD];
  84.     int    vx,vy;
  85. };
  86. struct    pt    tab_pt[MAX_NB*NB_PT];
  87.  
  88. int    d;
  89.  
  90. void    rotate()
  91. {
  92.     static    unsigned    int    compt=0;
  93.     static    unsigned    int    c=100;
  94.     UWORD    n,i,r,g,b,s2;
  95.  
  96.     c++;
  97.     if(c==100){
  98.     c=0;
  99.     n=compt;
  100.     for(i=1;i<d;i++){
  101.         n=n%31;
  102.         s2=ScreenColors[n+1];
  103.         r=s2>>8;
  104.         g=(s2>>5)&0x0f;
  105.         b=s2&0x0f;
  106.         SetRGB4(&(s->ViewPort),i,r,g,b);
  107.         n+=5;
  108.     }
  109.     compt++;
  110.    }
  111. }
  112.  
  113. void    dark()
  114. {
  115.     int    i,j,n,color;
  116.     struct    pt *t;
  117.  
  118.     if ( s = OpenScreen(&Screen)){
  119.  
  120.     FreeSprite (0);
  121.     GfxBase->SpriteReserved|=1;
  122.     rp = &(s->RastPort);
  123.     d=1<<(s->BitMap.Depth);
  124.     LoadRGB4(&s->ViewPort,ScreenColors,32);
  125.     SetRast(rp,0);
  126.  
  127.     speed=my_gadg[1].value;
  128.  
  129.     for(n=0;n<(my_gadg[0].value*NB_PT);n++){
  130.         tab_pt[n].x=rand()%WIDTH;
  131.         tab_pt[n].y=rand()%HEIGHT;
  132.         tab_pt[n].vx=rand()%10-5;
  133.         tab_pt[n].vy=rand()%10-5;
  134.         if((tab_pt[n].vx==0)&&(tab_pt[n].vy==0)){
  135.             tab_pt[n].vx=5;
  136.             tab_pt[n].vy=5;
  137.         }
  138.         for(i=0;i<NB_OLD;i++){
  139.             tab_pt[n].old_x[i]=0;
  140.             tab_pt[n].old_y[i]=0;
  141.         }
  142.     }
  143.     n=0;
  144.     i=n;
  145.  
  146.     while(tst_end()==FALSE){
  147.  
  148.         WaitTOF();
  149.         rotate();
  150.  
  151.         for(n=0;n<(my_gadg[0].value*NB_PT);n++){
  152.             tab_pt[n].x+=tab_pt[n].vx;
  153.             if(tab_pt[n].x>=WIDTH){
  154.                 tab_pt[n].x=WIDTH-1;
  155.                 tab_pt[n].vx=-rand()%speed-1;
  156.             }
  157.             if(tab_pt[n].x<0){
  158.                 tab_pt[n].x=0;
  159.                 tab_pt[n].vx=rand()%speed+1;
  160.             }
  161.  
  162.             tab_pt[n].y+=tab_pt[n].vy;
  163.             if(tab_pt[n].y>=HEIGHT){
  164.                 tab_pt[n].y=HEIGHT-1;
  165.                 tab_pt[n].vy=-rand()%speed-1;
  166.             }
  167.             if(tab_pt[n].y<0){
  168.                 tab_pt[n].y=0;
  169.                 tab_pt[n].vy=rand()%speed+1;
  170.             }
  171.         }
  172.         SetDrMd(rp,JAM1);
  173.         color=0;
  174.         for(n=0;n<(my_gadg[0].value);n++){
  175.             SetAPen(rp,0);
  176.             /*************************************/
  177.             /* Affichage du carre le plus ancien */
  178.             /*************************************/
  179.  
  180.             t=&tab_pt[n*NB_PT];
  181.             Move(rp,t->old_x[0],t->old_y[0]);
  182.             for(i=1;i<NB_PT;i++){
  183.                 t++;
  184.                 Draw(rp,t->old_x[0],t->old_y[0]);
  185.             }
  186.             t=&tab_pt[n*NB_PT];
  187.             Draw(rp,t->old_x[0],t->old_y[0]);
  188.  
  189.             /*******************************/
  190.             /* Decalage de coord d'un cran */
  191.             /*******************************/
  192.  
  193.             t=&tab_pt[n*NB_PT];
  194.             for(i=0;i<NB_PT;i++){
  195.                 for(j=0;j<NB_OLD-1;j++){
  196.                     t->old_x[j]=t->old_x[j+1];
  197.                     t->old_y[j]=t->old_y[j+1];
  198.                 }
  199.                 t->old_x[NB_OLD-1]=t->x;
  200.                 t->old_y[NB_OLD-1]=t->y;
  201.                 t++;
  202.             }
  203.  
  204.             /******************************/
  205.             /* Affichage du nouveau carre */
  206.             /******************************/
  207.             color=n+1;
  208.             if((color%d)==0){
  209.                 color=1;
  210.             }
  211.             SetAPen(rp,color);
  212.             
  213.             t=&tab_pt[n*NB_PT];
  214.             Move(rp,t->x,t->y);
  215.             for(i=1;i<NB_PT;i++){
  216.                 t++;
  217.                 Draw(rp,t->x,t->y);
  218.             }
  219.             t=&tab_pt[n*NB_PT];
  220.             Draw(rp,t->x,t->y);
  221.         }
  222.     }
  223.    CloseScreen(s);
  224.    }
  225.  
  226. }
  227.  
  228. void    proc_init()
  229. {
  230. }
  231. void    proc_save()
  232. {
  233. }
  234. void    proc_end()
  235. {
  236. }
  237.  
  238.