This commit is contained in:
parent
5456e17c8b
commit
39c1899843
1 changed files with 46 additions and 25 deletions
71
main.lua
71
main.lua
|
@ -1,5 +1,5 @@
|
|||
function lerp(x0, x1, t)
|
||||
return x0*(1-t) + x1*t
|
||||
return x0*(1-t) + x1*t
|
||||
end
|
||||
|
||||
function blendExp(x0, x1, t)
|
||||
|
@ -18,27 +18,27 @@ local coordsAL = {}
|
|||
local coordsBL = {}
|
||||
|
||||
local input = {
|
||||
0.9013,
|
||||
1.3685,
|
||||
1.1046,
|
||||
1.1633,
|
||||
0.7332,
|
||||
0.8603,
|
||||
[0]=0.9013,
|
||||
[60]=1.3685,
|
||||
[120]=1.1046,
|
||||
[180]=1.1633,
|
||||
[240]=0.7332,
|
||||
[300]=0.8603,
|
||||
[360]=0.9013,
|
||||
}
|
||||
local xPrecision = 60/20
|
||||
|
||||
local win = {
|
||||
T = 1.5,
|
||||
B = -0.5,
|
||||
L = 0,
|
||||
R = 1,
|
||||
stepX = 0.1,
|
||||
R = 360,
|
||||
stepX = 30,
|
||||
stepY = 0.25,
|
||||
}
|
||||
win.scaleX = 1/(win.L - win.R)
|
||||
win.scaleY = 1/(win.T - win.B)
|
||||
|
||||
local precision = 32
|
||||
|
||||
function screenX(x)
|
||||
return sw*(win.L-x)*win.scaleX
|
||||
end
|
||||
|
@ -52,11 +52,33 @@ function addPoint(coords, x, y)
|
|||
coords[#coords+1] = screenY(y)
|
||||
end
|
||||
|
||||
function interpolate(x, values, interpolator)
|
||||
local x = (x*#values) % #values
|
||||
local x0 = math.floor(x)
|
||||
local x1 = (x0 + 1) % #values
|
||||
return interpolator(values[x0+1], values[x1+1], x - x0)
|
||||
function index(t, x)
|
||||
if type(x) ~= type(0) then
|
||||
return nil
|
||||
end
|
||||
|
||||
local x0
|
||||
local x1
|
||||
for tx, ty in pairs(t) do
|
||||
-- we can't guarantee the order the key/values come in
|
||||
if tx ~= "interpolator" then
|
||||
-- x0 = largest tx that doesn't go over x
|
||||
if tx <= x and (x0 == nil or tx > x0) then
|
||||
x0 = tx
|
||||
end
|
||||
-- x1 = smallest tx that doesn't go under x
|
||||
if tx > x and (x1 == nil or tx < x1) then
|
||||
x1 = tx
|
||||
end
|
||||
end
|
||||
end
|
||||
x1 = x1 or x0
|
||||
|
||||
local y0 = rawget(t, x0)
|
||||
local y1 = rawget(t, x1)
|
||||
local f = rawget(t, "interpolator")
|
||||
local y = f(y0, y1, (x - x0)/(x1 - x0))
|
||||
return y
|
||||
end
|
||||
|
||||
function love.load()
|
||||
|
@ -68,19 +90,18 @@ function love.load()
|
|||
|
||||
--font = love.graphics.newFont("DejaVuSansMono.ttf", fs)
|
||||
--love.graphics.setFont(font)
|
||||
setmetatable(input, {__index = index})
|
||||
|
||||
local lines = #input * precision
|
||||
local seg = 1/lines
|
||||
|
||||
for n=1, lines+1 do
|
||||
local x = (n-1)*seg
|
||||
local hue = (n-1)/lines
|
||||
|
||||
local y = interpolate(hue, input, lerp)
|
||||
input.interpolator = lerp
|
||||
for x=win.L, win.R, xPrecision do
|
||||
local y = input[x]
|
||||
addPoint(coordsA, x, y)
|
||||
addPoint(coordsAL, x, math.log(y))
|
||||
end
|
||||
|
||||
y = interpolate(hue, input, blendExp)
|
||||
input.interpolator = blendExp
|
||||
for x=win.L, win.R, xPrecision do
|
||||
local y = input[x]
|
||||
addPoint(coordsB, x, y)
|
||||
addPoint(coordsBL, x, math.log(y))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue