Advertisement
Guest User

ppm1024(4).cpp

a guest
Aug 2nd, 2014
7,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // NOTE: compile with g++ filename.cpp -std=c++11
  2. //    also, if this doesn't work for you, try the alternate char-based version
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. #define DIM 1024
  7. #define DM1 (DIM-1)
  8. #define _sq(x) ((x)*(x))                           // square
  9. #define _cb(x) abs((x)*(x)*(x))                    // absolute value of cube
  10. #define _cr(x) (unsigned short)(pow((x),1.0/3.0))  // cube root
  11.  
  12. unsigned short GR(int,int);
  13. unsigned short BL(int,int);
  14.  
  15. unsigned short RD(int i,int j){
  16.     // YOUR CODE HERE
  17. }
  18. unsigned short GR(int i,int j){
  19.     // YOUR CODE HERE
  20. }
  21. unsigned short BL(int i,int j){
  22.     // YOUR CODE HERE
  23. }
  24.  
  25. void pixel_write(int,int);
  26. FILE *fp;
  27. int main(){
  28.     fp = fopen("MathPic","wb");
  29.     fprintf(fp, "P6\n%d %d\n1023\n", DIM, DIM);
  30.     for(int j=0;j<DIM;j++)
  31.         for(int i=0;i<DIM;i++)
  32.             pixel_write(i,j);
  33.     fclose(fp);
  34.     return 0;
  35. }
  36. void pixel_write(int i, int j){
  37.     static unsigned short color[3];
  38.     color[0] = RD(i,j)&DM1;
  39.     color[1] = GR(i,j)&DM1;
  40.     color[2] = BL(i,j)&DM1;
  41.     fwrite(color, 2, 3, fp);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement