Created
May 26, 2015 11:57
-
-
Save byyam/ec36994807f7ec912aea to your computer and use it in GitHub Desktop.
print a graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: compile with g++ filename.cpp -std=c++11 | |
#include <stdio.h> | |
#include <cmath> | |
#include <cstdlib> | |
#include <time.h> | |
#define DIM 1024 | |
#define DM1 (DIM-1) | |
#define _sq(x) ((x)*(x)) // square | |
#define _cb(x) abs((x)*(x)*(x)) // absolute value of cube | |
#define _cr(x) (unsigned char)(pow((x),1.0/3.0)) // cube root | |
unsigned char GR(int,int); | |
unsigned char BL(int,int); | |
unsigned char RD(int i,int j){ | |
return rand(); | |
} | |
unsigned char GR(int i,int j){ | |
return rand(); | |
} | |
unsigned char BL(int i,int j){ | |
return rand(); | |
} | |
void pixel_write(int,int); | |
FILE *fp; | |
int main(){ | |
srand(time(NULL)); | |
fp = fopen("MathPic.ppm","wb"); | |
fprintf(fp, "P6\n%d %d\n255\n", DIM, DIM); | |
for(int j=0;j<DIM;j++) | |
for(int i=0;i<DIM;i++) | |
pixel_write(i,j); | |
fclose(fp); | |
return 0; | |
} | |
void pixel_write(int i, int j){ | |
static unsigned char color[3]; | |
color[0] = RD(i,j)&255; | |
color[1] = GR(i,j)&255; | |
color[2] = BL(i,j)&255; | |
fwrite(color, 1, 3, fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment