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)
|
function lerp(x0, x1, t)
|
||||||
return x0*(1-t) + x1*t
|
return x0*(1-t) + x1*t
|
||||||
end
|
end
|
||||||
|
|
||||||
function blendExp(x0, x1, t)
|
function blendExp(x0, x1, t)
|
||||||
|
@ -18,27 +18,27 @@ local coordsAL = {}
|
||||||
local coordsBL = {}
|
local coordsBL = {}
|
||||||
|
|
||||||
local input = {
|
local input = {
|
||||||
0.9013,
|
[0]=0.9013,
|
||||||
1.3685,
|
[60]=1.3685,
|
||||||
1.1046,
|
[120]=1.1046,
|
||||||
1.1633,
|
[180]=1.1633,
|
||||||
0.7332,
|
[240]=0.7332,
|
||||||
0.8603,
|
[300]=0.8603,
|
||||||
|
[360]=0.9013,
|
||||||
}
|
}
|
||||||
|
local xPrecision = 60/20
|
||||||
|
|
||||||
local win = {
|
local win = {
|
||||||
T = 1.5,
|
T = 1.5,
|
||||||
B = -0.5,
|
B = -0.5,
|
||||||
L = 0,
|
L = 0,
|
||||||
R = 1,
|
R = 360,
|
||||||
stepX = 0.1,
|
stepX = 30,
|
||||||
stepY = 0.25,
|
stepY = 0.25,
|
||||||
}
|
}
|
||||||
win.scaleX = 1/(win.L - win.R)
|
win.scaleX = 1/(win.L - win.R)
|
||||||
win.scaleY = 1/(win.T - win.B)
|
win.scaleY = 1/(win.T - win.B)
|
||||||
|
|
||||||
local precision = 32
|
|
||||||
|
|
||||||
function screenX(x)
|
function screenX(x)
|
||||||
return sw*(win.L-x)*win.scaleX
|
return sw*(win.L-x)*win.scaleX
|
||||||
end
|
end
|
||||||
|
@ -52,11 +52,33 @@ function addPoint(coords, x, y)
|
||||||
coords[#coords+1] = screenY(y)
|
coords[#coords+1] = screenY(y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function interpolate(x, values, interpolator)
|
function index(t, x)
|
||||||
local x = (x*#values) % #values
|
if type(x) ~= type(0) then
|
||||||
local x0 = math.floor(x)
|
return nil
|
||||||
local x1 = (x0 + 1) % #values
|
end
|
||||||
return interpolator(values[x0+1], values[x1+1], x - x0)
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
@ -68,19 +90,18 @@ function love.load()
|
||||||
|
|
||||||
--font = love.graphics.newFont("DejaVuSansMono.ttf", fs)
|
--font = love.graphics.newFont("DejaVuSansMono.ttf", fs)
|
||||||
--love.graphics.setFont(font)
|
--love.graphics.setFont(font)
|
||||||
|
setmetatable(input, {__index = index})
|
||||||
|
|
||||||
local lines = #input * precision
|
input.interpolator = lerp
|
||||||
local seg = 1/lines
|
for x=win.L, win.R, xPrecision do
|
||||||
|
local y = input[x]
|
||||||
for n=1, lines+1 do
|
|
||||||
local x = (n-1)*seg
|
|
||||||
local hue = (n-1)/lines
|
|
||||||
|
|
||||||
local y = interpolate(hue, input, lerp)
|
|
||||||
addPoint(coordsA, x, y)
|
addPoint(coordsA, x, y)
|
||||||
addPoint(coordsAL, x, math.log(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(coordsB, x, y)
|
||||||
addPoint(coordsBL, x, math.log(y))
|
addPoint(coordsBL, x, math.log(y))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue