Compare commits

...

3 Commits

Author SHA1 Message Date
asciibene
ba95a344d4 Improvements...IIII 2022-04-21 14:19:58 -04:00
asciibene
602c3f947c Improvements...III 2022-04-14 23:43:11 -04:00
asciibene
ae1bb53004 Improvements...II 2022-04-12 21:51:29 -04:00
3 changed files with 178 additions and 70 deletions

View File

@ -1,3 +1,12 @@
# graphed
Paint in your terminal
graphed is a simple tool to create _ascii art_
It is very rudimentary for now...
## Changelog
- Version 0.2
- *WIP*
- Version 0.1
- added file write/load
-

186
main.lua
View File

@ -1,48 +1,21 @@
-- Paint in your terminal
nc = require("nocurses")
dofile("simplefuncs.lua")
-- Misc nc funcs ============================
function printul(s)
nc.setunderline(true)
print(s)
nc.setunderline(false)
end
------------------------------------
-- consts and vars
MSIZE_X=50 -- Map
COLORS={"BLACK","RED","GREEN","YELLOW","BLUE","MAGENTA","CYAN","WHITE"}
MSIZE_X=32 -- Map
MSIZE_Y=24 ---- size
PL_GLYPH="@"
VER=0.034
-- 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
VER=0.10
-- -------------- START FUNC -----------
function start()
nc.setcurshape("BAR")
nc.clrscr()
-- Make X functions
map=mkmat()
mapcolors=mkmat()
p=mkpointer()
nc.clrscr()
-- Now main loop
main()
end
@ -58,71 +31,150 @@ function drawmap()
end
-- XXX draw last info line XXX
nc.gotoxy(0,MSIZE_Y+1)
print(p.x.." . "..p.y.." ")
print("X:"..p.x.." | ".." Y:"..p.y.." ")
if mesg_string~=nil then
nc.gotoxy(1,1)
print(mesg_string)
mesg_string=nil
end
end
function drawmap_fg() -- Draw map foreground
nc.setfontcolor("RED")
nc.gotoxy(p.x,p.y)
print(p.glyph)
nc.setfontcolor("WHITE")
end
----------- main func -----
function main()
-- end drawmap--> main func ---------VVVVVVVVV
function main()
printul("Graphed -- 'Graphical Editor' --")
printcol("http://asciibene.tx0.org/","YELLOW")
printcol("version "..VER,"CYAN")
while exitbool~=true do
if await_cmd()~=0 then
if await_cmd()~=0 then
drawmap()
drawmap_fg()
end
end
end
exit()
end
function exit() -- Exits gracefully
nc.clrscr()
printul("Goodbye...")
end
function mkpointer(pn)
local p
p={}
p.x=5
p.y=5
p.glyph="X"
return p
end
-- END OF MAKE FUNCS ========== MAKE =====
function await_cmd()
local k
k=string.char(nc.getch())
if k=="h" then
if k=="h" and p.x>1 then
movep(-1,0)
elseif k=="j" then
elseif k=="j" and p.y<MSIZE_Y then
movep(0,1)
elseif k=="k" then
elseif k=="k" and p.y>1 then
movep(0,-1)
elseif k=="l" then
movep(1,0)
elseif k=="l" and p.x<MSIZE_X then
movep(1,0)
elseif k=="H" and p.x>3 then
movep(-3,0)
elseif k=="J" and p.y<MSIZE_Y-3 then
movep(0,3)
elseif k=="K" and p.y>3 then
movep(0,-3)
elseif k=="L" and p.x<MSIZE_X-3 then
movep(3,0)
elseif k=="q" then
exitbool=true
elseif k=="t" then
showmesg("This is a test")
mesg_string="This is a test"
elseif k=="c" then
changep()
elseif k=="." then
paint(p.x,p.y,p.glyph)
map[p.x][p.y]=p.glyph
elseif k=="x" then
paint(p.x,p.y," ")
map[p.x][p.y]=" "
elseif k=="w" then
write()
elseif k=="?" then
help()
elseif k=="o" then
-- TODO Set color
-- TODO OPTIONS -----
elseif k=="s" then
changesize()
else
return 0
end
end
function paint(px,py,pg)
map[px][py]=pg
function loadf(fn)
local tbl
fp=io.open(fn,"r")
ftxt={}
i=1
for i=1,MSIZE_Y do
ftxt[i]=io.read("l")
end
-- XXX This func is garbage XXX
-- initialze table
for ix=1,MSIZE_X do
for iy=1,MSIZE_Y do
tbl[ix]={}
tbl[ix][iy]=0
end
end
-- Read file
for ix=1,MSIZE_X do
for iy=1,MSIZE_Y do
end
end
return tbl
end
function help()
nc.clrscr()
nc.setfontcolor("BLUE")
printul("graphed commands")
print("c -> 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 changesize()
nc.clrscr()
print("Enter y size(lines)")
yin=io.read("l")
print("Enter y size(lines)")
xin=io.read("l")
MSIZE_X=tonumber(xin)
MSIZE_Y=tonumber(yin)
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()
mesg_string="Wrote to file : "..fn
end
function movep(dx,dy)
@ -139,11 +191,7 @@ function changep()
p.glyph=c
end
function showmesg(msg)
nc.gotoxy(1,1)
print(msg)
nc.wait()
end
-- -------------------------------------------
-- To write a ephemeral message that gets erased after any input (unlike 'press enter') messages then set 'mesg_string' to any value
-- ------------------------------------------
start()

51
simplefuncs.lua Normal file
View File

@ -0,0 +1,51 @@
-- Simple functions for graphed
function printul(s)
nc.setunderline(true)
print(s)
nc.setunderline(false)
end
function printcol(str,col)
nc.setfontcolor(col)
print(str)
nc.setfontcolor("WHITE")
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