Online BASH Compiler

//usr/bin/g++ -x c++ -O3 $0 -lm && ./a.out "$@" ; exit $? // ^...this is executed by bash and compiles the c-source below // // created by flockaroo (florian berger) 2025 // // genuary7 - genuary2025 - "use software not intended to create art or images" // using a shell script with a c++ compiler-shebang #include <stdio.h> #include <math.h> #include <unistd.h> #define VECI(n,i,x) for(int i=0;i<n;i++) {x;} #define VEC(n,x) VECI(n,i,x) #define VEC4(x) VEC(4,x) #define VEC3(x) VEC(3,x) #define VEC2(x) VEC(2,x) #define N_RES 64 #define N_RES_F float(N_RES) float noise[N_RES*N_RES*4]; float fract(float f) { return f-floor(f); } int iclamp(int x, int min, int max) { return (x<min)?min:((x>max)?max:x); } float clamp(float x, float min, float max) { return (x<min)?min:((x>max)?max:x); } int bitinvN(int x, int num) { int r=0,m=1<<(num-1); for(;m>0;x>>=1,m>>=1) r|=m*(x&1); return r; } float bitinv_pat(int x, int y) { return float((15*bitinvN(y,8)+73*bitinvN(x,8))%255)/float(254); } float dot3(float *a, float *b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; } float length3(float *a) { return sqrt(dot3(a,a)); } void normalize3(float *a) { float l=length3(a); VEC3(a[i]/=l); } void ROT2(float *a, float ang) { float b[2],s=sin(ang),c=cos(ang); VEC2(b[i]=a[i]); a[0]=b[0]*c+b[1]*s; a[1]=-b[0]*s+b[1]*c; } void noiselin(float * uv_, float * c) { float uv[2]; VEC2(uv[i]=uv_[i]*N_RES_F); int x=int(floor(uv[0])); int y=int(floor(uv[1])); VEC4(c[i]=0.); for(int j=0; j<4; j++) { float fx=fract(uv[0]); if((j&1)==0) fx=1.-fx; float fy=fract(uv[1]); if((j/2)==0) fy=1.-fy; int idx=(((x+(j&1))&(N_RES-1))+((y+(j/2))&(N_RES-1))*N_RES)*4; VEC4(c[i]+=fx*fy*noise[idx+i]); } } void noiselin3(float * uv3_, float * c) { float uv3[3]; VEC3(uv3[i]=uv3_[i]); float c1[4],c2[4], fr=fract(uv3[2]*N_RES_F), fl=floor(uv3[2]*N_RES_F); uv3[0]+=11./N_RES_F*fl; uv3[1]+=17./N_RES_F*fl; noiselin(uv3,c1); uv3[0]+=11./N_RES_F; uv3[1]+=17./N_RES_F; noiselin(uv3,c2); VEC4(c[i]=c1[i]*(1.-fr)+c2[i]*fr); } float dist(float * p) { float p2[3]; VEC3(p2[i]=p[i]); for( float sc=3.,cnt=1.; sc>.1; sc*=.6,cnt++ ) { float r2[4]; float uv3[3]; VEC3(uv3[i]=p[i]/N_RES_F/sc); ROT2(&uv3[0],cnt); ROT2(&uv3[1],cnt); noiselin3(uv3,r2); float sc3[3]={.7,.7,1.5}; VEC3(p2[i]+=(r2[i]-.5)*sc*sc3[i]*.76); } return p2[2]-(1.2*sin(p[0])+1.2*sin(p[1])); } void getGrad(float * p, float eps, float * g) { float p1[3],p2[3]; VECI( 3, j, VEC3(p1[i]=p[i]); VEC3(p2[i]=p[i]); p1[j]+=eps*.5; p2[j]-=eps*.5; g[j]=(dist(p1)-dist(p2))/eps ); } float img(float x, float y, float H) { float pos[]={0,+x*.006,2.7}; float pos0[3]; VEC3(pos0[i]=pos[i]); float ph=x/H*2.*.2; float th=((y/H)-.5)*.3-.25*.3; float dir[]={cos(ph)*cos(th),sin(ph)*cos(th),sin(th)}; for(int i=0;i<280;i++) { float d=dist(pos); VEC3(pos[i]=pos[i]+dir[i]*d*.35); if(d<.01) break; } float n[]={0,0,0}; float light[]={1,1,1}; normalize3(light); getGrad(pos,.01,n); normalize3(n); float br=clamp((dot3(n,light)),0.,1.); br+=-.2+pos[2]*.15; VEC3(pos0[i]-=pos[i]); br*=exp(-length3(pos0)/40.); if(dist(pos)>1.) br=0.; return br; } char *BR=" .:xX@"; int br2c(float br) { return BR[iclamp(int(br*5.99),0,5)]; } int br2c_ht(float br,int x, int y) { br*=5.99; int bi=int(br); float bfr=br-bi; return BR[iclamp(bi+(bitinv_pat(x,y)+bfr>1.?1:0),0,5)]; } int main(int argc, char *argv[]) { int allnum=N_RES*N_RES*4; for(int i=0;i<allnum;i++) noise[i]=float(rand()&0xFFF)/float(0x1000); int W=79; char str[256]; str[W]=0.; for(int y=0;1;y++) { //for(int y=999800;1;y++) { for(int x=0; x<W; x++) str[x]=br2c_ht(img(y,x,W),x,y); //printf("%s\n",str); printf("%s %d %s\n",str,y,(y==1000000)?"yippie!":""); usleep(10000); } }