Improvements...II
This commit is contained in:
parent
6fbccc1123
commit
ae1bb53004
@ -1,3 +1,5 @@
|
|||||||
# graphed
|
# graphed
|
||||||
|
|
||||||
Paint in your terminal
|
graphed is a simple tool to create _ascii art_
|
||||||
|
It is very rudimentary for now...
|
||||||
|
|
||||||
|
113
main.lua
113
main.lua
@ -1,46 +1,21 @@
|
|||||||
-- Paint in your terminal
|
-- Paint in your terminal
|
||||||
nc = require("nocurses")
|
nc = require("nocurses")
|
||||||
|
dofile("simplefuncs.lua")
|
||||||
-- Misc nc funcs ============================
|
-- Misc nc funcs ============================
|
||||||
function printul(s)
|
|
||||||
nc.setunderline(true)
|
|
||||||
print(s)
|
|
||||||
nc.setunderline(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
COLORS={"BLACK","RED","GREEN","YELLOW","BLUE","MAGENTA","CYAN","WHITE"}
|
||||||
|
MSIZE_X=32 -- Map
|
||||||
------------------------------------
|
|
||||||
-- consts and vars
|
|
||||||
|
|
||||||
|
|
||||||
MSIZE_X=50 -- Map
|
|
||||||
MSIZE_Y=24 ---- size
|
MSIZE_Y=24 ---- size
|
||||||
PL_GLYPH="@"
|
PL_GLYPH="@"
|
||||||
VER=0.034
|
VER=0.08
|
||||||
-- MAKE Map matrix -------------
|
-- MAKE Map matrix -------------
|
||||||
function mkmat()
|
|
||||||
local mt
|
|
||||||
mt = {} -- create the matrix
|
|
||||||
for i=1,MSIZE_X do
|
|
||||||
mt[i] = {} -- create a new row
|
|
||||||
for j=1,MSIZE_Y do
|
|
||||||
mt[i][j] = " "
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return mt
|
|
||||||
end
|
|
||||||
|
|
||||||
function at(s,p)
|
|
||||||
return string.sub(s,p,p)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- -------------- START FUNC -----------
|
-- -------------- START FUNC -----------
|
||||||
function start()
|
function start()
|
||||||
nc.setcurshape("BAR")
|
nc.setcurshape("BAR")
|
||||||
nc.clrscr()
|
nc.clrscr()
|
||||||
-- Make X functions
|
-- Make X functions
|
||||||
map=mkmat()
|
map=mkmat()
|
||||||
|
mapcolors=mkmat()
|
||||||
p=mkpointer()
|
p=mkpointer()
|
||||||
|
|
||||||
-- Now main loop
|
-- Now main loop
|
||||||
@ -58,71 +33,93 @@ function drawmap()
|
|||||||
end
|
end
|
||||||
-- XXX draw last info line XXX
|
-- XXX draw last info line XXX
|
||||||
nc.gotoxy(0,MSIZE_Y+1)
|
nc.gotoxy(0,MSIZE_Y+1)
|
||||||
print(p.x.." . "..p.y.." ")
|
print("X:"..p.x.." | ".." Y:"..p.y.." ")
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawmap_fg() -- Draw map foreground
|
function drawmap_fg() -- Draw map foreground
|
||||||
|
nc.setfontcolor("RED")
|
||||||
nc.gotoxy(p.x,p.y)
|
nc.gotoxy(p.x,p.y)
|
||||||
print(p.glyph)
|
print(p.glyph)
|
||||||
|
nc.setfontcolor("WHITE")
|
||||||
end
|
end
|
||||||
----------- main func -----
|
----------- main func -----
|
||||||
function main()
|
function main()
|
||||||
|
printul("Graphed")
|
||||||
|
print("version "..VER)
|
||||||
while exitbool~=true do
|
while exitbool~=true do
|
||||||
if await_cmd()~=0 then
|
if await_cmd()~=0 then
|
||||||
drawmap()
|
drawmap()
|
||||||
drawmap_fg()
|
drawmap_fg()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
exit()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function exit() -- Exits gracefully
|
|
||||||
nc.clrscr()
|
nc.clrscr()
|
||||||
printul("Goodbye...")
|
printul("Goodbye...")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mkpointer(pn)
|
|
||||||
local p
|
|
||||||
p={}
|
|
||||||
p.x=5
|
|
||||||
p.y=5
|
|
||||||
p.glyph="X"
|
|
||||||
return p
|
|
||||||
end
|
|
||||||
|
|
||||||
-- END OF MAKE FUNCS ========== MAKE =====
|
-- END OF MAKE FUNCS ========== MAKE =====
|
||||||
function await_cmd()
|
function await_cmd()
|
||||||
local k
|
local k
|
||||||
k=string.char(nc.getch())
|
k=string.char(nc.getch())
|
||||||
if k=="h" then
|
if k=="h" and p.x>1 then
|
||||||
movep(-1,0)
|
movep(-1,0)
|
||||||
elseif k=="j" then
|
elseif k=="j" and p.y<=MSIZE_Y then
|
||||||
movep(0,1)
|
movep(0,1)
|
||||||
elseif k=="k" then
|
elseif k=="k" and p.y>1 then
|
||||||
movep(0,-1)
|
movep(0,-1)
|
||||||
elseif k=="l" then
|
elseif k=="l" and p.x<MSIZE_X then
|
||||||
movep(1,0)
|
movep(1,0)
|
||||||
elseif k=="q" then
|
elseif k=="q" then
|
||||||
exitbool=true
|
exitbool=true
|
||||||
elseif k=="t" then
|
elseif k=="t" then
|
||||||
showmesg("This is a test")
|
showmesg("This is a test")
|
||||||
elseif k=="c" then
|
elseif k=="g" then
|
||||||
changep()
|
changep()
|
||||||
elseif k=="." then
|
elseif k=="." then
|
||||||
paint(p.x,p.y,p.glyph)
|
map[p.x][p.y]=p.glyph
|
||||||
elseif k=="x" then
|
elseif k=="x" then
|
||||||
paint(p.x,p.y," ")
|
map[p.x][p.y]=" "
|
||||||
elseif k=="o" then
|
elseif k=="w" then
|
||||||
-- TODO Set color
|
write()
|
||||||
|
elseif k=="?" then
|
||||||
|
help()
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
-- TODO make load func TODO
|
||||||
|
|
||||||
function paint(px,py,pg)
|
function help()
|
||||||
map[px][py]=pg
|
nc.clrscr()
|
||||||
|
nc.setfontcolor("BLUE")
|
||||||
|
printul("graphed commands")
|
||||||
|
print("g -> change current glyph")
|
||||||
|
print(". -> place current glyph on screen")
|
||||||
|
print("x -> delete glyph under cursor")
|
||||||
|
-- TODO
|
||||||
|
nc.setfontcolor("RED")
|
||||||
|
print("Press enter...")
|
||||||
|
nc.wait()
|
||||||
|
nc.setfontcolor("WHITE")
|
||||||
|
end
|
||||||
|
|
||||||
|
function write()
|
||||||
|
nc.clrscr()
|
||||||
|
print("Enter Filename")
|
||||||
|
fn=io.read("l")
|
||||||
|
fp=io.open(fn,"w+")
|
||||||
|
for i=1,MSIZE_Y do
|
||||||
|
for ii=1,MSIZE_X do
|
||||||
|
cc=map[ii][i]
|
||||||
|
fp:write(cc)
|
||||||
|
end
|
||||||
|
fp:write("\n")
|
||||||
|
end
|
||||||
|
fp:close()
|
||||||
|
nc.clrscr()
|
||||||
|
showmesg("wrote to file:'"..fn.."'. Press enter")
|
||||||
end
|
end
|
||||||
|
|
||||||
function movep(dx,dy)
|
function movep(dx,dy)
|
||||||
@ -139,11 +136,5 @@ function changep()
|
|||||||
p.glyph=c
|
p.glyph=c
|
||||||
end
|
end
|
||||||
|
|
||||||
function showmesg(msg)
|
|
||||||
nc.gotoxy(1,1)
|
|
||||||
print(msg)
|
|
||||||
nc.wait()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
start()
|
start()
|
||||||
|
45
simplefuncs.lua
Normal file
45
simplefuncs.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
-- Simple functions for graphed
|
||||||
|
|
||||||
|
function printul(s)
|
||||||
|
nc.setunderline(true)
|
||||||
|
print(s)
|
||||||
|
nc.setunderline(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
function mkmat()
|
||||||
|
local mt
|
||||||
|
mt = {} -- create the matrix
|
||||||
|
for i=1,MSIZE_X do
|
||||||
|
mt[i] = {} -- create a new row
|
||||||
|
for j=1,MSIZE_Y do
|
||||||
|
mt[i][j] = " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return mt
|
||||||
|
end
|
||||||
|
|
||||||
|
function showmesg(msg)
|
||||||
|
nc.gotoxy(1,1)
|
||||||
|
print(msg)
|
||||||
|
nc.wait()
|
||||||
|
end
|
||||||
|
|
||||||
|
function at(s,p)
|
||||||
|
return string.sub(s,p,p)
|
||||||
|
end
|
||||||
|
|
||||||
|
function mkpointer(pn)
|
||||||
|
local p
|
||||||
|
p={}
|
||||||
|
p.x=5
|
||||||
|
p.y=5
|
||||||
|
p.glyph="X"
|
||||||
|
return p
|
||||||
|
end
|
||||||
|
|
||||||
|
function dispmesg(m)
|
||||||
|
for i=1,150 do
|
||||||
|
nc.gotoxy(1,1)
|
||||||
|
print(m)
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user