077b12f1039dceb830c2b83be8dcbd1b

This code show how is possible to generate an image PPM.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <sys/types.h>

int main()  
{
  const int width=800, height=600;
  FILE *fp=NULL;
  int i,j;
  u_char col[3];

  // open binary file
  fp = fopen("output.ppm","wb");

  // print header
  fprintf (fp,"P6\n%d %d\n255\n",width,height);
 
  // create image values
  for (i=0; i<width; i++)
    for (j=0; j<width; j++)  {
      col[0] = (u_char) i-j;
      col[1] = (u_char) j-i;
      col[2] = (u_char) i+j;
      fwrite (col,3,1,fp);
    }
 
  // close file
  fclose(fp);

  return 0;
}

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel