home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch19 / prog2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  2.0 KB  |  91 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <math.h>
  5. #include <graphics.h>
  6.  
  7.  
  8. void main(void)
  9. {
  10. int i,j,k,l;
  11. int height, height2;
  12. unsigned char x,y,z;
  13. unsigned char bubblemass[70][70][70];
  14. unsigned char bubble[21][21][21];
  15. int graphdriver, graphmode, grerror;
  16.   
  17.   
  18.   
  19.   /*MAKE BUBBLE*/
  20.  
  21.   for(i=-10; i < 11; i++)
  22.     {
  23.     height = ceil(10*sin(acos((double)i/10)));
  24.     if(height != 0)
  25.       for(j=-height; j < height+1; j++)
  26.         {
  27.         height2 = ceil(height*sin(acos((double)j/height)));  
  28.         if(height2 !=0)
  29.           for(k=-height2; k < height2+1; k++)
  30.             bubble[i+10][j+10][k+10] = 1; 
  31.         }
  32.     }
  33.  
  34.   
  35.   /*INITIATE BUBBLE MASS*/
  36.  
  37.   for(i=0; i < 70; i++)
  38.     for(j=0; j < 70; j++)
  39.       for(k=0; k < 70; k++)
  40.         bubblemass[i][j][k] = 0;
  41.  
  42.  
  43.   /*CREATE BUBBLE MASS*/
  44.  
  45.   for(l=0; l<75; l++)
  46.     {
  47.     x = (unsigned char)(((double)(rand())*30/
  48.                          (double)RAND_MAX) + 10);
  49.     y = (unsigned char)(((double)(rand())*30/
  50.                          (double)RAND_MAX) + 10);
  51.     z = (unsigned char)(((double)(rand())*30/
  52.                          (double)RAND_MAX) + 10);
  53.  
  54.     for(i=0; i < 21; i++)
  55.       for(j=0; j < 21; j++)
  56.         for(k=0; k < 21; k++)
  57.           if(bubble[i][j][k] == 1)
  58.             if(bubblemass[x+i][y+j][z+k] < 15)
  59.               bubblemass[x+i][y+j][z+k] ++;
  60.     }
  61.  
  62.   
  63.   /*PLOT RESLICED IMAGES*/
  64.   
  65.   graphdriver = VGA256;
  66.   graphmode = 0;
  67.   initgraph(&graphdriver, &graphmode, "");
  68.   grerror = graphresult();
  69.   if(grerror)
  70.     {
  71.     closegraph();
  72.     printf("Error Initializing Graphics Mode.\n");
  73.     exit(1);
  74.     }
  75.   
  76.   while(!kbhit())
  77.     {
  78.     for(i=0; i < 70; i++)
  79.       for(j=0; j < 70; j++)
  80.         for(k=0; k < 70; k++)
  81.           {
  82.           putpixel(j, k, 16+bubblemass[i][j][k]); 
  83.           putpixel(j+70, k, 16+bubblemass[k][i][j]);
  84.           putpixel(j, k+70, 16+bubblemass[j][k][i]);
  85.           }
  86.     }
  87.  
  88.   getch();
  89.   closegraph();
  90. }
  91.