Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1.  @r = rand(@Frame * chf("seed"));
  2. v[]@phistory;
  3.  
  4. function vector go_towards(vector @from, @to){
  5.     if(@to.x < @from.x){
  6.         @from.x -= 1;
  7.     }
  8.     if(@to.x > @from.x){
  9.         @from.x += 1;
  10.     }
  11.     if(@to.y < @from.y){
  12.         @from.y -= 1;
  13.     }
  14.     if(@to.y > @from.y){
  15.         @from.y += 1;
  16.     }
  17.     if(@to.z < @from.z){
  18.         @from.z -= 1;
  19.     }
  20.     if(@to.z > @from.z){
  21.         @from.z += 1;
  22.     }
  23.  
  24.     return @from;
  25. }
  26.  
  27. function vector go_random(@P, @phistory){
  28.     @seed = fit(@r,0,1,-1,1);
  29.  
  30.     if(@seed > 0.5 && @seed < 1){
  31.         @P.x += 1;
  32.     }
  33.     if(@seed > 0 && @seed < 0.5){
  34.         @P.x -= 1;
  35.     }
  36.     if(@seed > -0.5 && @seed < 0){
  37.         @P.z += 1;
  38.     }
  39.     if(@seed > -1 && @seed < -0.5){
  40.         @P.z -= 1;
  41.     }
  42.  
  43.     foreach(vector @pos; @phistory) {
  44.         if(@P == @pos)
  45.         {
  46.             if(@r < 0.333) {
  47.                 @P.y += 1;
  48.             }else if (@r > 0.666){
  49.                 @P.y -= 1;
  50.             }
  51.         }
  52.     }
  53.  
  54.     return @P;
  55. }
  56.  
  57. function vector go_home(vector @P){
  58.     vector @o = @phistory[0];
  59.  
  60.     f@dist = distance(@P, @o);
  61.  
  62.     if(@dist > 50.0) {
  63.         @dist = 50.0;
  64.     }
  65.  
  66.     // If the distance is lower than snap, guarantee to go towards the origin
  67.     float @snap = 2.0;
  68.  
  69.     float @thresh = (@dist/100.0) - (@snap/100.0);
  70.  
  71.     // If biased, make the point go towards the origin
  72.     if(@r > @thresh){
  73.         @P = go_towards(@P, @o);
  74.     } else{
  75.         @P = go_random(@P, @seed, @phistory);
  76.     }
  77. }
  78.  
  79. if(@Frame > 100){
  80.     @P = go_home(@P);
  81. }else{
  82.     @P = go_random(@P, @seed, @phistory);
  83. }
  84.  
  85. push(@phistory, @P);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement