- -- test1.lua - simple function plotter in lua
- -- written by Roland Mainz <roland.mainz@nrubsig.org>
- -- Terminal size
- TermSize = {w = 376-2, h = 119-2}
- function term_clear ()
- io.write("\27[2J")
- end
- function term_cup (x,y)
- io.write(
- string.format("\27[%d;%dH",
- math.floor(y),
- math.floor(x)
- )
- )
- end
- -- plot a function
- -- (assume that domain&&image are in the range [-1,+1])
- function plot (f)
- local i
- local x
- local y
- term_clear()
- for i=1, TermSize.w do
- x = (i/TermSize.w)*2 - 1
- y = (f(x) + 1)/2 * TermSize.h
- term_cup(i, y)
- io.write('X')
- end
- -- move cursor to the bottom
- term_cup(1, TermSize.h+1)
- end
- plot(function (x) return math.sin(x*2*math.pi)*math.sin(x*3*math.pi) end)
- -- EOF.
LUA function plotter for sin(x)
Posted by Anonymous on Fri 3rd Feb 2023 10:59
raw | new post
view followups (newest first): LUA function plotter for sin(x) by Anonymous
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.