View difference between Paste ID: 12quxkA9 and jaV8uTR9
SHOW: | | - or go back to the newest paste.
1
// NOTE: compile with g++ filename.cpp -std=c++11
2
3
#include <iostream>
4
#include <cmath>
5
#define DIM 1024
6
#define DM1 (DIM-1)
7
#define _sq(x) ((x)*(x))                           // square
8
#define _cb(x) abs((x)*(x)*(x))                    // absolute value of cube
9
#define _cr(x) (unsigned char)(pow((x),1.0/3.0))   // cube root
10
11-
unsigned char green_fn(int,int);
11+
unsigned char GR(int,int);
12-
unsigned char blue_fn(int,int);
12+
unsigned char BL(int,int);
13
14-
unsigned char red_fn(int i,int j){
14+
unsigned char RD(int i,int j){
15
    // YOUR CODE HERE
16
}
17-
unsigned char green_fn(int i,int j){
17+
unsigned char GR(int i,int j){
18
    // YOUR CODE HERE
19
}
20-
unsigned char blue_fn(int i,int j){
20+
unsigned char BL(int i,int j){
21
    // YOUR CODE HERE
22
}
23
 
24
void pixel_write(int,int);
25
FILE *fp;
26
int main(){
27
    fp = fopen("MathPic","wb");
28
    fprintf(fp, "P6\n%d %d\n255\n", DIM, DIM);
29
    for(int j=0;j<DIM;j++)
30
        for(int i=0;i<DIM;i++)
31
            pixel_write(i,j);
32
    fclose(fp);
33
    return 0;
34
}
35
void pixel_write(int i, int j){
36
    static unsigned char color[3];
37-
    color[0] =   red_fn(i,j)&255;
37+
    color[0] = RD(i,j)&255;
38-
    color[1] = green_fn(i,j)&255;
38+
    color[1] = GR(i,j)&255;
39-
    color[2] =  blue_fn(i,j)&255;
39+
    color[2] = BL(i,j)&255;
40
    fwrite(color, 1, 3, fp);
41
}