Created
February 24, 2016 08:31
-
-
Save zsrinivas/2de320ee635005dec2b9 to your computer and use it in GitHub Desktop.
deadpool
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
#include <bits/stdc++.h> | |
using namespace std; | |
#define DIM 1024 | |
#define _sq(x) ((x) * (x)) // square | |
unsigned char RD(int i, int j) { | |
return (char)(_sq(cos(atan2(j-256, i-256)/2))*255); | |
} | |
FILE *fp; | |
void pixel_write(int i, int j) { | |
static unsigned char color[3]; | |
color[0] = RD(i, j) & 255; | |
color[1] = color[2] = 0; | |
fwrite(color, 1, 3, fp); | |
} | |
int main(void) { | |
fp = fopen("MathPic.ppm", "wb"); | |
fprintf(fp, "P6\n%d %d\n255\n", DIM, DIM); | |
int partsize = DIM / 4; | |
for (int j = 0; j < DIM; ++ j) { | |
for (int i = 0; i < partsize; ++ i) { | |
pixel_write(i, j); | |
} | |
for (int i = partsize - 1; i >= 0; -- i) { | |
pixel_write(i, j); | |
} | |
for (int i = 0; i < partsize; ++ i) { | |
pixel_write(i, j); | |
} | |
for (int i = partsize - 1; i >= 0; -- i) { | |
pixel_write(i, j); | |
} | |
} | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment