home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk433.lzh / Gwin / exsrc.lzh / changecolor.c < prev    next >
C/C++ Source or Header  |  1991-01-12  |  4KB  |  179 lines

  1. #include <stdio.h>
  2. #include "gwin.user.h"
  3.  
  4. /* I used this routine, embedded a geographic display system, */
  5. /* to adjust the relative brightnesses of the colors I was    */
  6. /* using so that I could get 35mm slides without the white    */
  7. /* "blooming" compared to the red.  I held a photocell up to  */
  8. /* each square region on the screen and read the intrinsic    */
  9. /* brightness with a voltmeter.  I then adjusted each color   */
  10. /* by clicking on the sub-squares to adjust the amount of red,*/
  11. /* blue, and green being used and adjusted to taste and to    */
  12. /* the camera response.                                       */
  13.  
  14. #define MAXBOXES 32
  15.  
  16. float black       = 0.0;
  17. float red         = 1.0;
  18. float green       = 2.0;
  19. float border      = 3.0;
  20. float yellow      = 5.0;
  21. float white       = 7.0;
  22. float forestgreen = 13.0;
  23. float aqua        = 14.0;
  24. float darkblue    = 10.0;
  25. float blue        = 11.0;
  26.  
  27. int R = 0;
  28. int G = 1;
  29. int B = 2;
  30.  
  31. struct boxstruct {
  32. int active;
  33. float x1,y1,x2,y2,color;
  34. } boxdata[MAXBOXES];
  35.  
  36. main()
  37. {
  38.    ustart("high2",0.,600.,0.,400.);
  39.    adjust_color();
  40. }
  41.  
  42. adjust_color()
  43. {
  44. float x,y,redvalue,greenvalue,bluevalue;
  45. int index,more,color,increment;
  46. float x1,y1,x2,y2;
  47.  
  48.    x1 = 0.0;
  49.    y1 = 0.0;
  50.    x2 = 100.0;
  51.    y2 = 100.0;
  52.  
  53.    udarea(x1,x2,y1,y2);
  54.    upset("colo",white);
  55.    uoutln();
  56.  
  57.    draw_box((int)red,red,                 1.,1.,13.,20.);
  58.    draw_box((int)green,green,            15.,1.,27.,20.);
  59.    draw_box((int)blue,blue,              29.,1.,41.,20.);
  60.    draw_box((int)yellow,yellow,          43.,1.,55.,20.);
  61.    draw_box((int)white,white,            57.,1.,69.,20.);
  62.    draw_box((int)forestgreen,forestgreen,71.,1.,83.,20.);
  63.    draw_box((int)aqua,aqua,              85.,1.,97.,20.);
  64.    draw_box((int)border,border,          1.,21.,13.,40.);
  65.  
  66.    for(;;){
  67.       ugrin(&x,&y);
  68.       getboxdata(x,y,&index,&more,&color);
  69.       if(index < 0 )break;
  70.       ugetrgb((float)index,&redvalue,&greenvalue,&bluevalue);
  71.       if(more){
  72.          increment = 1;
  73.       }else{
  74.          increment = -1;
  75.       }
  76.  
  77.       if(color == R) redvalue    = redvalue + increment;
  78.       if(color == G) greenvalue  = greenvalue + increment;
  79.       if(color == B) bluevalue   = bluevalue + increment;
  80.  
  81.       usetrgb((float)index,redvalue,greenvalue,bluevalue);
  82.       draw_box(index,boxdata[index].color,
  83.                      boxdata[index].x1,
  84.                      boxdata[index].y1,
  85.                      boxdata[index].x2,
  86.                      boxdata[index].y2);
  87.    }
  88.  
  89.    uend();
  90. }
  91.  
  92. draw_box(boxindex,color,x1,y1,x2,y2)
  93. int boxindex;
  94. float color;
  95. float x1,y1,x2,y2;
  96. {
  97. float redvalue,greenvalue,bluevalue;
  98. char redint[10],greenint[10],blueint[10];
  99.  
  100.    if(boxindex >= MAXBOXES){
  101.       printf("Box index limit of %d exceeded.\n",MAXBOXES);
  102.       exit(1);
  103.    }
  104.  
  105.    ugetrgb((float)boxindex,&redvalue,&greenvalue,&bluevalue);
  106.  
  107.    upset("colo",color);
  108.    uset("fill");
  109.    umove(x1,y1);
  110.    udraw(x1,y2);
  111.    udraw(x2,y2);
  112.    udraw(x2,y1);
  113.    udraw(x1,y1);
  114.    uset("nofi");
  115.  
  116.    upset("colo",black);
  117.  
  118.    umove(x1,y1+.3333*(y2-y1));
  119.    udraw(x2,y1+.3333*(y2-y1));
  120.  
  121.    umove(x1,y1+.6666*(y2-y1));
  122.    udraw(x2,y1+.6666*(y2-y1));
  123.  
  124.    umove(x1+.5*(x2-x1),y1);
  125.    udraw(x1+.5*(x2-x1),y2);
  126.  
  127.    sprintf(redint,"%2.0f",redvalue);
  128.    sprintf(greenint,"%2.0f",greenvalue);
  129.    sprintf(blueint,"%2.0f",bluevalue);
  130.  
  131.    upset("bcol",color);
  132.    uprint(x1+.7*(x2-x1),y1+.78*(y2-y1),redint);
  133.    uprint(x1+.7*(x2-x1),y1+.45*(y2-y1),greenint);
  134.    uprint(x1+.7*(x2-x1),y1+.11*(y2-y1),blueint);
  135.    upset("bcol",black);
  136.  
  137.    boxdata[boxindex].active = 1;
  138.    boxdata[boxindex].x1 = x1;
  139.    boxdata[boxindex].x2 = x2;
  140.    boxdata[boxindex].y1 = y1;
  141.    boxdata[boxindex].y2 = y2;
  142.    boxdata[boxindex].color = color;
  143.  
  144. }
  145.  
  146. getboxdata(x,y,index,more,color)
  147. float x,y;
  148. int *index,*more,*color;
  149. {
  150. int i;
  151. float rmax, gmax;
  152.  
  153.    *more = 0;
  154.    *index = -1;
  155.    for(i=0;i<MAXBOXES;i++){
  156.       if(       x >= boxdata[i].x1
  157.              && x <= boxdata[i].x2
  158.              && y >= boxdata[i].y1
  159.              && y <= boxdata[i].y2){
  160.          *index = i;
  161.          if(x > boxdata[i].x1
  162.                 + .5*(boxdata[i].x2 - boxdata[i].x1)){
  163.             *more = 1;
  164.          }else{
  165.             *more = 0;
  166.          }
  167.  
  168.          rmax = boxdata[i].y1 + .3333*(boxdata[i].y2 - boxdata[i].y1);
  169.          gmax = boxdata[i].y1 + .6666*(boxdata[i].y2 - boxdata[i].y1);
  170.  
  171.          if(y >= gmax)             *color = R;
  172.          if(y >= rmax && y < gmax) *color = G;
  173.          if(y <  rmax)             *color = B;
  174.       }
  175.    }
  176. }
  177.  
  178.  
  179.