home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / UTIL / mm1_colormix.lzh / colmix.c
C/C++ Source or Header  |  1994-05-18  |  3KB  |  106 lines

  1. /* colmix.c - additive color mixtures for MM/1                      */
  2. /* inspired by a program published once in "Rainbow" for Coco 3 ... */
  3. /* released to PD by Andrzej Kotanski,  May 1994                    */
  4. /* type: "cc colmix.c -t=/r0 -ix -l=/dd/lib/cgfx.l" to compile      */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8.  
  9. int red = 200, green = 200, blue = 200, ncol;
  10. char pal_data[12][3];
  11. char *name;
  12.  
  13. FILE *coltab;
  14. struct color {
  15.     int r, g, b;
  16.     char name[25];
  17. };
  18.  
  19. struct color Cols[550];
  20.  
  21. char *getcolor(red, green, blue)
  22. {
  23.     register int i;
  24.     register char *ptr;
  25.     register int val, tempval = 100000;
  26.  
  27.     for ( i = 0; i < ncol; i++ ) {
  28.         val =  abs(Cols[i].r - red) + abs(Cols[i].g - green)
  29.              + abs(Cols[i].b - blue);
  30.         if ( val < tempval ) {
  31.             tempval = val;
  32.             ptr = Cols[i].name;
  33.         }
  34.     }
  35.     return ptr;
  36. }
  37.  
  38. main()
  39. {
  40.     pal_data[9][0] = pal_data[9][1] = pal_data[9][2] = 255;
  41.     setpal();
  42.     FColor(1, 9);
  43.     BColor(1, 8);
  44.     Clear(1);
  45.     SetDPtr(1, 260, 60);    Circle(1, 90);
  46.     SetDPtr(1, 360, 60);    Circle(1, 90);
  47.     SetDPtr(1, 310, 100);   Circle(1, 90);
  48.  
  49.     coltab = fopen("/dd/sys/rgb.txt", "r");
  50.     if ( coltab == NULL )
  51.        exit(_errmsg(errno, "cannot open '/dd/sys/rgb.txt'\n"));
  52.     ncol = 0;
  53.     while ( !feof(coltab) ) {
  54.       fscanf(coltab, "%d %d %d %s", &Cols[ncol].r, &Cols[ncol].g,
  55.                      &Cols[ncol].b, Cols[ncol].name);
  56.       ncol++;
  57.     }
  58.  
  59.     CurXY(1, 0, 0);  printf("ADDITIVE\n\nCOLOR\n\nMIXTURES\n"); fflush(stdout);
  60.     CurXY(1, 50, 18); printf("COLOR"); fflush(stdout);
  61.     CurXY(1, 50, 20); printf("RED"); fflush(stdout);
  62.     CurXY(1, 50, 22); printf("GREEN"); fflush(stdout);
  63.     CurXY(1, 50, 24); printf("BLUE"); fflush(stdout);
  64.     CurXY(1, 56, 26); printf("enter new intensity !"); fflush(stdout);
  65.  
  66.     while (1) {
  67.        SetDPtr(1, 220, 60);    FColor(1, 1);    FFill(1);
  68.        SetDPtr(1, 310, 40);    FColor(1, 2);    FFill(1);
  69.        SetDPtr(1, 380, 60);    FColor(1, 3);    FFill(1);
  70.        SetDPtr(1, 250, 80);    FColor(1, 4);    FFill(1);
  71.        SetDPtr(1, 310, 80);    FColor(1, 5);    FFill(1);
  72.        SetDPtr(1, 360, 80);    FColor(1, 6);    FFill(1);
  73.        SetDPtr(1, 310, 120);   FColor(1, 7);    FFill(1);
  74.        FColor(1, 9);
  75.  
  76.        CurXY(1, 56, 20); ErEOLine(1); printf("%d", red); fflush(stdout);
  77.        CurXY(1, 56, 22); ErEOLine(1); printf("%d", green); fflush(stdout);
  78.        CurXY(1, 56, 24); ErEOLine(1); printf("%d", blue); fflush(stdout);
  79.        CurXY(1, 57, 18); ErEOLine(1); FColor(1, 5);
  80.        name =  getcolor(red, green, blue);
  81.        printf("%s", name); fflush(stdout);
  82.        FColor(1, 9);
  83.        CurXY(1, 0, 23); ErEOLine(1); 
  84.        printf("%s", name); fflush(stdout);
  85.        
  86.        do {
  87.             CurXY(1, 56, 20); scanf("%d", &red);
  88.        } while ( red < 0 || red > 255);
  89.        do {
  90.             CurXY(1, 56, 22); scanf("%d", &green);
  91.        } while ( green < 0 || green > 255);
  92.        do {
  93.             CurXY(1, 56, 24); scanf("%d", &blue);
  94.        } while ( blue < 0 || blue > 255);
  95.  
  96.        setpal();
  97.     }
  98. }
  99.  
  100. setpal()
  101. {
  102.     pal_data[1][0] = pal_data[2][0] = pal_data[4][0] = pal_data[5][0] = red;
  103.     pal_data[2][1] = pal_data[3][1] = pal_data[5][1] = pal_data[6][1] = green;
  104.     pal_data[4][2] = pal_data[5][2] = pal_data[6][2] = pal_data[7][2] = blue;
  105.     _ss_palette(1, 1, &pal_data[1][0], 9);
  106. }