Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/Escadas1.lua.html
--   http://anggtwu.net/LUA/Escadas1.lua
--          (find-angg "LUA/Escadas1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- Integrais de funções escada.
-- (defun i2 () (interactive) (find-angg "LUA/Indent2.lua"))
-- (defun p3 () (interactive) (find-angg "LUA/Pict3.lua"))
-- (defun e1 () (interactive) (find-angg "LUA/Escadas1.lua"))
-- (defun o  () (interactive) (find-angg "LUA/Pict2e1-1.lua" "FromYs"))
-- Used in:
--   (c2m232p1p 4 "questao-5-grids")
--   (c2m232p1a   "questao-5-grids")
--   (c2m232p1p 9 "questao-5-gab")
--   (c2m232p1a   "questao-5-gab")
-- Supersedes:
--   (find-angg "LUA/Pict2e1-1.lua" "FromYs")

-- «.vmatrix»		(to "vmatrix")
-- «.vmatrix-tests»	(to "vmatrix-tests")
-- «.FromYs»		(to "FromYs")
-- «.FromYs-test-1»	(to "FromYs-test-1")
-- «.FromYs-test-2»	(to "FromYs-test-2")

require "Indent2"     -- (find-angg "LUA/Indent2.lua")
require "Pict3"       -- (find-angg "LUA/Pict3.lua")
require "Piecewise2"  -- (find-angg "LUA/Piecewise2.lua")


-- «vmatrix»  (to ".vmatrix")
Pict.__index.vmatrix = function (p)
    local f = function (o) return Pict {o, "\\\\"} end
    return Pict(map(f, p)):wrapbe("\\begin{matrix}", "\\end{matrix}")
  end

-- «vmatrix-tests»  (to ".vmatrix-tests")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Escadas1.lua"
p = Pict {"a", "b", "c"}
= p:vmatrix()
= p:vmatrix():em()
= p:vmatrix():em():show("")
= p:vmatrix():em():show("", {scale=2})
= Show.log
= Show.bigstr
* (etv)

--]]



--  _____                 __   __   
-- |  ___| __ ___  _ __ __\ \ / /__ 
-- | |_ | '__/ _ \| '_ ` _ \ V / __|
-- |  _|| | | (_) | | | | | | |\__ \
-- |_|  |_|  \___/|_| |_| |_|_||___/
--                                  
-- «FromYs»  (to ".FromYs")
-- Based on: (c2m221p1p 7 "escadas-defs")
--           (c2m221p1a   "escadas-defs")
--           (c2m221p1p 8 "escadas-gab")
--           (c2m221p1a   "escadas-gab")
--           (find-angg "LUA/Pict2e1-1.lua" "FromYs")
--
FromYs = Class {
  type   = "FromYs",
  from   = function (o) return FromYs(o) end,
  fromys = function (ys) return FromYs {ys=ys} end,
  __tostring = function (fry) return mytostringv(fry) end,
  __index = {
    setYs = function (fry)
        fry.Y0 = fry.Y0 or 0
        fry.Ys = HTable {fry.Y0}
        for i,y in ipairs(fry.ys) do
          local lastY = fry.Ys[#fry.Ys]
          table.insert(fry.Ys, lastY+y)
        end
        return fry
      end,
    setranges = function (fry)
        fry.xmax = fry.xmax or #fry.ys
        fry.ymax = fry.ymax or foldl1(max, fry.ys)
        fry.ymin = fry.ymin or foldl1(min, fry.ys)
        fry.Ymax = fry.Ymax or foldl1(max, fry.Ys)
        fry.Ymin = fry.Ymin or foldl1(min, fry.Ys)
        return fry
      end,
    setyspec = function (fry)
        fry.yspec = ""
        local hxfmt = " (%s,%s)c--(%s,%s)o"
        local hx = function (x, y) return format(hxfmt, x-1,y, x,y) end
        for x,y in ipairs(fry.ys) do fry.yspec = fry.yspec .. hx(x, y) end
        return fry
      end,
    setYspec = function (fry)
        local xY = function (x) return format("(%s,%s)", x, fry.Ys[x+1]) end
        fry.Yspec = mapconcat(xY, seq(0, #fry.Ys-1), "--")
        return fry
      end,
    setall = function (fry)
        return fry:setYs():setranges():setyspec():setYspec()
      end,
    --
    pict = function (fry, ymin, ymax, spec)
        PictBounds.setbounds(v(0,ymin), v(fry.xmax,ymax))
        return PwSpec.from(spec):topict():pgat("pgatc")
      end,
    ypict = function (fry) return fry:pict(fry.ymin, fry.ymax, fry.yspec) end,
    Ypict = function (fry) return fry:pict(fry.Ymin, fry.Ymax, fry.Yspec) end,
    ygrid = function (fry) return fry:pict(fry.ymin, fry.ymax, "") end,
    Ygrid = function (fry) return fry:pict(fry.Ymin, fry.Ymax, "") end,
    grid  = function (fry,ymin,ymax) return fry:pict(ymin, ymax, "") end,
  },
}

-- «FromYs-test-1»  (to ".FromYs-test-1")
--[[
* (show2-use "~/LATEX/Show2.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Escadas1.lua"
usepackages.edrx21 = true
fry = FromYs.from {ys={0,1,2,1,0}, Y0=-2}
= fry:setall()
= fry:ypict()
= fry:Ypict()

p = Pict {
  fry:ypict(),
  fry:Ypict(),
  fry:Ygrid(),
  fry:grid(-1, 1)
} :vmatrix()
= p
= p:em():show0("", {scale=0.5})
= p:em():show ("", {scale=0.5})
* (etv)

= Show.log
= Show.bigstr

--]]



-- «FromYs-test-2»  (to ".FromYs-test-2")
--[[
* (show2-use "~/LATEX/Show2.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Escadas1.lua"
usepackages.edrx21 = true
fry = FromYs.from {ys={0,-1,1,-2,2,-3,3,-3,2,-2,1,-1,0},  Y0=-2} :setall()
fry = FromYs.from {ys={0,-1,-3,3,1,0,1,2,1,0,-1,-2,-1,0}, Y0=-2} :setall()
-- = fry:ypict():show("")
-- = fry:Ypict():show("")
** (etv)

p = Pict {
  fry:ypict()   :sa("fig f"),
  fry:Ypict()   :sa("fig F"),
  fry:grid(-4,4):sa("grid F"),
  Pict { "\\ga{fig f}",
         "\\ga{fig F}",
         "\\ga{grid F}",
       } :vmatrix(),
}

= p:show("", {scale=0.3})
* (etv)

--]]





-- Local Variables:
-- coding:  utf-8-unix
-- End: