// EyeBot Demo Program: Display color, gray, binary -- hue, sat, intensity
#include "eyebot.h"
#define DELTA 100

COLOR Hue2RGB(BYTE hue)
{ BYTE red, green, blue;
  int  g_b, b_r, r_g;
  
  if (hue <= 84) // 2 * 48
  { red = 255;   // MAX
    g_b = (hue-42) * DELTA/42;
    if (g_b > 0)
    { blue  = red - DELTA;
      green = g_b + blue;
    }
    else
    { green = red - DELTA;
      blue  = green - g_b;
    }
  }
  else if (hue <= 168) // 4 * 48
  { green = 255;      // MAX
    b_r = (hue-126) * DELTA/42;
    if (b_r > 0)
    { red  = green - DELTA;
      blue = b_r + red;
    }
    else
    { blue = green - DELTA;
      red  = blue - b_r;
    }  
  }
  else // hue > 168
  { blue = 255;  // MAX
    r_g = (hue-210) * DELTA/42;
    if (r_g > 0)
    { green = blue - DELTA;
      red   = r_g + green;
    }
    else
    { red   = blue - DELTA;
      green = red - r_g;
    }
  }
  return (red<<16) | (green<<8) | blue;  // color from components
  
}

int main()
{ int x,col;

  LCDMenu("", "", "", "END");
  for (x=0; x<256; x++)
  { col = Hue2RGB(x);
    LCDLine(x,0, x,100, col);
  }
  KEYWait(KEY4);
  return 0;
}
