]> git.jsancho.org Git - dungeon-master.git/blobdiff - dungeon-master/generators/town.scm
Voronoi relax (work in progress)
[dungeon-master.git] / dungeon-master / generators / town.scm
index 2f7013a14d0097ccb62b3f9ee811844108e6098e..e8e6d95b73ad6528105b08a3bb63881ddad031d6 100644 (file)
@@ -7,6 +7,7 @@
   (= (random 2) 1))
 
 (define pi 3.141592654)
+(define relax-steps 3)
 
 (define (generate patches)
   "City generator from https://github.com/watabou/TownGeneratorOS/blob/master/Source/com/watabou/towngenerator/building/Model.hx"
@@ -14,7 +15,7 @@
   (when (= patches -1) (set! patches 15))
   (build-patches patches))
 
-(define (build-patches patches)
+(define (build-patches n-patches)
   (define* (get-points n seed #:optional (l '()))
     (cond ((> n 0)
            (let* ((a (+ seed (* (sqrt n) 5)))
           (else
            l)))
 
+  (define (relax voronoi n step)
+    "Relaxing central wards"
+    (cond ((> step 0)
+           (let* ((voronoi-points (voronoi-mesh-points voronoi))
+                  (n-points (length voronoi-points))
+                  (to-relax (cons (list-ref voronoi-points (- n-points n-patches))
+                                  (list-tail voronoi-points (- n-points 3)))))
+             (relax (voronoi-mesh-relax voronoi to-relax) n (- step 1))))
+          (else
+           voronoi)))
+
   (let* ((sa (* (random:exp) 2 pi))
-         (points (get-points (* 8 patches) sa))
-         (voronoi (make-voronoi-mesh points)))
-    (format #t "~a~%~%~a~%" (voronoi-mesh-frame voronoi) (voronoi-mesh-points voronoi))))
+         (points (get-points (* 8 n-patches) sa))
+         (voronoi (relax (make-voronoi-mesh points) n-patches relax-steps)))
+    "end"))