modified biomes generation
This commit is contained in:
parent
ad75946a83
commit
279f7286b6
@ -11,15 +11,10 @@ class World
|
||||
map[x] = {}
|
||||
unless map[x][y]
|
||||
h = @altitude(x, y)
|
||||
-- map[x][y] = { h, h, h, 1 }
|
||||
p = @precipitation(x, y)
|
||||
-- p = math.sqrt(p * (1 - h)) -- correct precipitation according to altitude
|
||||
-- map[x][y] = { 1 - p, 1 - p, 1, 1 }
|
||||
|
||||
t = @temperature(x, y)
|
||||
-- map[x][y] = { t, 0, 0, 1 }
|
||||
t = math.sqrt(t * (1 - h)) -- correct temperature according to altitude
|
||||
-- map[x][y] = { t, h, p, 1 }
|
||||
|
||||
colors = {
|
||||
ocean: { 0, 0, 1, 1 }
|
||||
@ -43,23 +38,54 @@ class World
|
||||
for biome, color in pairs colors
|
||||
table.insert color, biome
|
||||
|
||||
-- biome, probability = "undefined", 0
|
||||
-- for name, fn in pairs biomes
|
||||
-- t = fn(t, h, p)
|
||||
-- if t > probability
|
||||
-- biome = name
|
||||
-- probability = t
|
||||
-- map[x][y] = colors[biome]
|
||||
biomes = {
|
||||
-- "frozen desert": { 1/3, 0.75, 0.76, 1, h: 0.5, p: 0.12, t: 0 }
|
||||
-- swamp: { 65/255, 104/255, 37/255, 1, h: 0.1, p: 1, t: 0.8 }
|
||||
-- -- savanna: { }
|
||||
-- -- shrubland: { }
|
||||
-- "broadleaf forest": { 0.2, 1, 0.2, 1, h: 0.6, p: 0.38, t: 0.4 }
|
||||
-- "evergreen forest": { 0, 0.75, 0, 1, h: 0.75, p: 0.46, t: 0.25 }
|
||||
-- "sandy desert": { 1, 1, 0.2, h: 0.45, p: 0, t: 0.5 }
|
||||
-- "baked desert": { 1, 0.75, 0.2, h: 0.5, p: 0, t: 1 }
|
||||
-- tundra: { 0, 1/3, 2/3, 1, h: 0.5, p: 0, t: 0 }
|
||||
-- -- tiaga: { }
|
||||
-- snow: { 0.9, 0.9, 0.9, 1, h: 0.8, p: 1, t: 0.05 }
|
||||
-- ice: { 0, 0.95, 0.95, 1, h: 1, p: 0.9, t: 0 }
|
||||
-- rainforest: { 0, 1, 0, 1, h: 0.4, p: 1, t: 1 }
|
||||
-- grassland: { 1/3, 1, 0, 1, h: 0.52, p: 0.18, t: 0.5 }
|
||||
"bright green": { 0.2, 1, 0.2, 1, h: 0.5, p: 0, t: 0 }
|
||||
green: { 0, 1, 0, 1, h: 0.5, p: 0, t: 1 }
|
||||
"dark green": { 0, 0.2, 0, 1, h: 0.5, p: 1, t: 0.5 }
|
||||
}
|
||||
d2 = (h, p, t, b) ->
|
||||
dh = h - b.h
|
||||
dp = p - b.p
|
||||
dt = t - b.t
|
||||
return dh^2 + dp^2 + dt^2
|
||||
choices = {}
|
||||
for name, value in pairs biomes
|
||||
table.insert choices, { d2(h, p, t, value), name, value }
|
||||
table.sort choices, (A, B) -> return A[1] < B[1]
|
||||
copy = (t) ->
|
||||
n = {}
|
||||
for k,v in pairs t
|
||||
n[k] = v
|
||||
return n
|
||||
merge = (A, B, f) ->
|
||||
r = math.sqrt A[1]^2 + B[1]^2
|
||||
g = math.sqrt A[2]^2 + B[2]^2
|
||||
b = math.sqrt A[3]^2 + B[3]^2
|
||||
a = math.sqrt (A[4] or 1)^2 + ((B[4] or 1)^2
|
||||
return { r, g, b, a or 1 }
|
||||
map[x][y] = merge choices[1][3], choices[2][3], choices[1][1] - choices[2][1]
|
||||
map[x][y][5] = "#{choices[1][2]}: #{tostring(h)\sub 1, 4}, #{tostring(p)\sub 1, 4}, #{tostring(t)\sub 1, 4}"
|
||||
|
||||
-- temperature is x value
|
||||
-- precipitation is y value (inverted)
|
||||
t = math.min 9, math.floor t * 10
|
||||
p = math.min 9, math.floor p * 10
|
||||
-- print t, p
|
||||
map[x][y] = { biomes\getPixel t, 9 - p }
|
||||
-- t = math.min 9, math.floor t * 10
|
||||
-- p = math.min 9, math.floor p * 10
|
||||
-- map[x][y] = { biomes\getPixel t, 9 - p }
|
||||
|
||||
unless map[x][y]
|
||||
map[x][y] = colors.white
|
||||
map[x][y] = colors.undefined
|
||||
|
||||
return map[x][y]
|
||||
generateSeed: =>
|
||||
|
Loading…
Reference in New Issue
Block a user