r/tinycode • u/matigekunst • Jul 28 '22
Patrick Bateman's business card flame fractal in 1337 bytes
#include <stdlib.h>
#include <math.h>//gcc -o c c.c -lm;./c>c.ppm
typedef float f;typedef int d;d R=600,C=1050;
f z(f x,f o){return fmod(fmod(x,o)+o,o);}f o=
1/22.,p=.04,H=.5,V=.25,Z=1.5,e=.07,b=.14;main
(){printf("P6 %i 600 255 ",C);f (*q)[C];q=
malloc(4*R*C);f I[25][6]={{0,-b,b,0,-3,1},{
0,-b,p,0,-2,Z},{e,0,0,b,-3,2},{e,0,0,b,-3,1},
{p,-b,b,p,-1,1},{p,b,-b,p,-H,Z},{p,0,0,b,-1,1
},{b,0,0,b,1,2},{0,-b,b,0,Z,1},{0,-b,b,0,3,1,
o},{0,-b,p,0,4,Z},{e,0,0,b,3,2},{e,0,0,b,3,1}
,{b,p,-p,b,3,1},{0,-b,b,0,5,1},{e,0,0,b,7,2},
{e,0,0,b,7,H},{0,-b,b,0,7,1},{0,-b,b,0,9,1},{
e,-p,e,b,9,Z},{e,b,-e,b,9,1}},J[25][6]={{0,-b
,b,0,-3,1},{e,0,0,b,-3,1},{e,0,0,b,-3,V},{0,-
b,p,0,-2,H},{p,-b,b,p,-1,1},{p,b,-b,p,-H,Z},{
p,0,0,b,-1,1},{b,0,0,b,1,2},{0,-b,b,0,Z,1},{e
,0,0,b,3,2},{e,0,0,b,3,H},{0,-b,b,0,3,1},{p,0
,0,b,3,1},{0,-b,b,0,5,1},{0,-b,b,0,6.5,1},{p,
-b,p,p,6,Z},{p,b,-b,p,5,2},{p,-b,b,p,7,1},{p,
b,-b,p,7.5,Z},{p,0,0,b,7,1},{0,-b,b,0,9,1},{0
,-b,b,0,9.9,1},{p,b,-b,p,9,Z}};d S=22;f t=H,s
=H,Y=H,X=-b,L=R*C;for(d i=2*L;i--;){if(i==L){
o=p;memcpy(&I,&J,R);S=25;Y=0;}f a=(f)rand()/
RAND_MAX;f P=0;for(d z=S;z--;){P+=o;if(a<P){f
G=t*I[z][0]+s*I[z][1]+I[z][4];s=t*I[z][2]+s*
I[z][3]+I[z][5];t=G;break;}}d W=(d)(z((s*b+Y)
,1)*R);d B=(d)(z(1.7-t*e,1)*C);q[W][B]=1;}for
(d x=R;x--;){for(d y=C;y--;){d E=(d)((1-q[x][
y])*255);printf("%c%c%c",E,E,E);}}}
25
Upvotes
4
u/matigekunst Jul 29 '22
The original program was a 7500 byte fractal flame renderer with a lot of features. To golf it to 1337 I had to sacrifice anti-aliasing, log density plotting, random initialisation, gamma correction, fidelity in the font, certain font letter segments (most notably B->b), non-equiprobable transform selection and per transform colour.
The business card is an actual fractal, but it's impossible to see past the first segments. This is due to the resolution (1050Γ600 is the size of a business card) and the removal of anti-aliasing. Other posts of mine show that the text is actually a fractal.
I also cut some corners with the imports. You'll get a lot of warnings during compilation. It may work with other compilers, but to be safe: use gcc 9.4.
4
u/[deleted] Jul 29 '22
Give us a video π³
2
u/_2bt Aug 05 '22
It's a very nice idea! I do see there are plenty of opportunities to golf it down further (like
f z(f x){return x-(d)x;}at which stage the function should likely be inlined). The resulting size might not wound up as such a round number, but perhaps the gained space is enough to add back some of the features you had to strip.I wished the sport of writing business card code would catch on more. It's a compelling format. I can't resist mentioning my own efforts in this category, https://github.com/2bt/bcrt.
4
u/Bisqwit Jul 29 '22
Here is how the result of this program looks like: https://i.imgur.com/RzaZn3g.png (https://imgur.com/a/iX31HNy)
3
u/kubazz Jul 29 '22
Cool, works on arm64 macOS compiled with clang 13. If you get:
just add -Wno-implicit-function-declaration to gcc parameters.
0
u/[deleted] Jul 28 '22
[deleted] β view deleted comment
13
u/[deleted] Jul 28 '22
[removed] β view removed comment