Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local width, height = 20, 10 -- Size of the drawing grid
- local grid = {}
- for y = 1, height do
- grid[y] = {}
- for x = 1, width do
- grid[y][x] = " " -- Empty cell
- end
- end
- local cursorX, cursorY = 1, 1 -- Starting cursor position
- local function drawGrid()
- term.clear()
- term.setCursorPos(1, 1)
- for y = 1, height do
- for x = 1, width do
- if x == cursorX and y == cursorY then
- term.write("X")
- else
- term.write(grid[y][x])
- end
- end
- print()
- end
- end
- local function saveArt(filename)
- local file = fs.open(filename, "w")
- for y = 1, height do
- file.writeLine(table.concat(grid[y]))
- end
- file.close()
- print("Drawing saved as " .. filename)
- end
- local function loadArt(filename)
- if not fs.exists(filename) then
- print("File not found.")
- return
- end
- local file = fs.open(filename, "r")
- for y = 1, height do
- local line = file.readLine()
- for x = 1, #line do
- grid[y][x] = line:sub(x, x)
- end
- end
- file.close()
- print("Drawing loaded!")
- end
- while true do
- drawGrid()
- print("Controls: WASD to move, Space to draw, C to clear, Save, Load, Exit")
- write("Command: ")
- local input = read()
- if input == "w" and cursorY > 1 then
- cursorY = cursorY - 1
- elseif input == "s" and cursorY < height then
- cursorY = cursorY + 1
- elseif input == "a" and cursorX > 1 then
- cursorX = cursorX - 1
- elseif input == "d" and cursorX < width then
- cursorX = cursorX + 1
- elseif input == " " then
- grid[cursorY][cursorX] = "#"
- elseif input == "c" then
- for y = 1, height do
- for x = 1, width do
- grid[y][x] = " "
- end
- end
- print("Canvas cleared.")
- elseif input == "save" then
- write("Enter filename: ")
- local filename = read()
- saveArt(filename)
- elseif input == "load" then
- write("Enter filename: ")
- local filename = read()
- loadArt(filename)
- elseif input == "exit" then
- break
- else
- print("Unknown command.")
- end
- end
Advertisement
Comments
-
- https://bigwarp.io/7txvvw88j47z
- https://bigwarp.io/37cal9qxtkfd
- https://bigwarp.io/yojwi7en1pvq
- https://bigwarp.io/qijd9p456n3q
- https://bigwarp.io/8q8rweiy8jbr
- https://bigwarp.io/twu7014koab0
- https://bigwarp.io/a52gx3me2yb6
- https://bigwarp.io/vbg8tr63zpg7
- https://bigwarp.io/0buj2xybbiya
- https://bigwarp.io/bpkjblxxvcne
- https://bigwarp.io/2uybz9tn4ylx
- https://bigwarp.io/zgj5po6pvxzi
- https://bigwarp.io/mku1zg635c3p
- https://bigwarp.io/ehrx7oehy8dz
- https://bigwarp.io/sgrz07aqfp65
- https://bigwarp.io/xrhv7lzwf1lg
- https://bigwarp.io/lng31yy8nn5t
- https://bigwarp.io/1m2pzph656py
- https://bigwarp.io/qigrntkn99pb
- https://bigwarp.io/8zndb2n6jiwy
- https://bigwarp.io/8ekzkk952yu3
- https://bigwarp.io/1u99fslfyel0
- https://bigwarp.io/n6cq48ytrt2i
- https://bigwarp.io/u1id0cxubkyb
- https://bigwarp.io/256mpeyeztk7
- https://bigwarp.io/4tj0wc77cwa6
- https://bigwarp.io/smia0be9sl37
- https://bigwarp.io/4ewhxoikf7h5
- https://bigwarp.io/2in30egwonhl
- https://bigwarp.io/tqy9xpjngixh
- https://bigwarp.io/h9xehnci6u8h
- https://bigwarp.io/qwpzfxbpgu4g
- https://bigwarp.io/l3cf70paqezn
- https://bigwarp.io/d0t4fi81l11u
- https://bigwarp.io/0gzjnnvnrtu3
- https://bigwarp.io/aak8g4hw082r
- https://bigwarp.io/if31zbaew096
- https://bigwarp.io/afpl9j47wc3p
- https://bigwarp.io/fphgzk153qxu
- https://bigwarp.io/c16cno5bjc4e
- https://bigwarp.io/x6xtle3ba6u0
- https://bigwarp.io/aav4uxfa6vy4
- https://bigwarp.io/rxzo4cgcquty
- https://bigwarp.io/tga6z9h6iblh
- https://bigwarp.io/mux73oomlrk4
- https://bigwarp.io/ojso2y0iiqla
- https://bigwarp.io/r2x3ww3buw4q
- https://bigwarp.io/43a823em4m6g
Add Comment
Please, Sign In to add comment
Advertisement