feat(sandbox): add creeper program

This commit is contained in:
Guillaume ARM 2026-06-11 04:33:42 +02:00
parent 8386c165b5
commit fd0a2fd110
3 changed files with 103 additions and 2 deletions

View File

@ -6,7 +6,7 @@
"trapos-net": "0.3.0",
"trapos-ui": "0.2.2",
"trapos-ai": "0.6.4",
"trapos-sandbox": "0.1.2",
"trapos-sandbox": "0.1.3",
"trapos": "0.8.6"
}
}

View File

@ -1,12 +1,13 @@
{
"name": "trapos-sandbox",
"version": "0.1.2",
"version": "0.1.3",
"description": "TrapOS sandbox programs for ccpm experiments and Lua learning",
"dependencies": ["trapos-core"],
"files": [
"apis/libcarre.lua",
"apis/libmcpcomputer.lua",
"programs/carre.lua",
"programs/creeper.lua",
"programs/mcp-computer.lua"
],
"autostart": []

100
programs/creeper.lua Normal file
View File

@ -0,0 +1,100 @@
local createVersion = require('/apis/libversion');
local args = table.pack(...);
local FACE = {
'0000000000000000',
'0000000000000000',
'0011110000111100',
'0011110000111100',
'0011110000111100',
'0011110000111100',
'0000001111000000',
'0000001111000000',
'0000111111110000',
'0000111111110000',
'0000111111110000',
'0000111111110000',
'0000110000110000',
'0000110000110000',
'0000110000110000',
'0000000000000000',
};
local function printUsage()
print('creeper usage:');
print();
print(' creeper');
print(' creeper --version');
print(' creeper --help');
end
local function drawRun(x, y, len, color)
term.setBackgroundColor(color);
term.setCursorPos(x, y);
term.write(string.rep(' ', len));
end
local function drawCreeper()
local width, height = term.getSize();
local pixelW = math.max(1, math.floor(width / 20));
local pixelH = math.max(1, math.floor(height / 18));
if pixelW > 3 then pixelW = 3; end
if pixelH > 2 then pixelH = 2; end
local artW = #FACE[1] * pixelW;
local artH = #FACE * pixelH;
local startX = math.max(1, math.floor((width - artW) / 2) + 1);
local startY = math.max(1, math.floor((height - artH) / 2) + 1);
term.setBackgroundColor(colors.green);
term.setTextColor(colors.white);
term.clear();
for row = 1, #FACE do
for sy = 0, pixelH - 1 do
local y = startY + ((row - 1) * pixelH) + sy;
local col = 1;
while col <= #FACE[row] do
local bit = FACE[row]:sub(col, col);
local run = 1;
while col + run <= #FACE[row]
and FACE[row]:sub(col + run, col + run) == bit do
run = run + 1;
end
local color = colors.green;
if bit == '1' then
color = colors.black;
end
drawRun(startX + ((col - 1) * pixelW), y, run * pixelW, color);
col = col + run;
end
end
end
term.setBackgroundColor(colors.green);
term.setTextColor(colors.white);
term.setCursorPos(1, height);
end
local command = args[1];
if command == '-help' or command == '--help' or command == 'help' then
printUsage();
return;
end
if command == '-version' or command == '--version' or command == 'version' then
print('v' .. createVersion().forSelf());
return;
end
if command ~= nil then
printUsage();
return;
end
drawCreeper();