Skip to content

Commit

Permalink
PaintExample: Add as new package
Browse files Browse the repository at this point in the history
  • Loading branch information
Panakotta00 committed Sep 6, 2024
1 parent 69e9329 commit 207ff0e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Packages/PainExample/README.adoc
Original file line number Diff line number Diff line change
@@ -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!
4 changes: 4 additions & 0 deletions Packages/PainExample/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Paint Examples"
short_description = "Simple Paint Program Example using GPU T1"
tags = ["example"]
authors = ["Panakotta00"]
55 changes: 55 additions & 0 deletions Packages/PainExample/v0.0.1/EEPROM.lua
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Packages/PainExample/v0.0.1/metadata.toml
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 207ff0e

Please sign in to comment.