From 207ff0e7b7d36895a92877aa2c01896d69b2126f Mon Sep 17 00:00:00 2001 From: Panakotta00 Date: Fri, 6 Sep 2024 19:27:23 +0200 Subject: [PATCH] PaintExample: Add as new package --- Packages/PainExample/README.adoc | 8 ++++ Packages/PainExample/metadata.toml | 4 ++ Packages/PainExample/v0.0.1/EEPROM.lua | 55 +++++++++++++++++++++++ Packages/PainExample/v0.0.1/metadata.toml | 6 +++ 4 files changed, 73 insertions(+) create mode 100644 Packages/PainExample/README.adoc create mode 100644 Packages/PainExample/metadata.toml create mode 100644 Packages/PainExample/v0.0.1/EEPROM.lua create mode 100644 Packages/PainExample/v0.0.1/metadata.toml diff --git a/Packages/PainExample/README.adoc b/Packages/PainExample/README.adoc new file mode 100644 index 0000000..c0ec0a7 --- /dev/null +++ b/Packages/PainExample/README.adoc @@ -0,0 +1,8 @@ += Paint Example + +This is a simple example showing how you can use the GPU T1. + +It gets any GPU and any Screen (built-in or via network), +then it clears the screen and adds at the bottom a row of colors you can choose from. + +You can then use your cursor to click on such color and start painting on the screen! diff --git a/Packages/PainExample/metadata.toml b/Packages/PainExample/metadata.toml new file mode 100644 index 0000000..35312a1 --- /dev/null +++ b/Packages/PainExample/metadata.toml @@ -0,0 +1,4 @@ +name = "Paint Examples" +short_description = "Simple Paint Program Example using GPU T1" +tags = ["example"] +authors = ["Panakotta00"] diff --git a/Packages/PainExample/v0.0.1/EEPROM.lua b/Packages/PainExample/v0.0.1/EEPROM.lua new file mode 100644 index 0000000..11383af --- /dev/null +++ b/Packages/PainExample/v0.0.1/EEPROM.lua @@ -0,0 +1,55 @@ +-- get first T1 GPU avialable from PCI-Interface +local gpu = computer.getPCIDevices(classes.GPUT1)[1] +if not gpu then + error("No GPU T1 found!") +end + +-- get first Screen-Driver available from PCI-Interface +local screen = computer.getPCIDevices(classes.FINComputerScreen)[1] +-- if no screen found, try to find large screen from component network +if not screen then + local comp = component.findComponent(classes.Screen)[1] + if not comp then + error("No Screen found!") + end + screen = component.proxy(comp) +end + +-- setup gpu +event.listen(gpu) +gpu:bindScreen(screen) +w, h = gpu:getSize() + +-- clear background +gpu:setBackground(0,0,0,0) +gpu:fill(0, 0, w, h, " ", " ") + +-- setup color palette +colors = {{0,0,0,0},{0,0,0,0},{1,0,0,1},{1,0,0,1},{0,1,0,1},{0,1,0,1},{0,0,1,1},{0,0,1,1},{1,1,1,1},{1,1,1,1}} + +-- draw color palette +for i, color in ipairs(colors) do + gpu:setBackground(color[1], color[2], color[3], color[4]) + gpu:setText(i - 1, h - 1, " ") +end + +gpu:setBackground(1,1,1,1) + +-- draw loop +isDown = false +while true do + e, s, x, y = event.pull() + if e == "OnMouseDown" then + isDown = true + -- is press on color palette, select color + if y == h - 1 and x < #colors then + color = colors[x + 1] + gpu:setBackground(color[1], color[2], color[3], color[4]) + end + elseif e == "OnMouseUp" then + isDown = false + elseif e == "OnMouseMove" and not (y == h - 1 and x < #colors) and isDown then + gpu:setText(x, y, " ") + end + gpu:flush() +end diff --git a/Packages/PainExample/v0.0.1/metadata.toml b/Packages/PainExample/v0.0.1/metadata.toml new file mode 100644 index 0000000..155c2dd --- /dev/null +++ b/Packages/PainExample/v0.0.1/metadata.toml @@ -0,0 +1,6 @@ +fin_version = ">= 0.3.20" + +[[EEPROM]] +name = "EEPROM.lua" +title = "EEPROM" +description = "The example program you have to put into your EEPROM."