Advertisement
yeeeeeeeeeeeee

Yeeet OS Part 2

Mar 24th, 2025
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. local width, height = 20, 10 -- Size of the drawing grid
  2. local grid = {}
  3. for y = 1, height do
  4.     grid[y] = {}
  5.     for x = 1, width do
  6.         grid[y][x] = " " -- Empty cell
  7.     end
  8. end
  9. local cursorX, cursorY = 1, 1 -- Starting cursor position
  10.  
  11. local function drawGrid()
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     for y = 1, height do
  15.         for x = 1, width do
  16.             if x == cursorX and y == cursorY then
  17.                 term.write("X")
  18.             else
  19.                 term.write(grid[y][x])
  20.             end
  21.         end
  22.         print()
  23.     end
  24. end
  25.  
  26. local function saveArt(filename)
  27.     local file = fs.open(filename, "w")
  28.     for y = 1, height do
  29.         file.writeLine(table.concat(grid[y]))
  30.     end
  31.     file.close()
  32.     print("Drawing saved as " .. filename)
  33. end
  34.  
  35. local function loadArt(filename)
  36.     if not fs.exists(filename) then
  37.         print("File not found.")
  38.         return
  39.     end
  40.     local file = fs.open(filename, "r")
  41.     for y = 1, height do
  42.         local line = file.readLine()
  43.         for x = 1, #line do
  44.             grid[y][x] = line:sub(x, x)
  45.         end
  46.     end
  47.     file.close()
  48.     print("Drawing loaded!")
  49. end
  50.  
  51. while true do
  52.     drawGrid()
  53.     print("Controls: WASD to move, Space to draw, C to clear, Save, Load, Exit")
  54.     write("Command: ")
  55.     local input = read()
  56.     if input == "w" and cursorY > 1 then
  57.         cursorY = cursorY - 1
  58.     elseif input == "s" and cursorY < height then
  59.         cursorY = cursorY + 1
  60.     elseif input == "a" and cursorX > 1 then
  61.         cursorX = cursorX - 1
  62.     elseif input == "d" and cursorX < width then
  63.         cursorX = cursorX + 1
  64.     elseif input == " " then
  65.         grid[cursorY][cursorX] = "#"
  66.     elseif input == "c" then
  67.         for y = 1, height do
  68.             for x = 1, width do
  69.                 grid[y][x] = " "
  70.             end
  71.         end
  72.         print("Canvas cleared.")
  73.     elseif input == "save" then
  74.         write("Enter filename: ")
  75.         local filename = read()
  76.         saveArt(filename)
  77.     elseif input == "load" then
  78.         write("Enter filename: ")
  79.         local filename = read()
  80.         loadArt(filename)
  81.     elseif input == "exit" then
  82.         break
  83.     else
  84.         print("Unknown command.")
  85.     end
  86. end
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement