wip creating voronoi images for biome generation
This commit is contained in:
parent
a4ad373b79
commit
7aaddaa373
BIN
1563914054.png
Normal file
BIN
1563914054.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
exported wip.xcf
Normal file
BIN
exported wip.xcf
Normal file
Binary file not shown.
@ -1,3 +1,9 @@
|
|||||||
|
size = 500
|
||||||
|
debug = false
|
||||||
|
|
||||||
|
love.load = ->
|
||||||
|
love.window.setMode size, size
|
||||||
|
|
||||||
biomes = {
|
biomes = {
|
||||||
"frozen desert": { 1/3, 0.75, 0.76, 1, h: 0.5, p: 0.12, t: 0 }
|
"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 }
|
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 }
|
-- "dark green": { 0, 0.2, 0, 1, h: 0.5, p: 1, t: 0.5 }
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = {}
|
|
||||||
|
|
||||||
d2 = (A, B) ->
|
d2 = (A, B) ->
|
||||||
dx = A[1] - B[1]
|
dx = A[1] - B[1]
|
||||||
dy = A[2] - B[2]
|
dy = A[2] - B[2]
|
||||||
return dx * dx + dy * dy
|
return dx * dx + dy * dy
|
||||||
|
|
||||||
size = 500
|
colors = {}
|
||||||
|
|
||||||
for h = 1, size
|
for h = 0, size
|
||||||
colors[h] = {}
|
colors[h] = {}
|
||||||
for t = 1, size
|
for t = 0, size
|
||||||
distances = {}
|
distances = {}
|
||||||
for name, biome in pairs biomes
|
for name, biome in pairs biomes
|
||||||
table.insert distances, { d2({biome.h, biome.t}, {h/size, t/size}), name, biome }
|
table.insert distances, { d2({biome.h, biome.t}, {h/size, t/size}), name, biome }
|
||||||
table.sort distances, (A, B) -> return A[1] < B[1]
|
table.sort distances, (A, B) -> return A[1] < B[1]
|
||||||
merge = (A, B, f) ->
|
colors[h][t] = distances[1][3]
|
||||||
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])
|
|
||||||
|
|
||||||
love.draw = ->
|
love.draw = ->
|
||||||
for x = 1, size
|
for x = 1, size
|
||||||
@ -62,8 +48,24 @@ love.draw = ->
|
|||||||
love.graphics.setColor colors[x][y]
|
love.graphics.setColor colors[x][y]
|
||||||
love.graphics.points x, y
|
love.graphics.points x, y
|
||||||
|
|
||||||
love.graphics.setColor 1, 0, 0, 1
|
if debug
|
||||||
for _, bitch in pairs biomes
|
love.graphics.setColor 1, 0, 0, 1
|
||||||
love.graphics.circle "line", bitch.h * size, bitch.t * size, 2
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user