wip creating voronoi images for biome generation

This commit is contained in:
Tangent 2019-07-24 20:31:44 -07:00
parent a4ad373b79
commit 7aaddaa373
3 changed files with 30 additions and 28 deletions

BIN
1563914054.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
exported wip.xcf Normal file

Binary file not shown.

View File

@ -1,3 +1,9 @@
size = 500
debug = false
love.load = ->
love.window.setMode size, size
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 }
@ -19,42 +25,22 @@ biomes = {
-- "dark green": { 0, 0.2, 0, 1, h: 0.5, p: 1, t: 0.5 }
}
colors = {}
d2 = (A, B) ->
dx = A[1] - B[1]
dy = A[2] - B[2]
return dx * dx + dy * dy
size = 500
colors = {}
for h = 1, size
for h = 0, size
colors[h] = {}
for t = 1, size
for t = 0, size
distances = {}
for name, biome in pairs biomes
table.insert distances, { d2({biome.h, biome.t}, {h/size, t/size}), name, biome }
table.sort distances, (A, B) -> return A[1] < B[1]
merge = (A, B, f) ->
r = math.sqrt (A[1]^2 + B[1]^2) / 2
g = math.sqrt (A[2]^2 + B[2]^2) / 2
b = math.sqrt (A[3]^2 + B[3]^2) / 2
a = math.sqrt ((A[4] or 1)^2 + (B[4] or 1)^2) / 2
return { r, g, b, a }
merge2 = (A, B, f) ->
r = math.sqrt (A[1]^2 + (B[1] * f)^2) / 2
g = math.sqrt (A[2]^2 + (B[2] * f)^2) / 2
b = math.sqrt (A[3]^2 + (B[3] * f)^2) / 2
a = math.sqrt ((A[4] or 1)^2 + ((B[4] or 1) * f)^2) / 2
return { r, g, b, a }
merge3 = (A, B, f) ->
r = math.sqrt (A[1]^2 + B[1]^2 / f) / 2
g = math.sqrt (A[2]^2 + B[2]^2 / f) / 2
b = math.sqrt (A[3]^2 + B[3]^2 / f) / 2
a = math.sqrt ((A[4] or 1)^2 + (B[4] or 1)^2 / f) / 2
return { r, g, b, a }
-- colors[h][t] = distances[1][3]
colors[h][t] = merge3 distances[1][3], distances[2][3], 1 / (distances[2][1] - distances[1][1])
colors[h][t] = distances[1][3]
love.draw = ->
for x = 1, size
@ -62,8 +48,24 @@ love.draw = ->
love.graphics.setColor colors[x][y]
love.graphics.points x, y
love.graphics.setColor 1, 0, 0, 1
for _, bitch in pairs biomes
love.graphics.circle "line", bitch.h * size, bitch.t * size, 2
if debug
love.graphics.setColor 1, 0, 0, 1
for _, bitch in pairs biomes
love.graphics.circle "line", bitch.h * size, bitch.t * size, 2
love.keypressed = (key) -> love.event.quit! if key == "escape"
love.keypressed = (key) ->
love.event.quit! if key == "escape"
if key == 'd'
debug = not debug
if key == 's'
fn = (image_data) ->
file_name = "#{love.filesystem.getSourceBaseDirectory!}/#{os.time!}.png"
file_data = image_data\encode 'png'
str = file_data\getString!
file = io.open file_name, "wb"
file\write str
file\flush!
file\close!
love.graphics.captureScreenshot fn