Change a few things in the island generator (notably : altitude generation, rainfall generation). Fix a few errors in the river drawing algorithm.
This commit is contained in:
parent
9e4f49ab04
commit
43c66e1a3c
|
@ -23,22 +23,55 @@
|
|||
(define cells (island-cells island))
|
||||
(define size (min (2d-array-width cells) (2d-array-height cells)))
|
||||
(define half-size (/ size 2))
|
||||
(define noise-size (floor (/ size 12)))
|
||||
(define noise-size (floor (/ size 15)))
|
||||
(define ns (make-noise 2 noise-size))
|
||||
(define (block i n) (* n (quotient i n)))
|
||||
(define (on-border? i j)
|
||||
(or (< i 5)
|
||||
(< j 5)
|
||||
(< (- (2d-array-width cells) i) 5)
|
||||
(< (- (2d-array-height cells) j) 5)))
|
||||
(2d-array-for-each/indexes
|
||||
(island-cells island)
|
||||
(lambda (cell i j)
|
||||
(set-cell-altitude!
|
||||
cell
|
||||
(* 7
|
||||
(+ -200
|
||||
(* 400 (* (sin (/ (* pi i) size)) (sin (/ (* pi j) size))))
|
||||
(* -100 (+ (expt (- i half-size) 2) (expt (- j half-size) 2)) (/ 2 (* size size)))
|
||||
(* 200 (noise-gradient-value ns i j))
|
||||
(* 25 (noise-value ns (block i 3) (block j 3)))
|
||||
(* 25 (noise-value ns (block i 1) (block j 1)))
|
||||
)))))
|
||||
(cond
|
||||
((on-border? i j) -700)
|
||||
(#t
|
||||
(* 200
|
||||
(+ -7
|
||||
(* 14 (* (sin (/ (* pi i) size)) (sin (/ (* pi j) size))))
|
||||
(* -4 (+ (expt (- i half-size) 2) (expt (- j half-size) 2)) (/ 2 (* size size)))
|
||||
(* 4 (noise-gradient-fractal-value ns 6 0.80 i j))
|
||||
(* 2 (noise-gradient-value ns i j))
|
||||
(* 1 (noise-value ns i j))
|
||||
)))))))
|
||||
; Add a temporary sea biome to remove the inland depressions
|
||||
(2d-array-flood-map!
|
||||
(island-cells island)
|
||||
0 0
|
||||
(lambda (cell)
|
||||
(set-cell-biome! cell 'sea)
|
||||
cell)
|
||||
(lambda (init-cell visited-cell)
|
||||
(and (not (cell-biome visited-cell))
|
||||
(<= (cell-altitude visited-cell) 0)))
|
||||
)
|
||||
; Update the altitude to remove inland depressions
|
||||
(2d-array-for-each
|
||||
(island-cells island)
|
||||
(lambda (cell)
|
||||
(define alt (cell-altitude cell))
|
||||
(when (and (not (eq? (cell-biome cell) 'sea))
|
||||
(> 0 alt))
|
||||
(set-cell-altitude!
|
||||
cell
|
||||
(- 0 alt)))))
|
||||
; Remove the sea biome
|
||||
(2d-array-for-each
|
||||
(island-cells island)
|
||||
(lambda (cell)
|
||||
(set-cell-biome! cell #f)))
|
||||
)
|
||||
|
||||
; Island generation, step 2: erosion pass
|
||||
|
@ -279,7 +312,7 @@
|
|||
pos-queue
|
||||
(cdr pos+wind)))
|
||||
distances-to-sea
|
||||
'(888 1515 2121)
|
||||
'(1919 1313 777)
|
||||
(list
|
||||
(pos+winds dominant-wind width height #t #f #f #t #f) ; M + AO
|
||||
(pos+winds dominant-wind width height #f #t #f #f #t) ; A + O
|
||||
|
@ -296,9 +329,9 @@
|
|||
(+ ret (* weight (max 0 (/ (- max-dist dist) max-dist)))))
|
||||
0
|
||||
dists
|
||||
'(175 75 50)
|
||||
'(75 125 250))
|
||||
(* alt 1/60)
|
||||
'(100 75 75)
|
||||
'(200 140 80))
|
||||
(sqrt (* alt alt 1/100000))
|
||||
(* -50 temp 1/50)
|
||||
)))
|
||||
; Update island
|
||||
|
@ -427,7 +460,7 @@
|
|||
(ni i)
|
||||
(nj j)
|
||||
(next-points+altitude (list)))
|
||||
(when (< 0 iter)
|
||||
(when (and (< 0 iter) (island-is-inside? island ni nj))
|
||||
; set the lake biome on the cell
|
||||
(set-cell-biome! (island-get-cell island ni nj) 'lake)
|
||||
; Reset the river count of the cell
|
||||
|
@ -442,14 +475,15 @@
|
|||
(filter
|
||||
(lambda (x)
|
||||
(and
|
||||
(island-is-inside? island (caar x) (cdar x))
|
||||
(cdr x)
|
||||
(not (eq? 'lake (island-biome island (caar x) (cdar x))))))
|
||||
(map
|
||||
(lambda (x)
|
||||
(define nni (+ ni (car x)))
|
||||
(define nnj (+ nj (cdr x)))
|
||||
(cons (point nni nnj)
|
||||
(island-altitude island nni nnj)))
|
||||
(define nnalt (and (island-is-inside? island nni nnj)
|
||||
(island-altitude island nni nnj)))
|
||||
(cons (point nni nnj) nnalt))
|
||||
river-directions)))
|
||||
(lambda (x y)
|
||||
(< (cdr x) (cdr y)))))
|
||||
|
@ -488,6 +522,26 @@
|
|||
|
||||
; Island generation, step 8: add biomes
|
||||
(define (island-set-biome! island)
|
||||
; Fix lake touching sea by changing them to sea
|
||||
; Change sea to lake
|
||||
(2d-array-flood-map!
|
||||
(island-cells island)
|
||||
0 0
|
||||
(lambda (cell)
|
||||
(set-cell-biome! cell 'lake)
|
||||
cell)
|
||||
(lambda (init-cell visited-cell)
|
||||
(eq? (cell-biome visited-cell) 'sea)))
|
||||
; Change lake to sea
|
||||
(2d-array-flood-map!
|
||||
(island-cells island)
|
||||
0 0
|
||||
(lambda (cell)
|
||||
(set-cell-biome! cell 'sea)
|
||||
cell)
|
||||
(lambda (init-cell visited-cell)
|
||||
(eq? (cell-biome visited-cell) 'lake)))
|
||||
; Compute the other biomes
|
||||
(2d-array-for-each
|
||||
(island-cells island)
|
||||
(lambda (cell)
|
||||
|
@ -564,19 +618,13 @@
|
|||
(displayln "Computation of centers")
|
||||
; random centers
|
||||
(set-island-voronoi-centers! island
|
||||
; Remove points located in sea and lakes
|
||||
(filter
|
||||
(lambda (x)
|
||||
(define biome (island-biome island (car x) (cdr x)))
|
||||
(and (not (eq? 'sea biome))
|
||||
(not (eq? 'lake biome))))
|
||||
; remove identical points
|
||||
(remove-duplicates
|
||||
; build the list: each point is randomly choosen
|
||||
(build-list
|
||||
(ceiling (* width height 1/25)) ; number of points: island-width/25 * island-height/25
|
||||
(lambda (i)
|
||||
(point (random width) (random height))))))))
|
||||
; remove identical points
|
||||
(remove-duplicates
|
||||
; build the list: each point is randomly choosen
|
||||
(build-list
|
||||
(ceiling (* width height 1/25)) ; number of points: island-width/25 * island-height/25
|
||||
(lambda (i)
|
||||
(point (random width) (random height)))))))
|
||||
; relax twice the points : recompute the voronoi centers from each voronoi cell
|
||||
(time
|
||||
(displayln "Relax centers")
|
||||
|
@ -1033,7 +1081,7 @@
|
|||
(define (island-generate size)
|
||||
(define island (make-island size size))
|
||||
(time
|
||||
(displayln "Add Island")
|
||||
(displayln "Add Altitude")
|
||||
(island-set-altitude! island))
|
||||
(time
|
||||
(displayln "Add Erosion")
|
||||
|
|
Loading…
Reference in New Issue