SHOW:
|
|
- or go back to the newest paste.
1 | /// @func instance_create_random_grid(width, height, density, deviance, instance) | |
2 | /// @arg0 width width of area | |
3 | /// @arg1 height height of area | |
4 | /// @arg2 density the higher the value the greater the density of the distribution | |
5 | /// @arg3 deviance randomness factor within cell | |
6 | /// @arg4 instance | |
7 | ||
8 | var w = argument0; // Width of grid | |
9 | var h = argument1; // Height of grid | |
10 | var d = argument2; // Density of elements (size of cell) | |
11 | var r = argument3; // Random deviation within cell | |
12 | var i = argument4; // Instance to create | |
13 | var gridw = w / d; // How many cells to create on the x-axis | |
14 | var gridh = h / d; // How many cells to create on the y-axis | |
15 | ||
16 | for (var xx = 0; xx < gridw; xx++) { | |
17 | for (var yy = 0; yy < gridh; yy++) { | |
18 | var cell_posx = d * xx + d / 2; // x-position of cell within grid (centred) | |
19 | var cell_posy = d * yy + d / 2; // y-position of cell within grid (centred) | |
20 | var cell_disx = d * random_range(-r, r); // x-position within cell | |
21 | var cell_disy = d * random_range(-r, r); // y-position within cell | |
22 | instance_create_layer( | |
23 | x + cell_posx + cell_disx, | |
24 | y + cell_posy + cell_disy, | |
25 | "Instances", i) | |
26 | } | |
27 | } |