-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathPic.cpp
More file actions
57 lines (51 loc) · 1.17 KB
/
Copy pathMathPic.cpp
File metadata and controls
57 lines (51 loc) · 1.17 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// NOTE: compile with g++ filename.cpp -std=c++11
#include <iostream>
#include <cmath>
#include <cstdlib>
#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 RD(int i, int j)
{
// YOUR CODE HERE
}
unsigned char GR(int i, int j)
{
// YOUR CODE HERE
}
unsigned char BL(int i, int j)
{
// YOUR CODE HERE
}
/*
unsigned char RD(int i,int j){
return (char)(_sq(cos(atan2(j-512,i-512)/2))*255);
}
unsigned char GR(int i,int j){
return (char)(_sq(cos(atan2(j-512,i-512)/2-2*acos(-1)/3))*255);
}
unsigned char BL(int i,int j){
return (char)(_sq(cos(atan2(j-512,i-512)/2+2*acos(-1)/3))*255);
}
*/
FILE *fp;
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);
}
int main()
{
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;
}