attempt using layered additive colors

This commit is contained in:
Tangent 2019-07-25 13:07:58 -07:00
parent a22acc2220
commit 0839b30015

View File

@ -1,9 +1,6 @@
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 }
@ -33,17 +30,85 @@ d2 = (A, B) ->
colors = {}
for h = 0, size
colors[h] = {}
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]
colors[h][t] = distances[1][3]
merge = (A, B, d) ->
A[4] = A[4] or 1
B[4] = B[4] or 1
c = 1
f = 1 - d
r = math.sqrt ((A[1]*c)^2 + (B[1]*d)^2) / (2 - f)
g = math.sqrt ((A[2]*c)^2 + (B[2]*d)^2) / (2 - f)
b = math.sqrt ((A[3]*c)^2 + (B[3]*d)^2) / (2 - f)
a = math.sqrt ((A[4]*c)^2 + (B[4]*d)^2) / (2 - f)
-- r = math.abs (A[1] + B[1]*d) / (2 - f)
-- g = math.abs (A[2] + B[2]*d) / (2 - f)
-- b = math.abs (A[3] + B[3]*d) / (2 - f)
-- a = math.abs (A[4] + B[4]*d) / (2 - f)
-- r = math.sqrt math.abs(A[1]^2 - B[1]^2)*d + A[1]^2
-- g = math.sqrt math.abs(A[2]^2 - B[2]^2)*d + A[2]^2
-- b = math.sqrt math.abs(A[3]^2 - B[3]^2)*d + A[3]^2
-- a = math.sqrt math.abs(A[4]^2 - B[4]^2)*d + A[4]^2
-- 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]^2 + B[4]^2) / 2
return { r, g, b, a }
love.load = ->
love.window.setMode size, size
for h = 0, size
colors[h] = {}
for t = 0, size
colors[h][t] = { 0, 0, 0, 1 }
max = 0
for name, biome in pairs biomes
for h = 0, size
for t = 0, size
v = 1 - math.sqrt d2({biome.h, biome.t}, {h/size, t/size})
color = colors[h][t]
color[1] += biome[1] * v
color[2] += biome[2] * v
color[3] += biome[3] * v
max = color[1] if color[1] > max
max = color[2] if color[2] > max
max = color[3] if color[3] > max
-- print color[1], color[2], color[3], color[4]
for h = 0, size
for t = 0, size
color = colors[h][t]
color[1] /= max
color[2] /= max
color[3] /= max
if true return
for h = 0, size
colors[h] = {}
for t = 0, size
distances = {} -- format: distance, biome name, biome colors
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]
-- colors[h][t] = distances[1][3]
-- distanceA, distanceB = 28, 99
-- relative distance is B - A (71)
-- ratio = 28/99 = 0.28 mix of B
-- another example, w 30 and 31... 0.91 (way to high..either divide it in half OR...smaller/difference?)
d = distances[1][1] / distances[2][1] --/ 2
colors[h][t] = merge(distances[1][3], distances[2][3], d)
love.draw = ->
for x = 1, size
-- green = size / x
-- yellow = 1 - green
-- yg = math.min green, yellow
-- love.graphics.setColor yellow, yg, 0, 1
for y = 1, size
love.graphics.setColor colors[x][y]
love.graphics.points x, y