Last active
March 14, 2022 02:21
-
-
Save pmalin/5e2906acc4983bdcbf9a7349997fe824 to your computer and use it in GitHub Desktop.
Landscape Effect
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 | |
#define D 2048 | |
F m[D*D],I,O,w,x,y,z,h,u,v,l;int q,i,j,T,M;F&A(int x,int y){return m[(x&(D-1))+(y&(D-1))*D];} | |
F S(F x,F y){I=A(x*D,y*D);return 1-I*I*9;} | |
void L(F& x,F a,F c){x=sqrt(1.-exp(-a*I*(1.-O)-c*O));} | |
#define R ((rand()%98)/49.-1)*l | |
void FX(ImDrawList*d,V a,V b,V B,ImVec4 o,F t){ | |
if(!q){q=1;m[0]=0;l=.5; | |
for(T=D;T>1;l=l/2,T=T/2){M=T/2;for(j=0;j<D;j+=T){for(i=0;i<D;i+=T){w=A(i,j);x=A(i+T,j);y=A(i,j+T);z=A(i+T,j+T); | |
A(i+M,j)=(w+x)/2+R;A(i+M,j+T)=(y+z)/2+R;A(i,j+M)=(w+y)/2+R;A(i+T,j+M)=(x+z)/2+R;A(i+M,j+M)=(w+x+y+z)/4+R;}}}} | |
V s=a,e=b;o.w=1;for(i=64;i--;){s.y=e.y;e.y=a.y+B.y*i/150;d->AddRectFilled(s,e,0xffff6000+i*771);} | |
for(i=0;i<B.x;i++){s.x=e.x=a.x+i;e.y=s.y=b.y;w=(i/B.x)*2-1;h=S(.5,t*.2)-.5; | |
for(j=0;j<400;j++){z=j/400.;z=z*z*500;x=w*z;u=x/300+.5;v=z/300+t*.2;l=S(u,v);y=(l-h)*32;s.y=a.y+B.y*(y/(z+.1)+.25); | |
if(s.y<e.y){I=l-S(u+.01,v+.005)+.01;I=I*(I>0)*30+.2;O=1.0-exp(-z*3e-4);L(o.x,.6,2);L(o.y,.25,4);L(o.z,.15,10);d->AddLine(s,e,ImColor(o));e.y=s.y;}}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, thats so awesome. i love this.