From 5c6fd80b0c5911f91f6823801875e253115e6fd2 Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Wed, 21 Apr 2021 08:57:32 -0700 Subject: [PATCH] Use term.blit on original paint render This makes it super speedy, meaning an initial refresh doesn't take ages to load. --- patchwork.md | 10 ++++++++++ .../lua/rom/programs/fun/advanced/paint.lua | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/patchwork.md b/patchwork.md index dc29682d5..7729d8500 100644 --- a/patchwork.md +++ b/patchwork.md @@ -325,3 +325,13 @@ d2a1a00dc43e5b65f6b64111ce76dd3db16c919f Clear gets an option to reset the palette (#582) Fixes #555. +``` + +``` +aab0cd34cd64fdf837ff1c3b91a957a25c2cf7f9 + +Use term.blit on original paint render + +This makes it super speedy, meaning an initial refresh doesn't take ages +to load. +``` diff --git a/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/paint.lua b/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/paint.lua index cb9de4153..21934e3c5 100644 --- a/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/paint.lua +++ b/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/paint.lua @@ -233,14 +233,31 @@ local function drawCanvasPixel(x, y) end end +local color_hex_lookup = {} +for i = 0, 15 do + color_hex_lookup[2 ^ i] = string.format("%x", i) +end + --[[ Converts each colour in a single line of the canvas and draws it returns: nil ]] +local text, fg, bg = "", "", "" local function drawCanvasLine(y) for x = 1, w - 2 do - drawCanvasPixel(x, y) + local pixel = getCanvasPixel(x, y) + if pixel then + text = text .. " " + fg = fg .. "0" + bg = bg .. color_hex_lookup[pixel or canvasColour] + else + text = text .. "\127" + fg = fg .. color_hex_lookup[canvasColour] + bg = bg .. color_hex_lookup[colours.grey] + end end + term.setCursorPos(1, y) + term.blit(text, fg, bg) end --[[