1 (define-module (dungeon-master generators town)
2 #:use-module (dungeon-master geom voronoi)
3 #:use-module (dungeon-master geom point)
9 (define pi 3.141592654)
10 (define relax-steps 3)
12 (define (generate patches)
13 "City generator from https://github.com/watabou/TownGeneratorOS/blob/master/Source/com/watabou/towngenerator/building/Model.hx"
14 (set! *random-state* (random-state-from-platform))
15 (when (= patches -1) (set! patches 15))
16 (build-patches patches))
18 (define (build-patches n-patches)
19 (define* (get-points n seed #:optional (l '()))
21 (let* ((a (+ seed (* (sqrt n) 5)))
24 (+ 10 (* n (+ 2 (random:exp))))))
28 (get-points (- n 1) seed (cons point l))))
32 (define (relax voronoi n step)
33 "Relaxing central wards"
35 (let* ((voronoi-points (voronoi-mesh-points voronoi))
36 (n-points (length voronoi-points))
37 (to-relax (cons (list-ref voronoi-points (- n-points n-patches))
38 (list-tail voronoi-points (- n-points 3)))))
39 (relax (voronoi-mesh-relax voronoi to-relax) n (- step 1))))
43 (let* ((sa (* (random:exp) 2 pi))
44 (points (get-points (* 8 n-patches) sa))
45 (voronoi (relax (make-voronoi-mesh points) n-patches relax-steps)))