Advertisement
Guest User

Untitled

a guest
Dec 30th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. static struct colour rainbow(double x)
  2. {
  3.     double red, green, blue;
  4.     struct colour colour;
  5.  
  6.     red = 4.0 * x - 2.0;
  7.     red = clip(red);
  8.  
  9.     if (x < 0.5)
  10.         green = 4.0 * x;
  11.     else
  12.         green = (-4.0) * x + 4;
  13.     green = clip(green);
  14.  
  15.     blue = (-4.0) * x + 2.0;
  16.     blue = clip(blue);
  17.  
  18.     colour.r = (unsigned char)round(red   * 255.0);
  19.     colour.g = (unsigned char)round(green * 255.0);
  20.     colour.b = (unsigned char)round(blue  * 255.0);
  21.  
  22.     return colour;
  23. }
  24.  
  25. static struct colour heat(double x)
  26. {
  27.     double red, green, blue;
  28.     struct colour colour;
  29.  
  30.     red = sqrt(x);
  31.     red = clip(red);
  32.  
  33.     green = pow(x,3);
  34.     green = clip(green);
  35.  
  36.     blue = 1 - pow(x * 4 - 1, 2);
  37.     blue = clip(blue);
  38.  
  39.     colour.r = (unsigned char)round(red   * 255.0);
  40.     colour.g = (unsigned char)round(green * 255.0);
  41.     colour.b = (unsigned char)round(blue  * 255.0);
  42.  
  43.     return colour;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement