Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description ground_place_pattern(ground_grid)
- /// @param ground_grid
- var _grid = argument0;
- var _w = ds_grid_width(_grid);
- var _h = ds_grid_height(_grid);
- var _brush_circle = 0;
- var _brush_square = 1;
- var _brush_random = 2;
- var _brush_type = _brush_square;
- var _num_strokes = 4 * floor(sqrt(_w * _h));
- var _n = 0;
- var _brush;
- for(;_n<_num_strokes;++_n){
- var _i = irandom(_w);
- var _j = irandom(_h);
- var _brush_size = 2;
- var _ctr = floor(_brush_size / 2);
- var _bx, _by;
- for(_bx=0;_bx<_brush_size;++_bx)
- for(_by=0;_by<_brush_size;++_by)
- if(_brush_type == _brush_square)
- _brush[_bx, _by] = true;
- else if (_brush_type == _brush_circle)
- _brush[_bx, _by] = point_distance(_ctr,_ctr,_bx,_by) <= (_ctr-1) ? 1 : 0;
- else if (_brush_type == _brush_random)
- _brush[_bx, _by] = choose(true,false);
- // wander
- var _iterations = 1 + irandom(3);
- var _t = 0;
- for(;_t<_iterations;++_t){
- _i += irandom_range(-1,1);
- _j += irandom_range(-1,1);
- // place patches according to brush
- for(_bx=0;_bx<_brush_size;++_bx){
- for(_by=0;_by<_brush_size;++_by){
- if(_brush[_bx, _by]){
- var _x = _i +_bx;
- var _y = _j +_by;
- if(_x < 0 || _x >= _w
- || _y < 0 || _y >= _h)
- continue;
- _grid[# _x, _y] = 1;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement