pastebin - collaborative debugging tool
iljamainz.kpaste.net RSS

Difference between
modified post 80ef9c by Anonymous on Thu 17th Oct 2024 06:42
original post e0bfcc287f by Anonymous on Fri 3rd Feb 2023 10:59
Download diff
Show old version | new version | both versions

    
11
-- test1.lua - simple function plotter in lua
22
-- written by Roland Mainz <roland.mainz@nrubsig.org>
33
44
-- Terminal size
55
TermSize = {w = 376-2, h = 119-2}
66
77
88
function term_clear ()
99
	io.write("\27[2J")
1010
end
1111
1212
function term_cup (x,y)
1313
	io.write(
1414
		string.format("\27[%d;%dH",
1515
			math.floor(y),
1616
			math.floor(x)
1717
			)
1818
		)
1919
end
2020
2121
2222
-- plot a function
2323
-- (assume that domain&&image are in the range [-1,+1])
2424
function plot (f)
2525
	local i
2626
	local x
2727
	local y
2828
2929
	term_clear()
3030
3131
	for i=1, TermSize.w do
3232
		x = (i/TermSize.w)*2 - 1
3333
		y = (f(x) + 1)/2 * TermSize.h
3434
3535
		term_cup(i, y)
3636
		io.write('X')
3737
	end
3838
3939
	-- move cursor to the bottom
4040
	term_cup(1, TermSize.h+1)
4141
end
4242
4343
plot(function (x) return math.sin(x*2*math.pi)*math.sin(x*3*math.pi) end)
4444
4545
-- EOF.
4646
4747

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at