home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff374.lzh / PopArt / sorcery / art.c < prev    next >
C/C++ Source or Header  |  1990-10-08  |  16KB  |  485 lines

  1.  
  2.  
  3.                 /*  art  ---  play around with dots...  */
  4.  
  5.  
  6. #include <graphics/gfxmacros.h>
  7. #include "stuff.h"
  8.  
  9. #define PIXI        Ratio
  10. #define MAXWID      MaxUP
  11.  
  12. #define INSIDE(x,j) ((x) >= 36 && (x) < 36 + ImageWid * PIXI && \
  13.                      (j) >= 21 && (j) < 21 + MaxDN * PIXI)
  14.  
  15.  
  16.                extern  ULONG                   msgclass   ;
  17.                extern  USHORT                  msgcode    ;
  18.                extern    int                   gadcode    ;
  19.                extern  struct   Gadget         TGads []   ;
  20.                extern  struct   RastPort     * reep       ;
  21.                extern    int                   no_help    ;
  22.                extern  UWORD                   mrQ        ;
  23.                extern  struct  SUPERwindow SuperWindows [];
  24.                extern    int               CurrentWindow  ;
  25.                extern    int                    bloking   ;
  26.                        struct  Window         * win       ;
  27.                        ULONG                   thisCol = 1;
  28.                        USHORT                   Mx, My    ;
  29.                        USHORT                   izDn      ;
  30.                          int                webefillin = 0;
  31.                          int                  curOnion = 0;
  32.                          int                  togOnion = 1;
  33.                          int                   picking     ;
  34.  
  35.                void     maybedospotat (),  maybedospot  (),
  36.                       dospot (),  dumb_gadgets (), doKeys ();
  37.  
  38.  
  39.       void
  40. art ()
  41. {
  42.  
  43.     SWITCH  (msgclass)   {
  44.         CS  MOUSEBUTTONS :  switch (msgcode)  {
  45.           CS SELECTDOWN  :  if (izShift (mrQ) && INSIDE (Mx, My))
  46.                                                 {  doBox ();           RET;  }
  47.                             ifn (webefillin)  izDn = 1, maybedospotat ();  RET;
  48.           CS  SELECTUP   :  izDn=0; if (webefillin) fill(); new_title ();  RET;
  49.           CS   MENUUP    :  gadcode = PICKG;      dumb_gadgets ();     RET; }
  50.                 RET;
  51.  
  52.         CS  MOUSEMOVE    :  if (izDn)  maybedospotat ();  no_help = 0; RET;
  53.         CS  GADGETUP     :  if (  gadcode > 32 )  {  dumb_gadgets () ; RET; }
  54.                             new_color (gadcode % 32L);                 RET;
  55.         CS  RAWKEY       :  doKeys ();                                 RET;
  56.     }
  57.  
  58. }  /*  end of art.  In the words of Mark Knopfler,
  59.                                 "they never gave us no money - no breaks"!  */
  60.  
  61.  
  62.          void
  63. doKeys ()
  64. {
  65.     ULONG bink;
  66.  
  67.  
  68.     if (msgcode < 76 || msgcode > 79) {       /*  if it's not an arrow key  */
  69.         switch (msgcode)  {
  70.             case 53:  gadcode = BLOKG;  break;
  71. /*            case 54:  gadcode = NEW_G;  break;  it shouldn't be this easy */
  72.             case 33:  gadcode = SAVEG;  break;
  73.             case 40:  gadcode = LOADG;  break;
  74.             case 51:  gadcode = CLONG;  break;
  75.             case 23:  gadcode = INC_G;  break;
  76.             case 35:  gadcode = FILLG;  break;
  77.             case 49:  gadcode = COPYG;  break;
  78.             case 22:  gadcode = UNDOG;  break;
  79.             case 20:  gadcode = STAKG;  break;
  80.             case 19:  gadcode = ROLLG;  break;
  81.             case 16:  gadcode = SEQ_G;  break;
  82.             case 24:  gadcode = ONIOG;  break;
  83.             case 25:  gadcode = POP_G;  break;
  84.             default:  return;  }
  85.  
  86.         dumb_gadgets ();
  87.         return;  }
  88.  
  89.     bink = thisCol;
  90.  
  91.     switch (msgcode)  {
  92.         case 76:  --bink;  break;
  93.         case 77:  ++bink;  break;
  94.         case 78:  if (bink < 16)  bink += 16;  break;
  95.         case 79:  if (bink > 15)  bink -= 16;  break;  }
  96.  
  97.     if (bink < 0)  bink += 32; else if (bink > 31)  bink %= 32;
  98.     new_color (bink);
  99.  
  100. }                                           /* the mysteries of finite math */
  101.  
  102.  
  103.                 void
  104. maybedospotat ()
  105. {
  106.     REG USHORT i, j, x = Mx - Mx % PIXI,  y = My - My % PIXI;
  107.  
  108.  
  109.     ifn (INSIDE (Mx, My))   return;
  110.     ifn (bloking)  {  maybedospot (x, y);  return;  }
  111.  
  112.     LOOP     ( i = x - bloking * PIXI;  i < x + bloking;  i += PIXI )
  113.         loop ( j = y - bloking * PIXI;  j < y + bloking;  j += PIXI )
  114.                    if INSIDE (i, j)  maybedospot (i, j);
  115.  
  116. }
  117.  
  118.  
  119.                       void
  120. maybedospot (atx, aty)   USHORT atx, aty;                        /* uh huh  */
  121. {
  122.     REG UBYTE x = (int) (atx - 35) / PIXI, y = (int) (aty - 20) / PIXI;
  123.  
  124. #define even(x) ((x)%2)
  125. #define  odd(x) (!even(x))                                      /*  duh...  */
  126.  
  127.  
  128.     if (!gadzon (TGads [ 1 ]) && !gadzon (TGads [ 2 ]))  {
  129.         dospot (atx, aty, x, y);                                RET;  }
  130.  
  131.     if (gadzon (TGads [ 2 ]))  {
  132.         if ((even (x) && odd (y)) || (odd (x) && even (y)))
  133.             dospot (atx, aty, x, y);                            RET; }
  134.  
  135.     if  ((odd (x) && odd (y)) || (even (x) && even (y)))
  136.             dospot (atx, aty, x, y);
  137.             
  138. }                                     /*  end of maybedospot ... maybe ... */
  139.  
  140.  
  141.                                 void
  142. dospot ( x, y, imageX, imageY )      USHORT  x, y; UBYTE   imageX, imageY;
  143. {
  144.     ULONG spot;
  145.     extern int popping;
  146.  
  147.  
  148.     spot = popping && curOnion != CurrentWindow?
  149.         ReadPixel (zreep (curOnion), imageX + 4L, imageY + 14L): thisCol;
  150.  
  151.     SetAPen (zreep (CurrentWindow), spot);
  152.     SetAPen (reep, spot);
  153.  
  154.     IFN ( reep->DrawMode & COMPLEMENT )
  155.         WritePixel (reep, (long) (imageX+PixOver), (long) (imageY+PixDown)),
  156.         WritePixel (zreep (CurrentWindow), imageX +  4L, imageY + 14L);
  157.  
  158.     RectFill (reep, x - 1L, y - 1L, x + PIXI - 2L, y + PIXI - 2L);
  159.  
  160.     if (togOnion && !popping)  {
  161.         spot = (long) ReadPixel (zreep (curOnion), imageX + 4L, imageY + 14L);
  162.  
  163.         if (spot != thisCol)  {
  164.             SetAPen (reep, spot);
  165.             WritePixel (reep, (long) x, (long) y);
  166.             SetAPen (reep, (long) thisCol);  }
  167.  
  168.     }
  169.  
  170. }                                                   /* dismal end of dospot */
  171.  
  172.  
  173.         void
  174. suck ()                       /*  copy the working image into a new window  */
  175. {
  176.  
  177.     ClipBlit (reep, (long) PixOver, (long) PixDown,
  178.              zreep (CurrentWindow), 4L, 14L, (long) ImageWid,
  179.                                         (long) MaxDN, (long) 0xc0);
  180.  
  181. }                                                    /*  one suck later...  */
  182.  
  183.  
  184.         void
  185. blow ()                    /*  copy a window image into the working images  */
  186. {
  187.  
  188.     ClipBlit (zreep (CurrentWindow), 4L, 14L,
  189.                reep, (LONG) PixOver,  (LONG) PixDown,
  190.                      (LONG) ImageWid, (LONG) MaxDN, (LONG) 0xc0);
  191.  
  192.     redrawWorkArea (0);
  193.  
  194. }       /*  sorry about the names.  You gotta admit they jog the memory...  */
  195.  
  196.  
  197.         void
  198. copy ()                    /*  copy the working image into the undo buffer  */
  199. {
  200.  
  201.     ClipBlit (reep, (LONG) PixOver,  (LONG) PixDown,
  202.               reep, (LONG) UbfOver,  (LONG) UbfDown,
  203.                     (LONG) ImageWid, (LONG) MaxDN, (LONG) 0xc0);
  204.  
  205. }                                          /*  long long long long long...  */
  206.  
  207.  
  208.         void
  209. undo ()                        /*  copy the buffer back the working images  */
  210. {
  211.  
  212.     ClipBlit (reep, (LONG) UbfOver,  (LONG) UbfDown,
  213.               reep, (LONG) PixOver,  (LONG) PixDown,
  214.                     (LONG) ImageWid, (LONG) MaxDN, (LONG) 0xc0);
  215.  
  216.     suck ();
  217.     redrawWorkArea (0);
  218.  
  219. }                                     /*  long long long long long long...  */
  220.  
  221.  
  222.               void
  223. newOnion (it)
  224. {
  225.     REG LONG rX, rY, spot;
  226.         LONG XX, YY, wasspot = thisCol;
  227.  
  228.  
  229.     if (curOnion == CurrentWindow || !togOnion)  return;
  230.     Mess ("Redrawing shadow area...");
  231.     offInput ();
  232.  
  233.     LOOP   (rX = 36, XX = 4L;  rX < 36 + ImageWid * Ratio;  rX += Ratio, ++XX)
  234.         loop (rY = 21, YY = 14L;  rY < 21 + MaxDN * Ratio;  rY += Ratio, ++YY)  {
  235.             spot = (long) ReadPixel (zreep (it), XX, YY);
  236.             if (spot != wasspot)  SetAPen (reep, wasspot = spot);
  237. /*          if (spot != ReadPixel (reep, rX, rY))  */
  238.             WritePixel (reep, rX, rY);  }
  239.  
  240.     SetAPen (reep, (long) thisCol);
  241.     Mess ("Finished Reshadowing");
  242.     onInput ();
  243.  
  244. }
  245.  
  246.                      void
  247. redrawWorkArea (total)
  248. {
  249.     REG LONG realX, realY, spot;      /*  "real" meaning the working image  */
  250.         LONG XX, YY, wasspot = thisCol;
  251.  
  252.  
  253.     Mess ("Redrawing work area...");
  254.     offInput ();                              /*  turn off mouse reporting  */
  255.  
  256.     LOOP (realX = 35, XX = PixOver;
  257.           realX < 35 + ImageWid * Ratio;
  258.           realX += Ratio, ++XX)
  259.  
  260.         loop (realY = 20, YY = PixDown;
  261.               realY < 20 + MaxDN * Ratio;
  262.               realY += Ratio, ++YY)  {
  263.  
  264.             spot = (long) ReadPixel (reep, XX, YY);
  265.             if (spot != wasspot)  SetAPen (reep, wasspot = spot);
  266.  
  267.             if (total || spot != ReadPixel (reep, realX, realY))
  268.                 RectFill (reep, realX, realY, realX+PIXI-1L, realY+PIXI-1L);
  269.  
  270.         }                                       /*  looping thru the spots  */
  271.  
  272.     SetAPen (reep, (long) thisCol);
  273.     Mess ("Finished Redrawing");
  274.     onInput ();
  275.     if (togOnion)  newOnion (curOnion);
  276.  
  277. }
  278.  
  279.  
  280.              void
  281. flash_blok ()                            /*  complement the mouse location  */
  282. {
  283.     static USHORT patsy [] = { 0x5555, 0xaaaa };
  284.  
  285.  
  286.     SetDrMd (reep, COMPLEMENT);
  287.     SetAfPt (reep, patsy, 1L);
  288.     maybedospotat ();
  289.     SetAfPt (reep, NULL, 0L);
  290.     SetDrMd (reep, JAM2);
  291.  
  292. }
  293.  
  294.  
  295.                 void
  296. dumb_gadgets ()                                      /*  title says all...  */
  297. {
  298.  
  299.     SWITCH (gadcode)  {  extern struct Window *seqwin;
  300.         CS  BLOKG  :  blokOnOff ();                                     RET;
  301.         CS  NEW_G  :  anim (&TGads  [3]);   new ();                     RET;
  302.         CS  PICKG  :                       pick ();  input ();          RET;
  303.         CS  SAVEG  :  if izCtrl (mrQ)  increment ();  else  anim (&TGads [ 5]);
  304.                       save ();                                          RET;
  305.         CS  LOADG  :  if izCtrl (mrQ)  stor ();  else anim (&TGads [6]);
  306.                       load ();                                          RET;
  307.         CS  CLONG  :  anim (&TGads [ 7]);  stor ();           RET;
  308.         CS  INC_G  :  anim (&TGads [10]);  increment ();                RET;
  309.         CS  INS_G  :                       increment ();  save ();      RET;
  310.  
  311.         CS  FILLG  :  anim (&TGads [12]);
  312.  
  313.                       ifn (webefillin)  fillermouse (), webefillin = 1;
  314.                           else      ClearPointer (win), webefillin = 0; RET;
  315.  
  316.         CS  COPYG  :   copy ();                                         RET;
  317.         CS  UNDOG  :   undo ();                                         RET;
  318.         CS  STAKG  :  stack ();                                         RET;
  319.         CS  ROLLG  :  anim (&TGads [ 9]);  /* roll(); is in anim.c!*/   RET;
  320.  
  321.         CS  SEQ_G  :  if (seqwin)  WindowToFront (seqwin);
  322.                           else  openSeqWin ();                          RET;
  323.  
  324.         CS  CNL_G  :  stor ();  load ();                                RET;
  325.         CS  POP_G  :  popOnOff ();                                      RET;
  326.         CS  XWB_G  :  clozeWB ();                                       RET;
  327.         CS  TWEKG  :  tweakColors ();                                       RET;
  328.         CS  ONIOG  :  togOnion = !togOnion;
  329.  
  330.                       ifn (togOnion)  onionOff ();
  331.                           else       onionOn  (), newOnion (curOnion);  RET;
  332.  
  333. /*      CS  FREEG  :  free ();                                          RET;*/
  334.     }                                 /*  switch, whip, paddle, spank, etc  */
  335.  
  336. }                                            /*  done all the dumb gadgets  */
  337.  
  338.  
  339.        void
  340. new ()             /*  "new" is a computer euphemism for "KILL EVERYTHING"  */
  341. {
  342.  
  343.         hotHelp  ("To the Great Bit Bucket!!!", 2, 1);
  344.  
  345.         RectFill  ( reep,  35L,                    20L,
  346.                            34L + ImageWid * Ratio, 19L + MaxDN * Ratio );
  347.  
  348.         RectFill  ( reep, (long) PixOver, (long) PixDown,
  349.                           (long) PixOver + ImageWid - 1L,
  350.                           (long) PixDown + MaxDN - 1L );
  351.  
  352.         RectFill  ( zreep (CurrentWindow), 4L, 14L,
  353.                             3L + ImageWid, 13L + MaxDN );
  354.  
  355.         if (togOnion)  newOnion (curOnion);
  356.  
  357. }
  358.  
  359.  
  360.     int  no_help = 0;
  361.  
  362.        void
  363. pick ()
  364. {
  365.  
  366.     Mess ("Click on a Color (\"Pick\" to Cancel)");
  367.     pickmouse ();
  368.  
  369.     forever {
  370.         no_help = 1;
  371.         picking = 1;
  372.         if (!input ())  quit ("Wrong color picked...");
  373.         picking = 0;
  374.         no_help = 0;
  375.         Mx = win->MouseX;
  376.         My = win->MouseY;
  377.  
  378.         if ( (msgclass == MOUSEBUTTONS && msgcode == SELECTUP) ||
  379.              (msgclass == GADGETUP     && gadcode != PICKG   )    )  {
  380.             ClearPointer (win);
  381.             Mess ("New Color Picked");
  382.             new_color ((ULONG) ReadPixel (reep, (long) Mx, (long) My));
  383.             Wait (1L << win->UserPort->mp_SigBit);
  384.             break;  }
  385.  
  386.         if ( msgclass == GADGETUP     && gadcode == PICKG )  {
  387.             ClearPointer (win);
  388.             Mess ("Cancelled - No New Color Picked");
  389.             Wait (1L << win->UserPort->mp_SigBit);
  390.             break;  }
  391.     }                                                   /*  end of forever  */
  392.  
  393.     if (webefillin)  fillermouse ();
  394.         else ClearPointer (win);
  395.  
  396.  
  397. }       /*  you can pick your mouse and you can pick your friends, but ...  */
  398.  
  399.  
  400.     static ULONG fillcolor;
  401.     void fillazoid ();
  402.  
  403.         void
  404. fill ()
  405. {
  406.  
  407.     if (!INSIDE (Mx, My))  return;
  408.     fillcolor = (ULONG) ReadPixel (reep, (long) Mx, (long) My);
  409.     if (fillcolor == thisCol)  {  Mess ("Same Color Picked!");  return;  }
  410.     Mess ("Here We Go!");
  411.     copy ();
  412.     offInput ();
  413.     fillazoid (Mx - Mx % PIXI, My - My % PIXI, 170);
  414.     onInput ();
  415.     Mess ("Done Filling");
  416.  
  417. }       /*  you can fill your mouse and you can fill your friends, but ...  */
  418.  
  419.  
  420.                     void
  421. fillazoid (xx, yy, count)
  422. {
  423.  
  424.     ifn (--count)  return;
  425.     ifn (INSIDE (xx, yy))  return;
  426.     if (fillcolor != (ULONG) ReadPixel (reep, xx - 1L, yy - 1L))  return;
  427.     maybedospot (xx, yy);
  428.  
  429.     switch (rand () % 4)  {
  430.         case 0: fillazoid (xx - PIXI, yy, count);
  431.                 fillazoid (xx + PIXI, yy, count);
  432.                 fillazoid (xx, yy + PIXI, count);
  433.                 fillazoid (xx, yy - PIXI, count);
  434.         case 1: fillazoid (xx + PIXI, yy, count);
  435.                 fillazoid (xx, yy + PIXI, count);
  436.                 fillazoid (xx, yy - PIXI, count);
  437.                 fillazoid (xx - PIXI, yy, count);
  438.         case 2: fillazoid (xx, yy + PIXI, count);
  439.                 fillazoid (xx, yy - PIXI, count);
  440.                 fillazoid (xx - PIXI, yy, count);
  441.                 fillazoid (xx + PIXI, yy, count);
  442.         case 3: fillazoid (xx, yy - PIXI, count);
  443.                 fillazoid (xx - PIXI, yy, count);
  444.                 fillazoid (xx + PIXI, yy, count);
  445.                 fillazoid (xx, yy + PIXI, count);  }
  446.  
  447.  
  448. }   /*  why so many fillazoids?  the order they are called affects the outer
  449.                                             boundary of the filled area...  */
  450.  
  451.                  void
  452. SchRep (waz)
  453. {
  454.     long xx, yy;
  455.  
  456.  
  457.     Mess ("SchRepping Color");
  458.     offInput ();
  459.  
  460.     LOOP  (xx = 35; xx < ImageWid * PIXI + 35; xx += PIXI)
  461.         loop (yy = 20; yy < MaxDN * PIXI + 20; yy += PIXI)
  462.             if (waz == ReadPixel (reep, xx, yy))
  463.                 maybedospot ((USHORT) xx + 1, (USHORT) yy + 1);
  464.  
  465.     Mess ("SchRepped Color");
  466.     onInput ();
  467.  
  468. }
  469.  
  470.  
  471. new_title ()
  472. {
  473.     static char buff [125], number [16] ;
  474.  
  475.     strcpy ( buff, "PopArt  -  by PHLIP  -  " );
  476.     strcat ( buff, decimal ((int) Mx, number) );
  477.     strcat ( buff, "  ");
  478.     strcat ( buff, decimal ((int) My, number) );
  479.     strcat ( buff, "         ");
  480.  
  481.     SetWindowTitles (win,  buff, -1L);
  482.  
  483. }                          /*  pop out the mouseXY, for position new stuff  */
  484.  
  485.