Advertisement
asshousotn

paint

Apr 30th, 2025
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. -- paint.lua - программа рисования
  2. local colors = require("colors")
  3.  
  4. local paint = {
  5.     tools = {"pencil", "line", "rectangle", "fill"},
  6.     currentTool = "pencil",
  7.     color = colors.white,
  8.     bgColor = colors.black
  9. }
  10.  
  11. function paint.run(win, path)
  12.     -- Настройка обработчиков событий
  13.     win:on("click", function(x, y, button)
  14.         if y == 1 then return false end -- Заголовок
  15.        
  16.         if button == 1 then -- ЛКМ
  17.             if paint.currentTool == "pencil" then
  18.                 win.buffer[y][x] = {text = " ", bg = paint.bgColor, fg = paint.color}
  19.                 win:renderToScreen()
  20.             end
  21.         end
  22.         return true
  23.     end)
  24.    
  25.     -- Отрисовка интерфейса
  26.     win.buffer[1][win.width-1] = {text = "×", bg = colors.red, fg = colors.white} -- Кнопка закрытия
  27.    
  28.     -- Панель инструментов
  29.     for i, tool in ipairs(paint.tools) do
  30.         win.buffer[2][i*2] = {text = tool:sub(1,1), bg = (tool == paint.currentTool) and colors.blue or colors.gray, fg = colors.white}
  31.     end
  32.    
  33.     -- Область рисования
  34.     for y = 3, win.height - 1 do
  35.         for x = 1, win.width do
  36.             win.buffer[y][x] = {text = " ", bg = colors.black, fg = colors.white}
  37.         end
  38.     end
  39.    
  40.     win:renderToScreen()
  41. end
  42.  
  43. return paint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement