#include <stdio.h>
#include <stdlib.h>
#include "GrWin.h"

/* 色見本 */

int main()
{
  int i, r, g, b, c;
  float x, y, h, w, xx;
  char s[256];

  GWopen(0);
  GWindow(0.0, 0.0, 700.0, 500.0);
  GWclear(0);

  h=25.0;
  w=60.0;
  x=310; y=420; 

  c=GWkrgb(100,100,100);
  GWsettxt(12, 1.0, 1, c, 0, ""); /* 文字サイズなど */

  x=100; y=400; 
  /* 白、灰、黒（背景色と同じで見えない） */
  r=255; g=255; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=100; g=100; b=100; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=0; b=0; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  /* Red, Gree, Blue の数値を 0 or 255 で組み合わせた発色例 */
  x=100; y-=h*1.8; 
  r=255; g=0; b=0; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=255; g=255; b=0; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=255; b=0;
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=255; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=0; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=255; g=0; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  /* Red, Gree, Blue を最大発色の半分(128)で組み合わせた例 */
  x=100; y-=h*1.8; 
  r=128; g=0; b=0; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=128; g=128; b=0; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=128; b=0;
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=128; b=128; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=0; g=0; b=128; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=128; g=0; b=128; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  /* Red, Gree, Blue を最大発色、かつ白っぽい色で組み合わせた例 */
  x=100; y-=h*1.8; 
  r=255; g=128; b=128; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=255; g=255; b=128; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=128; g=255; b=128;
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=128; g=255; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=128; g=128; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);

  x+=w*1.1;
  r=255; g=128; b=255; 
  c=GWkrgb(r,g,b); GWsrect(x, y, x+w, y+h, c);
  sprintf(s, "%3d,%3d,%3d",r,g,b); GWputtxt(x, y-10, s);
  
  /* なめらかに発色を変更した例 */

  x=50.0; xx=x+256.0;
  y=20.0;
  h=25.0;
  
  for(i=0;i<256;i++) { /* 赤 */
    r=i; g=0; b=0; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=255; g=i; b=i; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 緑 */
    r=0; g=i; b=0; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=i; g=255; b=i; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 青 */
    r=0; g=0; b=i; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=i; g=i; b=255; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 紫 */
    r=i; g=0; b=i; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=255; g=i; b=255; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 水色 */
    r=0; g=i; b=i; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=i; g=255; b=255; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 黄 */
    r=i; g=i; b=0; c=GWkrgb(r, g, b); GWsrect(x+i, y, x+i+1, y+h, c);
    r=255; g=255; b=i; c=GWkrgb(r, g, b); GWsrect(xx+i, y, xx+i+1, y+h, c);
  };
  y+=(h*1.2); 
  for(i=0;i<256;i++) { /* 灰 */
    r=i; g=i; b=i; c=GWkrgb(r, g, b); GWsrect(x+i*2, y, x+i*2+2, y+h, c);
  };

  return 0;
}

