From fd0a2fd110fe3278b5a960cb4672e0733ab7cf44 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Thu, 11 Jun 2026 04:33:42 +0200 Subject: [PATCH] feat(sandbox): add creeper program --- packages/index.json | 2 +- packages/trapos-sandbox/ccpm.json | 3 +- programs/creeper.lua | 100 ++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 programs/creeper.lua diff --git a/packages/index.json b/packages/index.json index 205ce41..cedf7d0 100644 --- a/packages/index.json +++ b/packages/index.json @@ -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" } } diff --git a/packages/trapos-sandbox/ccpm.json b/packages/trapos-sandbox/ccpm.json index 9a7030d..57ee18e 100644 --- a/packages/trapos-sandbox/ccpm.json +++ b/packages/trapos-sandbox/ccpm.json @@ -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": [] diff --git a/programs/creeper.lua b/programs/creeper.lua new file mode 100644 index 0000000..f431840 --- /dev/null +++ b/programs/creeper.lua @@ -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();