Created
July 14, 2019 22:40
-
-
Save aleozlx/69f84ac008f4ab22fbbcd6960ca53fa0 to your computer and use it in GitHub Desktop.
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
| // Played with vector fields at https://anvaka.github.io/fieldplay | |
| float phi(float x) { | |
| return 1./(1.+exp(-x)); | |
| } | |
| vec2 get_velocity(vec2 p) { | |
| vec2 v = vec2(0., 0.); | |
| float pi = 3.14159; | |
| float alpha = pi/2.*phi(length(p)-2.*pi)+pi/2.; | |
| if (length(p)<pi) { | |
| alpha = pi/2.*phi(1.6*(pi/2.-length(p)))+pi/2.; | |
| } | |
| else { | |
| alpha = pi/2.*phi(length(p)-2.*pi)+pi/2.; | |
| alpha = - alpha; | |
| } | |
| v.x = cos(alpha)*p.x+sin(alpha)*p.y; | |
| v.y = -sin(alpha)*p.x+cos(alpha)*p.y; | |
| if (length(p)<pi) { | |
| vec2 u = vec2(0., 0.); | |
| u.x = v.x/length(v); | |
| u.y = v.y/length(v); | |
| return u*pi; | |
| } | |
| else { | |
| return v; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment