Home

Awesome

<img src="assets/logo.png" alt="logo" width="50"/> PIXELBOX LITE

About

Very fast ComputerCraft library used for rendering graphics with teletext characters (\128-\159)

<img src="assets/charset.png" alt="logo" width="50%"/>

What is this and why do i need it?

Pixelbox lite is a "minimal" library for drawing 2D graphics (color buffers) to the terminal/windows in CC:T.

Its main objective is to be

With pixelbox lite you can technically get 6x more pixels out of your terminal, each character can now be a block of 3x2 pixels

Here you can see the same terminal resolution (default computer: 51x19 chars) being filled with random colors, without and with pixelbox

Installation

Installing is a very simple as its just a singular file

wget https://raw.githubusercontent.com/9551-Dev/pixelbox_lite/master/pixelbox_lite.lua

Modularity

Some info about the modularity of pixelbox can be found here

For a list of modules and info about them you can check out https://github.com/9551-Dev/pixelbox_modules

Basic usage

As for the usage its pretty simple to get started

Heres an example of how that could look

local box = require("pixelbox_lite").new(term.current())

-- blue vertical line
box.canvas[5][5] = colors.blue
box.canvas[6][5] = colors.blue
box.canvas[7][5] = colors.blue

-- disconnect on it
box.canvas[6][6] = colors.blue

-- yellow vertical line
box.canvas[5][7] = colors.yellow
box.canvas[6][7] = colors.yellow
box.canvas[7][7] = colors.yellow

-- display to terminal
box:render()

Heres what this produces

Instead of defining stuff like hand like we did here, how about we use some for loops to make some interesting patterns

local box = require("pixelbox_lite").new(term.current())

local n,m,scale  = 0.9,7.8,30
local full_color = 15/4

for i=0,15 do local c = i/15 term.setPaletteColor(2^i,c,c,c) end

for y=1,box.height do
    for x=1,box.width do
        box.canvas[y][x] = 2^math.floor(((
            math.sin(n*math.pi*x/scale) *
            math.sin(m*math.pi*y/scale) +
            math.sin(m*math.pi*x/scale) *
            math.sin(n*math.pi*y/scale)
        )*full_color)%15)
    end
end

box:render()

os.pullEvent("char")
for i=0,15 do term.setPaletteColor(2^i,term.nativePaletteColor(2^i)) end

Just like this

api functions

Here i will show the functions which are actually under the pixelbox api, to access these you would actually have to make a separate variable for pixelbox like this

local pixelbox = require("pixelbox")
local box = pixelbox.new(term.current())
...

instead of the classic

local box = require("pixelbox").new(term.current())

Values

Methods

data

Here i will tell ya a bunch of useful data you can get from the box object

Values

Methods

Suggested usage:

box:load_module{
    require("pb_modules/module1"),
    require("pb_modules/module2"),
    require("pb_modules/module3"),
    -- ...

    force   = false,
    supress = false,
}

More complex usage

just to show what you can do, i will take previous H example but setup the canvas completely by hand

local pixelbox = require("pixelbox_lite")
local box      = pixelbox.new(term.current())

local bare_canvas   = pixelbox.make_canvas()
local usable_canvas = pixelbox.setup_canvas(box,bare_canvas,colors.black)

-- blue vertical line
usable_canvas[5][5] = colors.blue
usable_canvas[6][5] = colors.blue
usable_canvas[7][5] = colors.blue

-- disconnect on it
usable_canvas[6][6] = colors.blue

-- yellow vertical line
usable_canvas[5][7] = colors.yellow
usable_canvas[6][7] = colors.yellow
usable_canvas[7][7] = colors.yellow

box:set_canvas(usable_canvas)
box:render()

You could also just use an empty table instead of pixelbox.make_canvas but that wont have protection against writing outside of bounds. Thats why i rather recommend passing in a source_table to it


Modules

An example use of the module api:

test.lua

local pixelbox = require("pixelbox_lite")
local box      = pixelbox.new(term.current(),nil,{
    require("test_module"),
    require("test_module_2")
})

box:load_module{
    require("test_module"),
    require("test_module_2"),
    supress = true,
}

for y=1,box.height do
    for x=1,box.width do
        box.canvas[y][x] = 2^math.random(0,15)
    end
end

box.bd.set_box(2,2,9,6,colors.red)
box.bd.set_dot(1,1,3,colors.blue)

box:render()

term.setTextColor(colors.pink)
print(("Box drawer loadstate: %q"):format(box.state.get_box_drawer_loadstate()))

box:throw()

os.pullEvent("char")

test_module.lua

return {init=function(box,module,api,share,api_init)
    return {
        throw=function()
            api.module_error(module,"Oopsie daisy >w<",2)
        end,
        bd={
            set_box=function(x,y,w,h,color)
                for y_iter=y,y+h-1 do
                    for x_iter=x,x+w-1 do
                        box.canvas[y_iter][x_iter] = color
                    end
                end
            end,
            set_dot=function(x,y,diameter,color)
                diameter = diameter - 0.5

                local half_dia = diameter/2 - (diameter/2)%1
                for y_iter=y-half_dia,diameter+y do
                    for x_iter=x-half_dia,diameter+x do
                        box.canvas[y_iter][x_iter] = color
                    end
                end
            end,
            field="teehe"
        }
    },{
        verified_load=function()
            share[module.id] = {init_state=not api_init}
        end
    }
end,id="9551:box_drawer",name="box drawer",author="9551",contact="https://ligma-hotline.uwu",report_msg="\nMrow:3 -> %s"}

test_module_2.lua

return {init=function(box,module,api,share,api_init)
    return {
        state={get_box_drawer_loadstate=function()
            return share["9551:box_drawer"].init_state
        end}
    }
end,id="9551:etc_plg",name=":3",author="9551",contact="https://ligma-hotline.gay",report_msg="\nMeow:3 -> %s"}

Some stuff made with Pixelbox


credit


Meow :3 https://devvie.cc