2010-11-14

How to Create a Text File List of RGB Values in C

Here is a very simple C program for generating RGB values listed in a text file:



#include <stdio.h>

int main() {

  FILE *fp;
  fp = fopen("true_colour.txt", "w");

  int r = 255;
  int g = 255;
  int b = 255;

  for (r = 255; r >= 0; r--) {
    for (g = 255; g >= 0; g--) {
      for (b = 255; b >= 0; b--) {
        fprintf(fp, "%d", r);
        fprintf(fp, ",");
        fprintf(fp, "%d", g);
        fprintf(fp, ",");
        fprintf(fp, "%d", b);
        fprintf(fp, "\n");
      }
    }
  }

  fclose(fp);
  return 0;

}


C source available at http://gist.github.com/mikequentel/e32acc62b3ae5e330558
Also available in Ada at http://gist.github.com/mikequentel/6bfc40638ca4a789f8e2
and Nim at http://gist.github.com/mikequentel/d74507a6c3738869150b