lua で媒介変数方程式をグラフ化する 1

-- lua の中だけで完結する。
-- 参考: http://triode.dip.jp/honkytonk/2014/09/tsuredure/ti-n-spire-cx-cas-lua-1.html
function on.resize()
   W, H = platform.window:width(), platform.window:height()
   X0, Y0 = math.floor(W/2), math.floor(H/2)
   UNIT = math.floor(H/2)
end
function on.paint(gc)
   local FROM, TO = -math.pi, math.pi
   local DT = math.pi/256
   local x1, y1 = Lissajous(FROM)
   for t = (FROM + DT), TO, DT do
      local x2, y2 = Lissajous(t)  
      gc:drawLine(xy2screen(x1, y1, x2, y2, X0, Y0, UNIT))
      x1, y1 = x2, y2         
   end
end

------------------
-- リサジュ函数 --
------------------
function Lissajous(ft)
   return math.sin(5 * ft), math.cos(7 * ft)
end
----------------------------------------------
-- 2 組の xy 座標をスクリーン座標に変換する --
----------------------------------------------
function xy2screen(x1, y1, x2, y2, X0, Y0, UNIT)
   return (X0 + x1 * UNIT), (Y0 - y1 * UNIT), (X0 + x2 * UNIT), (Y0 - y2 * UNIT)
end

f:id:ti-nspire:20160506102205j:plain:w500