Advertisement
Guest User

ground_place_pattern

a guest
Nov 15th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description ground_place_pattern(ground_grid)
  2. /// @param ground_grid
  3.  
  4. var _grid   = argument0;
  5.  
  6. var _w      = ds_grid_width(_grid);
  7. var _h      = ds_grid_height(_grid);
  8.  
  9. var _brush_circle = 0;
  10. var _brush_square = 1;
  11. var _brush_random = 2;
  12. var _brush_type   = _brush_square;
  13.  
  14. var _num_strokes = 4 * floor(sqrt(_w * _h));
  15. var _n = 0;
  16. var _brush;
  17.  
  18. for(;_n<_num_strokes;++_n){
  19.  
  20.     var _i = irandom(_w);
  21.     var _j = irandom(_h);
  22.                
  23.     var _brush_size = 2;
  24.                
  25.     var _ctr = floor(_brush_size / 2);
  26.            
  27.     var _bx, _by;
  28.            
  29.     for(_bx=0;_bx<_brush_size;++_bx)
  30.         for(_by=0;_by<_brush_size;++_by)
  31.             if(_brush_type == _brush_square)
  32.                 _brush[_bx, _by] = true;
  33.             else if (_brush_type == _brush_circle)
  34.                 _brush[_bx, _by] = point_distance(_ctr,_ctr,_bx,_by) <= (_ctr-1) ? 1 : 0;
  35.             else if (_brush_type == _brush_random)
  36.                 _brush[_bx, _by] = choose(true,false);
  37.            
  38.     // wander
  39.            
  40.     var _iterations = 1 + irandom(3);
  41.     var _t = 0;
  42.            
  43.     for(;_t<_iterations;++_t){
  44.        
  45.         _i += irandom_range(-1,1);
  46.         _j += irandom_range(-1,1);
  47.                
  48.         // place patches according to brush
  49.                
  50.         for(_bx=0;_bx<_brush_size;++_bx){
  51.             for(_by=0;_by<_brush_size;++_by){
  52.                        
  53.                 if(_brush[_bx, _by]){
  54.                        
  55.                     var _x = _i +_bx;
  56.                     var _y = _j +_by;
  57.                                                    
  58.                     if(_x < 0 || _x >= _w
  59.                     || _y < 0 || _y >= _h)
  60.                         continue;
  61.                                
  62.                     _grid[# _x, _y] = 1;
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement