Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.82 KB | None | 0 0
  1. #include "common.h"
  2. #include "logo.h"
  3.  
  4. Logos *GetLogoXY(void)
  5. /* Function to read the logo from file and return a pointer to it. */
  6. {
  7.     Logos *a;
  8.     Logo *b;
  9.     /* Temporary variables to save logo parts */
  10.    
  11.     int i, j;
  12.     FILE *fp;
  13.     fp = fopen("logo.txt", "r");
  14.     /* Open logo.txt for read */
  15.    
  16.     a = ALLOC(sizeof(Logos));
  17.     /* Allocate memory to the temporary logo variable */
  18.    
  19.     fscanf(fp, "%d", &a -> n);
  20.     /* Read parts of the logo from file */
  21.    
  22.     a -> logo = (Logo **)ALLOC(a -> n * sizeof(Logo *));
  23.     /* Allocate memory to the pointer array of logo parts */
  24.    
  25.     for(i = 0; i < a -> n; i++)
  26.     {
  27.         b = ALLOC(sizeof(Logo));
  28.         /* Allocate memory for every part of the logo */
  29.        
  30.         fscanf(fp, "%d", &b -> n);
  31.         /* Read the number of pointer for a part */
  32.        
  33.         b -> x = (int *)ALLOC(b -> n * sizeof(int));
  34.         b -> y = (int *)ALLOC(b -> n * sizeof(int));
  35.         /* Dynamic Allocate array to save the coordinates */
  36.        
  37.         for(j = 0; j < b -> n; j++)
  38.             fscanf(fp, "%d%d", &b -> x[j], &b -> y[j]);
  39.             /* Read each coordinates from file */
  40.        
  41.         a -> logo[i] = b;
  42.         /* Give the pointer back to the whole logo pointer */
  43.     }
  44.     fclose(fp);
  45.     return a;
  46. }
  47.  
  48. void DrawLogo(void *n)
  49. /* Draw out the Logo */
  50. {
  51.     int midx, midy;
  52.     /* Saving the center of the screen */
  53.    
  54.     int dx, dy;
  55.     /* Saving current X,Y coordinates */
  56.    
  57.     int dnx, dny;
  58.     /* Saving the delta X,Y for putpixel operations */
  59.    
  60.     int c, lc = -1;
  61.     /* Saving random color and the last one, to make sure no same color
  62.      * is used between next door letters */
  63.    
  64.     int i, j, tx, ty;
  65.     Logos *a;
  66.     a = GetLogoXY();
  67.     /* Get Logo Using GetLogoXY() */
  68.    
  69.     DoNothing(n);
  70.    
  71.     midx = getmaxx() / 2;
  72.     midy = getmaxy() / 2;
  73.     /* Get the center of the screen */
  74.    
  75.     for(i = 200; i>0; i-=20)
  76.     /* Draw some circles */
  77.     {
  78.         SetColor(15);
  79.         circle(midx, midy, i);
  80.         /* Draw a circle */
  81.        
  82.         delay(50);
  83.         SetColor(0);
  84.         circle(midx, midy, i);
  85.         /* Set color to black and erase the circle */
  86.     }
  87.    
  88.     for(i = 0; i < a -> n; i++)
  89.     /* Draw each part of the logo */
  90.     {
  91.         SetColor(15);
  92.         for(j = 1; j < a -> logo[i] -> n; j++)
  93.         /* String the points to lines */
  94.         {
  95.             dx = a -> logo[i] -> x[j-1];
  96.             dy = a -> logo[i] -> y[j-1];
  97.             /* Current location is at last point */
  98.            
  99.             for(; dx != a -> logo[i] -> x[j] ||
  100.                   dy != a -> logo[i] -> y[j]; )
  101.             /* If not reached, just draw another pixel */
  102.             {
  103.                 putpixel(dx, dy, 15);
  104.                 delay(3);
  105.                 dnx = dny = 1;
  106.                 if((dx != a -> logo[i] -> x[j]) &&
  107.                    (dy != a -> logo[i] -> y[j]))
  108.                 /* Wordaround for non 1:1 scaling */
  109.                 {
  110.                     tx = dx - a -> logo[i] -> x[j];
  111.                     ty = dy - a -> logo[i] -> y[j];
  112.                     /* Calculate the difference */
  113.                    
  114.                     tx = tx > 0 ? tx: -tx;
  115.                     ty = ty > 0 ? ty: -ty;
  116.                     /* Force it to positive */
  117.                    
  118.                     if(tx > ty)
  119.                         dnx++;
  120.                     else if(ty > tx)
  121.                         dny++;
  122.                     /* A simple workaround that supports 1:2 and 2:1
  123.                      * scaling ... */
  124.                 }
  125.                 if(dx != a -> logo[i] -> x[j])
  126.                     dx += (dx < a -> logo[i] -> x[j] ? dnx: -dnx);
  127.                 if(dy != a -> logo[i] -> y[j])
  128.                     dy += (dy < a -> logo[i] -> y[j] ? dny: -dny);
  129.                 /* Plus the delta into current location */
  130.             }
  131.         }
  132.         do
  133.         {
  134.             c = rand() % 6 + 1;
  135.         } while(c == lc);
  136.         /* Generate a different color from the last letter */
  137.        
  138.         lc = c;
  139.         /* Save the color for next time comparison */
  140.        
  141.         if(a -> logo[i] -> n < 5)
  142.             c = 0;
  143.         /* Workaround for the triangle in letter "A" */
  144.        
  145.         setfillstyle(1, c);
  146.         floodfill((a -> logo[i] -> x[0] + a -> logo[i] -> x[1]) / 2 + 1,
  147.                   (a -> logo[i] -> y[0] + a -> logo[i] -> y[1]) / 2, 15);
  148.         /* Floodfill in the pixel right to the first line of the
  149.          * letter. */
  150.     }
  151.    
  152.     /* Keep the image until a keyboard hit */
  153.    
  154.     for(i = 0; i < a -> n; i++)
  155.     {
  156.         FREEMEM(a -> logo[i] -> x);
  157.         FREEMEM(a -> logo[i] -> y);
  158.         FREEMEM(a -> logo[i]);
  159.     }
  160.     FREEMEM(a -> logo);
  161.     FREEMEM(a);
  162.     /* Release all memory that used */
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement