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

  1.  /* Fichier effect.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 <exec/memory.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <graphics/gfx.h>
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/gfxmacros.h>
  15. #include <graphics/rastport.h>
  16. #include <graphics/displayinfo.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include "/includes/struct.h"
  20. #include "/includes/tom_gadget.h"
  21.  
  22. char    p_ver[]="$VER: Effects v1.1 (28/02/93)";
  23.  
  24. char    *p_text_info="   effects V1.1\n\n   by Thomas landspurg\n\nThere is 3 effects:\n- One effect based on the interferences\n- Another one based on a old article from\n  the Scientific America (effect Dragon)\n  Basicly, there is some things to see with\n  chaos theory!\n- The last one also based on this article,but\n  give another effect. Fracblanck is also\n  based on this effect.\n\n Just choose the effect you want..\n";
  25.  
  26. struct    Screen        *s;
  27. struct    RastPort    *rp;
  28.  
  29. #define reg register
  30. extern    void __asm MultiPlot(reg __a0 struct Screen *,reg __d0 WORD, reg __d1 WORD,reg __d2 WORD);
  31. extern    void __asm MonoPlot(    reg __a0 PLANEPTR,
  32.                 reg __d0 WORD,
  33.                 reg __d1 WORD,
  34.                 reg __d2 WORD,
  35.                 reg __d3 WORD,
  36.                 reg __d4 WORD);
  37.  
  38. #define    WIDTH    320
  39. #define    HEIGHT    256
  40. UWORD    width,height,nb_col;
  41. extern    struct    GfxBase    *GfxBase;
  42.  
  43. int    max_color=10;
  44. UWORD  *ScreenColors;
  45. #define    NB_COL    12
  46. UWORD    CMap[NB_COL+1]={
  47.     0x00f, 0x8f8, 0xff0, 0xe50, 0xf00,
  48.     0x0ff, 0x356, 0xf06, 0x00f, 0x0ff,
  49.     0xfff, 0xf00, 0xff0
  50. };
  51.  
  52.  
  53. int    duree;
  54. struct NewScreen   Screen = {
  55.     0, 0, WIDTH,HEIGHT, 5,0,1,NULL,CUSTOMSCREEN,NULL,NULL,NULL,NULL};
  56.  
  57. UBYTE         *TypeLabels[] = {
  58.     "interferences",
  59.     "dragon",
  60.     "Frac Effect",
  61.     "Random",
  62.     0l };
  63.  
  64.  
  65. struct tom_gadget my_gadg[]={
  66.     {"Ty_pe",    MX,    167,14,17,40,0, 0,0,0,(char *)TypeLabels},
  67.     {"T_empo",    SLIDER,    100,60,100,10,100,50,100,0,0},
  68.     {"_Resolution",    SCREEN,    100,80,100,12,0, 0,0,0,0},
  69.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  70. };
  71. static  unsigned        int     seed;
  72.  
  73.  
  74. unsigned        int     my_rand()
  75. {
  76.         
  77.         seed=25173*seed+138490;
  78.         return(seed);
  79. }
  80.  
  81. void    rotate()
  82. {
  83.     static    unsigned    int    compt=0;
  84.     unsigned    int    n,i;
  85.  
  86.     n=compt;
  87.     for(i=1;i<nb_col;i++){
  88.         n=n%max_color;
  89.         SetRGB4(    &s->ViewPort,i,
  90.                 (ScreenColors[n+1]&0xf00)>>8,
  91.                 (ScreenColors[n+1]&0x0f0)>>4,
  92.                 (ScreenColors[n+1]&0x00f));
  93.         n++;
  94.     }
  95.     compt++;
  96. }
  97. void    interferences()
  98. {
  99.     int    i,x,y,factor,col;
  100.     UWORD    my_mod;
  101.  
  102.     my_mod=nb_col-1;
  103.     factor=my_rand()%20+1;
  104.     for(y=-height/2+1;(y<=0)&&(tst_end()==FALSE);y++){
  105.         for(x=-width/2+1;x<=0;x++){
  106.             col=((x*x+y*y)/factor)%(my_mod)+1;
  107.             MultiPlot(s,(WORD)(width/2-1+x),(WORD)(height/2-1+y),col);
  108.             MultiPlot(s,(WORD)(width/2-1-x),(WORD)(height/2-1+y),col);
  109.             MultiPlot(s,(WORD)(width/2-1+x),(WORD)(height/2-1-y),col);
  110.             MultiPlot(s,(WORD)(width/2-1-x),(WORD)(height/2-1-y),col);
  111.  
  112.         }
  113.         rotate();
  114.     
  115.     }
  116.     for(i=0;(i<100)&&(tst_end()==FALSE);i++){
  117.         Delay(2);
  118.         WaitTOF();
  119.         rotate();
  120.     }
  121. }
  122.  
  123. /************************************************************ carre */
  124. /* suite de point quit provoaue des effets sympas */
  125.  
  126. void    carre()
  127. {
  128.     int    i,flg_end;
  129.     float    xx,yy,x,y;
  130.     float    a,t;
  131.     PLANEPTR    plane;
  132.     UWORD    Modulo;
  133.  
  134.     plane=rp->BitMap->Planes[0];
  135.     Modulo=rp->BitMap->BytesPerRow;
  136.     t=(float)(my_rand()%100+10);
  137.     a=PI-t/5000;
  138.     SetRast(rp,0);
  139.     SetRGB4(&s->ViewPort,1,0xf,0xf,0xf);
  140.     SetAPen(rp,1);
  141.     x=y=0;
  142.     flg_end=FALSE;
  143.     for(i=0;(i<duree)&&(flg_end==FALSE);i++){
  144.         if(i%100==0){
  145.             flg_end=tst_end();
  146.         }
  147.         xx=y-sin(x);
  148.         yy=a-x;
  149.         MonoPlot(    plane,
  150.                 width/2+(int)(2.0*x),
  151.                 height/2+(int)(2.0*y),
  152.                 Modulo,
  153.                 width,height
  154.                 );
  155. /*
  156.         WritePixel(rp,width/2+(int)(2.0*x),height/2+(int)(2.0*y));
  157. */
  158.         x=xx;
  159.         y=yy;
  160.     }
  161.     SetRast(rp,0);
  162. }
  163. #define    SGN(x)    ((x)<0?-1:1)
  164. #define    ABS(x)    ((x)<0?(-(x)):(x))
  165.  
  166. float    one_param()
  167. {
  168.     return ((float)((my_rand()%1000)/10-50.0));
  169. }
  170.  
  171. /************************************************************ effet_sun */
  172.  
  173. void    effet_sun()
  174. {
  175.     float    x,y,xx,yy,a,b,c;
  176.     int    i,xe,ye,flg_end;
  177.     UWORD    my_mod,duree2;
  178.  
  179.     my_mod=nb_col-1;
  180.     flg_end=FALSE;
  181.     SetRast(rp,0);
  182.     x=0;y=0;
  183.  
  184.     a=(float)one_param();
  185.     do{
  186.         b=(float)one_param();
  187.     }while(b==0.0);
  188.     c=(float)one_param();
  189.     duree2=duree*4;
  190.     for(i=0;(i<duree2)&&(flg_end==FALSE);i++){
  191.         if(i%100==0){
  192.             flg_end=tst_end();
  193.             if(i%1000==0){
  194.                 rotate();
  195.             }
  196.         }
  197.         xx=y-SGN(x)*sqrt(ABS(b*x-c));
  198.         yy=a-x;
  199.         xe=width/2+(int)(1.0*x);
  200.         ye=height/2+(int)(1.0*y);
  201.         if((xe>=0)&&(xe<width)&&(ye>=0)&&(ye<height)){
  202.             MultiPlot(s,(WORD)(xe),(WORD)(ye),(ReadPixel(rp,xe,ye)+1)%(my_mod)+1);
  203.         }
  204.         x=xx;
  205.         y=yy;
  206.     }
  207.     SetRast(rp,0);
  208. }
  209.  
  210.  
  211. /***************************************************************************/
  212.  
  213. UWORD    fade_one_digit(USHORT    n,USHORT    j,UWORD mask)
  214. {
  215.     register    UWORD    s,d;
  216.     s=CMap[n]&mask;
  217.     d=CMap[n+1]&mask;
  218.     return(((s+(d-s)*j*NB_COL/max_color))&mask);
  219. }
  220.  
  221. /***************************************************************************/
  222.  
  223. void    dark()
  224. {
  225.   int    effet,i,n,j;
  226.   struct    tom_gadget    *pg;
  227.  
  228.   /* With WB2.0 or higher, we use facilities of the intuition lib. */
  229.   /* to open screen (overscan...)                       */
  230.   pg=&my_gadg[2];
  231.   if((GfxBase->LibNode.lib_Version>=37)&&(pg->d3!=0)){
  232.     
  233.      s=OpenScreenTags(NULL,
  234.                SA_Width,(ULONG)pg->d1,
  235.                SA_Height,(ULONG)pg->d2,
  236.                            SA_Depth,(ULONG)pg->d3,
  237.                SA_Overscan,(ULONG)pg->value,
  238.                            SA_DisplayID,(ULONG)pg->p_data,
  239.                            SA_Quiet,TRUE,TAG_DONE);
  240.    }else{
  241.         s = OpenScreen( &Screen );
  242.    }
  243.    if ( s != 0){
  244.     FreeSprite (0);
  245.     GfxBase->SpriteReserved|=1;
  246.     rp = &(s->RastPort);
  247.     width=s->Width;
  248.     height=s->Height;
  249.     nb_col=1<<rp->BitMap->Depth;
  250.  
  251.  
  252.     /****************************************************************/
  253.     /* We create a color map, with transitions, in the range of all */
  254.     /* the availables colors                     */
  255.     /****************************************************************/
  256.  
  257.     if(nb_col>NB_COL*4){
  258.         max_color=nb_col;
  259.     }else{
  260.         max_color=nb_col*4;
  261.     }
  262.     ScreenColors=(UWORD *)AllocMem(sizeof(UWORD)*(max_color),MEMF_CLEAR);
  263.     if(ScreenColors){
  264.         /* We create a fading ColorMap, with transition....*/
  265.         n=0;
  266.         j=0;
  267.         for(i=1;i<max_color;i++){
  268.  
  269.             ScreenColors[i]= fade_one_digit(n,j,0xF00)
  270.                     |fade_one_digit(n,j,0X0f0)
  271.                     |fade_one_digit(n,j,0X00F);
  272.  
  273.             j++;
  274.             if(j>=(max_color/NB_COL)){
  275.                 j=0;
  276.                 n++;
  277.         }
  278.       }
  279.       ScreenColors[0]=0;
  280.     }
  281.     LoadRGB4(&s->ViewPort,ScreenColors,nb_col);
  282.     SetRast(rp,0);
  283.     while(tst_end()==FALSE){
  284.         if(my_gadg[0].value==3){
  285.             effet=my_rand()%3;
  286.         }else{
  287.             effet=my_gadg[0].value;
  288.         }
  289.         duree=my_gadg[1].value*100;
  290.         switch(effet){
  291.             case 0:    
  292.                 interferences();
  293.                 break;
  294.             case 1:    
  295.                 carre();
  296.                 break;
  297.             case 2:    
  298.             default:
  299.                 effet_sun();
  300.                 break;
  301.         }
  302.     }
  303.     if(ScreenColors)FreeMem(ScreenColors,sizeof(UWORD)*(max_color));
  304.     CloseScreen(s);
  305.       }
  306. }
  307.  
  308. void    proc_init()
  309. {
  310.         seed=VBeamPos();
  311. }
  312.  
  313. void    proc_save()
  314. {
  315. }
  316. void    proc_end()
  317. {
  318. }
  319.  
  320.