Last active
November 29, 2020 18:46
-
-
Save pmalin/550058583492478beedd7b31ab468174 to your computer and use it in GitHub Desktop.
3D Spinning Glass
This file contains 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
#define V ImVec2 | |
#define F float | |
void R(F&x,F&y,F r){F s=sin(r),c=cos(r),t=c*x-s*y;y=s*x+c*y;x=t;} | |
F c,e,f,g,l,x,y,z; | |
F L(F a){l*=l>0;return sqrt(1-exp(-a*(l+.1)-l*l*l));} | |
void T(F u){R(x,z,c/3+6.28*u);R(x,y,c);R(y,z,c/5);} | |
void FX(ImDrawList*d,V a,V b,V S,ImVec4,F t){ | |
int i,j,k,n=0,u,v,K=7,J=16; | |
char P[]="GZHXITGPBMBCGA",*X=P; | |
struct Q{F d,l;V o[4];}q[99]; | |
V m=(a+b)/2; | |
for(k=K;--k;){X+=2;for(j=J;j--;){ | |
Q&o=q[n++]; | |
o.d=0; | |
for(i=4;i--;){ | |
u=j+(i%3>0);v=-(i/2)*2; | |
x=X[v]-65;y=77-X[v+1];z=0; | |
c=t;T((F)u/J); | |
e=x;f=y; | |
o.d+=z=S.y/(g=z+40); | |
o.o[i]=m+V(x,y)*z; | |
} | |
x=X[1]-X[-1];y=*X-X[-2];z=0; | |
l=sqrt(x*x+y*y); | |
T((j+.5)/J); | |
o.l=((x*e+y*f+z*g)>0?1:-1)*y/l; | |
}} | |
for(i=99;i--;){b.y=a.y;a.y=m.y+9e2/(i+1);d->AddRectFilled(a,b,i>97?0xffffd050:0xff608000+(i/9&1)*64+i*65793);} | |
for(;c=9e9,j=-1;){ | |
for(i=n;i--;){z=q[i].d;if(z>0&z<c){c=z;j=i;}} | |
if(j<0)break; | |
Q&o=q[j];o.d=-1;l=o.l; | |
d->AddConvexPolyFilled(o.o,4,ImColor(L(.1),L(.3),L(1),.8)); | |
d->AddPolyline(o.o,4,~0<<24,1,1); | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment