|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://angg.twu.net/LATEX/2014-1-GA-P2-gab.lua
-- http://angg.twu.net/LATEX/2014-1-GA-P2-gab.lua.html
-- (find-angg "LATEX/2014-1-GA-P2-gab.lua")
-- See: (find-angg "LATEX/2014-1-GA-P2-gab.tex")
--
loadstring = loadstring or load
debug.setmetatable (print, {
__mul = function (f, g) return
function (...) return f(g(...)) end
end,
})
comma = function (a, b) return a..","..b end
pcomma = function (a, b) return "("..a..","..b..")" end
seq = function (a, b, step)
local T = {}
for i=a,b,(step or 1) do table.insert(T, i) end
return T
end
map = function (f, A)
local B = {}
for i=1,#A do table.insert(B, f(A[i])) end
return B
end
seqpath = function(a, b, step, xyfromt)
local values = seq(a, b, step)
local pcoords = map(pcomma*xyfromt, values)
print(table.concat(pcoords, " -- "))
return table.concat(pcoords, " -- ")
end
-- (find-angg "LUA/lua50init.lua" "eval-and-L")
eval = function (str) return assert(loadstring(str))() end
expr = function (str) return eval("return "..str) end
L00 = function (args, body)
return string.format("function (%s) return %s end", args, body)
end
L0 = function (str)
str = str:gsub("^%s*(%S+)%s+->", "%1 ")
local args, body = str:match("^%s*(%S+)%s+(.*)$")
return L00(args, body)
end
L = function (str) return expr(L0(str)) end
xyfromuv = L"u,v 2*u-2*v, 2+u+v" -- (0,2) + u*(2,1) + v*(-2,1)
uvfromxy = L"x,y x/4+y/2-1, -x/4+y/2-1"
cos = math.cos
sin = math.sin
xyfromh = function (t) return xyfromuv(t, 1/t) end
xyfromp = function (t) return xyfromuv(t, t*t) end
xyfrome = function (t) return xyfromuv(cos(t), sin(t)) end
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "2014-1-GA-P2-gab.lua"
= uvfromxy(0, 2)
= uvfromxy(2, 3)
= uvfromxy(-2, 3)
= xyfromuv(uvfromxy(0, 2))
= xyfromuv(uvfromxy(2, 3))
= xyfromuv(uvfromxy(-2, 3))
xyfromt = L"u,v u+v,u-v" * L"t t,1/t"
= xyfromt(10)
= seqpath(1, 2, 0.125, xyfromt)
--]]
-- Local Variables:
-- coding: raw-text-unix
-- End: