So create some random rectangles with in a circle:

Code: Select all

```
for i in range(0, num_cells):
var xy = get_xy()
var wh = get_wh()
var type = "hall"
if wh.x * wh.y > mean_width * mean_height * 0.9:
type="room"
cells.append({"id": i, "xy": xy, "wh": wh, "topleft": xy, "bottomright": xy + wh, "type":type})
```

Code: Select all

```
func get_xy():
var r = 100 * randf()
var theta = randf() * 2 * PI
var x = r * cos(theta) + 300
var y = r * sin(theta) + 300
return Vector2(x,y)
```

Code: Select all

```
func get_wh():
var w = gaussian(mean_width, width_dev)
var h = gaussian(mean_height, height_dev)
if w < 10 or h < 10: return get_wh()
return Vector2(w,h)
```

Code: Select all

```
while touching:
touching = false
for i in range(0, num_cells):
for j in range(i+1, num_cells):
var a = cells[i]
var b = cells[j]
if touches(a, b):
touching = true
var dx = min(a["bottomright"].x - b["topleft"].x + padding, a["topleft"].x - b["bottomright"].x - padding)
var dy = min(a["bottomright"].y - b["topleft"].y + padding, a["topleft"].y - b["bottomright"].y - padding)
if abs(dx) < abs(dy): dy = 0
else: dx = 0
var dxa = -dx/2
var dxb = dx + dxa
var dya = -dy/2
var dyb = dy+dya
shift_cell(a,Vector2(dxa, dya))
shift_cell(b,Vector2(dxb, dyb))
```