|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://angg.twu.net/LUA/CabosNaDiagonal.lua.html
-- http://angg.twu.net/LUA/CabosNaDiagonal.lua
-- (find-angg "LUA/CabosNaDiagonal.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- Supersedes: (find-LATEX "2021-2-C3-diag-nums.lua")
-- Superseded by: (find-angg "LUA/Cabos1.lua")
--
-- (defun e () (interactive) (find-angg "LUA/CabosNaDiagonal.lua"))
-- «.barranco» (to "barranco")
CabosNaDiagonal = Class {
type = "CabosNaDiagonal",
from = function (bigstr)
local bigarr = {}
for i,line in ipairs(splitlines(bigstr)) do
local sline = split(line)
if #sline > 0 then table.insert(bigarr, sline) end
end
PPPV(bigarr)
return CabosNaDiagonal { bigstr=bigstr, bigarr=bigarr, n=0 }
end,
__index = {
maxy = function (c) return (#c.bigarr - 1) / 2 end,
maxx = function (c) return (#c.bigarr[1] - 1) / 2 end,
bigget = function (c, x, y)
local a = #c.bigarr - y*2
local b = x*2 + 1
-- print(a, b)
return c.bigarr[a][b]
end,
xyz = function (c, x, y)
return format("%s,%s,%s", x, y, c:bigget(x, y))
end,
vertices = function (c, x, y)
local nw, ne = c:xyz(x, y+1), c:xyz(x+1, y+1)
local sw, se = c:xyz(x, y), c:xyz(x+1, y)
middle = c:bigget(x+0.5, y+0.5)
return nw, ne, sw, se, middle
end,
square = function (c, nw, ne, sw, se)
return format("%s to %s to %s to %s to %s", sw, se, ne, nw, sw)
end,
triangles = function (c, nw, ne, sw, se, middle)
if middle == "/" then
return format("%s to %s to %s to %s", sw, ne, nw, sw),
format("%s to %s to %s to %s", sw, se, ne, sw)
elseif middle == "\\" then
return format("%s to %s to %s to %s", sw, se, nw, sw),
format("%s to %s to %s to %s", se, ne, nw, se)
else PP("bad middle", middle); error()
end
end,
nincr = function (c) c.n = c.n+1; return c.n end,
squareortriangle = function (c, x, y)
local nw, ne, sw, se, middle = c:vertices(x, y)
if middle == "." then
local sq = c:square(nw, ne, sw, se)
return format("set obj %d polygon from %s", c:nincr(), sq)
else
local tri1, tri2 = c:triangles(nw, ne, sw, se, middle)
return format("set obj %d polygon from %s\n", c:nincr(), tri1)
.. format("set obj %d polygon from %s", c:nincr(), tri2)
end
end,
allsots = function (c)
local sots = {}
for y=c:maxy()-1,0,-1 do
for x=0,c:maxx()-1 do
table.insert(sots, c:squareortriangle(x, y))
end
end
return table.concat(sots, "\n")
end,
},
}
bigstr_video = [[
0 - 0 - 0 - 1 - 2 - 3
| . | . | . | . | / |
0 - 0 - 0 - 1 - 2 - 2
| . | . | . | \ | . |
0 - 0 - 0 - 1 - 1 - 1
| . | . | / | . | . |
0 - 0 - 0 - 0 - 0 - 0
| . | . | . | . | . |
0 - 0 - 0 - 0 - 0 - 0
| . | . | . | . | . |
0 - 0 - 0 - 0 - 0 - 0
]]
bigstr_barranco = [[
4 - 4 - 4 - 4 - 4 - 4 - 4 - 4 - 4
| . | . | . | . | . | . | . | . |
4 - 4 - 4 - 4 - 4 - 4 - 4 - 4 - 4
| . | . | . | \ | . | . | . | . |
3 - 3 - 3 - 3 - 4 - 4 - 4 - 4 - 4
| . | . | . | . | \ | . | . | . |
2 - 2 - 2 - 2 - 3 - 4 - 4 - 4 - 4
| . | . | . | . | . | \ | . | . |
1 - 1 - 1 - 1 - 2 - 3 - 4 - 4 - 4
| . | . | . | . | . | . | \ | . |
0 - 0 - 0 - 0 - 1 - 2 - 3 - 4 - 4
| . | . | . | \ | . | . | / | . |
0 - 0 - 0 - 0 - 0 - 1 - 2 - 2 - 2
| . | . | . | . | \ | . | . | . |
0 - 0 - 0 - 0 - 0 - 0 - 1 - 1 - 1
| . | . | . | . | . | \ | . | . |
0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0
]]
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "CabosNaDiagonal.lua"
c = CabosNaDiagonal.from(bigstr_video)
PPPV(c.bigarr)
= c:maxy()
= c:maxx()
= c:bigget(4, 3)
= c:bigget(4, 4)
= c:xyz(4, 4)
= c:vertices(3, 3)
= c:squareortriangle(2, 3)
= c:squareortriangle(3, 3)
= c:allsots()
c.n = 0
= c:allsots()
--]==]
-- «barranco» (to ".barranco")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "CabosNaDiagonal.lua"
c = CabosNaDiagonal.from(bigstr_barranco)
= c:allsots()
--]==]
-- Local Variables:
-- coding: utf-8-unix
-- End: