Last active
August 20, 2017 05:43
-
-
Save afarah1/05b622183f19733a9aac25b642bfe512 to your computer and use it in GitHub Desktop.
Draws a glider flag
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
/* | |
* ./this width height topRGB bottomRGB [circleSizeDivFactor=4] | |
* ./this 800 600 FFFFFF 000000 | feh - | |
*/ | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define PRINT(c) do { printf("%d %d %d ", c >> 16, c >> 8 & 0xFF, c & 0xFF); } while(0) | |
#define IN_CIRCLE(x, y) ((i - y) * (i - y) + (j - x) * (j - x) <= r*r) | |
int | |
main(int argc, char **argv) | |
{ | |
int factor = 4; | |
if (argc < 5) | |
return 1; | |
if (argc >= 6) | |
factor = atoi(argv[5]); | |
int w = atoi(argv[1]), | |
h = atoi(argv[2]), | |
w3i = w / 3, | |
h3i = h / 3, | |
r = sqrt(w3i * w3i + h3i * h3i) / factor, | |
c01i = h / 6, | |
c01j = w / 2, | |
c12i = h / 2, | |
c12j = w - w / 6, | |
c20i = h - h / 6, | |
c20j = w / 6, | |
c21i = h - h / 6, | |
c21j = w / 2, | |
c22i = h - h / 6, | |
c22j = w - w / 6, | |
color1 = strtol(argv[3], 0, 16), | |
color2 = strtol(argv[4], 0, 16); | |
printf("P3 %d %d 255 ", w, h); | |
for (int i = 0; i < h; i++) { | |
for (int j = 0; j < w; j++) { | |
int z = h - i; | |
if (IN_CIRCLE(c01j, c01i) || | |
(IN_CIRCLE(c20j, c20i) && (z*w) - (j*h) > 0) || | |
((z*w) - (j*h) <= 0 && | |
!IN_CIRCLE(c12j, c12i) && | |
!IN_CIRCLE(c20j, c20i) && | |
!IN_CIRCLE(c21j, c21i) && | |
!IN_CIRCLE(c22j, c22i))) | |
PRINT(color1); | |
else | |
PRINT(color2); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment