Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- paint.lua - программа рисования
- local colors = require("colors")
- local paint = {
- tools = {"pencil", "line", "rectangle", "fill"},
- currentTool = "pencil",
- color = colors.white,
- bgColor = colors.black
- }
- function paint.run(win, path)
- -- Настройка обработчиков событий
- win:on("click", function(x, y, button)
- if y == 1 then return false end -- Заголовок
- if button == 1 then -- ЛКМ
- if paint.currentTool == "pencil" then
- win.buffer[y][x] = {text = " ", bg = paint.bgColor, fg = paint.color}
- win:renderToScreen()
- end
- end
- return true
- end)
- -- Отрисовка интерфейса
- win.buffer[1][win.width-1] = {text = "×", bg = colors.red, fg = colors.white} -- Кнопка закрытия
- -- Панель инструментов
- for i, tool in ipairs(paint.tools) do
- win.buffer[2][i*2] = {text = tool:sub(1,1), bg = (tool == paint.currentTool) and colors.blue or colors.gray, fg = colors.white}
- end
- -- Область рисования
- for y = 3, win.height - 1 do
- for x = 1, win.width do
- win.buffer[y][x] = {text = " ", bg = colors.black, fg = colors.white}
- end
- end
- win:renderToScreen()
- end
- return paint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement