Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Created February 24, 2016 08:31
Show Gist options
  • Save zsrinivas/2de320ee635005dec2b9 to your computer and use it in GitHub Desktop.
Save zsrinivas/2de320ee635005dec2b9 to your computer and use it in GitHub Desktop.
deadpool
#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