This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xelostar's profile picture

Buffer API

Started by Xelostar, 03 February 2018 - 01:29 PM
Xelostar #1
Posted 03 February 2018 - 02:29 PM
Hello there,
Today I've got my buffer API to how you. It's fairly simple to use:
[media]http://youtu.be/Sv75gGhmrd4[/media]




Code (for copying):
Spoiler

os.loadAPI("/bufferAPI")

local x1, y1 = 1, 1
local x2, y2 = term.getSize()
local buffer = bufferAPI.newBuffer(x1, y1, x2, y2)

--[[
	All handle functions:
	buffer:setBufferSize(x1, y1, x2, y2)
	buffer:clear(color)
	buffer:setPixel(x, y, c1, c2, char)
	buffer:write(x, y, c1, c2, string)
	buffer:loadImage(x, y, image, useBlittle)
	buffer:loadBox(x1, y1, x2, y2, c1, c2, char)
	buffer:loadBorderBox(x1, y1, x2, y2, c1, c2, char)
	buffer:loadBorderBoxBlittle(x1, y1, x2, y2, c1, c2, char)
	buffer:loadLine(x1, y1, x2, y2, c)
	buffer:loadTriangle(x1, y1, x2, y2, x3, y3, c)
	buffer:loadCircle(x, y, c1, c2, char, radius)
	buffer:drawBuffer(blittleOn) -- For drawing the buffer
]]--

function drawScreen()
	-- Load everything into the buffer
	buffer:clear(colors.lime)
	buffer:write(5, 5, colors.blue, colors.white, "This is text.")
	buffer:loadTriangle(8, 6, 4, 15, 20, 12, colors.red)

	-- Draw the buffer
	buffer:drawBuffer(false) -- BlittleOn
end

while true do
	drawScreen()
	-- Do stuff here

	os.queueEvent("FakeEvent")
	os.pullEvent("FakeEvent")
end

Latest download (2.0):
https://pastebin.com/kep0mppq
Or type the following into the CraftOS shell:
pastebin get kep0mppq bufferAPI

Download (1.0):
https://pastebin.com/qU2pf0jy
Or type the following into the CraftOS shell:
pastebin get qU2pf0jy bufferAPI


Let me know if you have any questions.
Edited on 14 July 2018 - 10:49 AM
Jummit #2
Posted 04 February 2018 - 08:53 AM
I always used the window api for buffering, but I guess you have way more control over what is drawn when with this api. You can also use the old terminal without worrying about your buffer window. I think the window api is better in that regard that you can just write a normal program, and put everything the term api draws on a buffer window you created.
Xelostar #3
Posted 04 February 2018 - 09:36 AM
I always used the window api for buffering, but I guess you have way more control over what is drawn when with this api. You can also use the old terminal without worrying about your buffer window. I think the window api is better in that regard that you can just write a normal program, and put everything the term api draws on a buffer window you created.

That is true. I found out about the Window API after having worked on this quite a bit :P/>
Though I'm using this API for my 3D rendering API, because I added the triangle function (which takes quite some time to get right) and I'm pretty happy with that. I just thought I'd share it :)/>