This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Exerro's profile picture

Sketch-it paint program

Started by Exerro, 28 September 2012 - 05:15 PM
Exerro #1
Posted 28 September 2012 - 07:15 PM
Sketch-it


I made a program a while ago and decided to make it a whole lot better…

Current features:
v-1.0.2
-Ability to draw any ascii key character
-Ability to remove any drawing on the screen
-Ability to draw a box using draw box tool (point to point drawing and realtime graphics)
-Ability to fill in a box area with a certain character
-Ability to save, open, and create new projects
-(Saves files in .skt format)
-Keyboard shortcuts to move cursor
-Friendly graphics
-Easy to use interface
-Optimized for typing
v-1.0.3 (coming soon)-
-All previous features and
-Select tool added
—Move parts of screen around
—Change visible parts to any ascii character
—More coming soon
-Added de-fragment option
-Ability to change pencil draw font
-Ability to save in different file formats (pm me to add yours)
-Movie maker with install
-You now have to enter a verification code to run the program - "2514-V103-SEFB"
-Extremely buggy pre-release enter function added (r-ctrl:enter:r-shift) to activate for 100 key presses

Still to come:
-Way way way quicker saving (current rate is 1 character/0.05secs (takes a minute for a 1200 character picture))
-Add pre-installed templates to screen
-Make your own templates
-Print using cc-1.41 printers
-Send pictures over rednet
-Automatic saving of files from rednet
-Add in .skt at end of saved files
-More intelligent saving system

Tips and controls:
Spoiler

Use arrow keys to navigate menu
Press enter to make selection
Press tab to switch screen
Use arrow keys to move
Press key to draw it to the screen in pencil mode
(Space clears that spot and moves to the left 1)
Press l-shift to toggle the always draw mode (you will understand if you try) in draw mode
Move eraser/rubber over things you want to erase/rub out
Press l-shift to erase whole screen in rubber mode
Press l-shift to start drawing box in draw box mode
Use arrow keys to set the bottom right point of the box when you have started in draw box mode
Press key to set interior of box to that character in draw box mode
Press backspace to cancel/abort the box in draw box mode
Press backspace to exit the program
Submit feedback here
Type "sketch-it/app" to run the program


I will be putting loads of pictures that I have made on the website…if you make one and want to have it available for other people send me a pm!

Screenshots and videos coming soon!
If you try it make sure to comment and if you find bugs please tell me so i can squash them

V-1.0.2 Source code:

Spoiler

--this is the sketch-it program
--copyright of BlueTide Programs.inc, Benedict Allen, all members of BlueTide Programs.inc and all members of programcraft.inc
--if you wish to use this program please contact Benedict Allen(awsumben13 on cc forums) and make sure you give the credit to BlueTide Programs
--usability functions
local function clear(x,y)
if x == nil or y == nil then
  term.clear()
  term.setCursorPos(1,1)
else
  term.clear()
  term.setCursorPos(x,y)
end
end
function writePos(x,y,text)
term.setCursorPos(x,y)
term.write(text)
end
function clearPrint(x,y,text)
term.clear()
term.setCursorPos(x,y)
term.write(text)
end
function reset(file, x, y)
if fs.exists(file) then
  h = fs.open(file, "w")
  h.write("")
  h.close()
  term.setCursorPos(x,y)
  term.write("File reset")
  sleep(2)
else
  term.setCursorPos(x,y)
  term.write("file not found")
  sleep(2)
end
end
function tip(help)
while true do
  clear()
  print(help)
  writePos(1,17,"press enter to exit")
  event, key = os.pullEvent()
  if key == 28 then break
  end
end
end
function drawBox(x,y,z,n)
for k = 1,n-y do
  for i = 1,z-x do
   writePos(x+i,y+k," ")
  end
end
writePos(x,y,"+")
term.setCursorPos(x+1,y)
for i = 1,(z-x)-1 do
  write("-")
end
writePos(z,y,"+")
term.setCursorPos(x+1,n)
for i = 1,(z-x)-1 do
  write("-")
end
for i = 1,(n-y)-1 do
  writePos(x,y+i,"|")
end
for i = 1,(n-y)-1 do
  writePos(z,y+i,"|")
end
writePos(x,n,"+")
writePos(z,n,"+")
end
function saveBox(type)
if type == nil then
  add("+", cursorPosX, boxY)
  for i = 1,((cursorPosX+1)-boxX)-2 do
   add("-", boxX+i, boxY)
  end
  add("+", boxX, boxY)
  add("+", cursorPosX, cursorPosY)
  for i = 1,((cursorPosX+1)-boxX)-2 do
   add("-", boxX+i, cursorPosY)
  end
  add("+",boxX, cursorPosY)
  for i = 1,((cursorPosY+1)-boxY)-2 do
   add("|", boxX, boxY+i)
  end
  for i = 1,((cursorPosY+1)-boxY)-2 do
   add("|", cursorPosX, boxY+i)
  end
else
  for i = boxX, cursorPosX do
   for k = boxY, cursorPosY do
	add(type, i, k)
   end
  end
end
end
function split(str, pat)
   local t = {}
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
	  if s ~= 1 or cap ~= "" then
  table.insert(t,cap)
	  end
	  last_end = e+1
	  s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
	  cap = str:sub(last_end)
	  table.insert(t, cap)
   end
   return t
end
function animation(limit, item, time, x, y)
yer = 0
if x == nil or y == nil then
  x, y = term.getCursorPos()
end
while true do
  if yer > limit then
   yer = 0
  end
  writePos(x, y+yer, item)
  sleep(time)
  yer = yer+1
end
end
--end
--programs functions
function askToSave()
while true do
  drawBox(14,8,44,11)
  writePos(16,9,"Do you want to save first?")
  writePos(17,10,"Yes   No   Cancel")
  if newPos == 1 then
   writePos(16,10,"[")
   writePos(20,10,"]")
  elseif newPos == 2 then
   writePos(22,10,"[")
   writePos(25,10,"]")
  elseif newPos == 3 then
   writePos(27,10,"[")
   writePos(34,10,"]")
  end
  event, key = os.pullEvent()
  if key == 203 and newPos > 1 then
   newPos = newPos-1
  elseif key == 205 and newPos < 3 then
   newPos = newPos+1
  elseif key == 28 then
   if newPos == 1 then
	save()
	xToPrint = {}
	yToPrint = {}
	itemToPrint = {}
	fileOpen = "New File"
	break
   elseif newPos == 2 then
	xToPrint = {}
	yToPrint = {}
	itemToPrint = {}
	fileOpen = "New File"
	break
   elseif newPos == 3 then
	loopBreaker = false
	break
   end
  end
end
end
function open()
if changed == true then
  askToSave()
end
openSel = 1
while true do
  variable = 0
  bottomLimit = topLimit+14
  clear()
  drawBox(1,1,50,18)
  writePos(2,2,"Select the file you want to open:")
  files = fs.list("sketch-it/saves")
  table.insert(files, "Cancel")
  if #files < 15 then
   bottomLimit = #files
  end
  for i = topLimit,bottomLimit do
   variable = variable+1
   writePos(3,2+variable,files[i])
  end
  writePos(2,2+openSel,">")
  event, key = os.pullEvent()
  if key == 200 and openSel > 1 then
   openSel = openSel-1
  elseif key == 208 and openSel < 14 and openSel < #files then
   openSel = openSel+1
  elseif key == 200 and openSel == 1 and topLimit > 1 then
   topLimit = topLimit-1
  elseif key == 208 and openSel == 14 and (bottomLimit <= #files or bottomLimit == 15) then
   topLimit = topLimit+1
  elseif key == 14 then
   break
  elseif key == 28 then
   selectedFile = files[openSel+(topLimit-1)]
   if fs.exists("sketch-it/saves/"..selectedFile.."/xpos") and fs.exists("sketch-it/saves/"..selectedFile.."/ypos") and fs.exists("sketch-it/saves/"..selectedFile.."/item") and selectedFile ~= #files then
	xToPrint = {}
	yToPrint = {}
	itemToPrint = {}
	writePos(2,18,"opening "..selectedFile)
	sleep(1.3)
	file = fs.open("sketch-it/saves/"..selectedFile.."/xpos","r")
	while true do
	 line = file.readLine()
	 table.insert(xToPrint, tonumber(line))
	 if not line then
	  break
	 end
	end
	file = fs.open("sketch-it/saves/"..selectedFile.."/ypos","r")
	while true do
	 line = file.readLine()
	 table.insert(yToPrint, tonumber(line))
	 if not line then
	  break
	 end
	end
	file = fs.open("sketch-it/saves/"..selectedFile.."/item","r")
	while true do
	 line = file.readLine()
	 table.insert(itemToPrint, line)
	 if not line then
	  break
	 end
	end
	fileOpen = selectedFile
	currentField = 2
	break
   elseif openSel == #files then
	break
   else
	drawBox(17,8,33,10)
	writePos(20,9,"broken file")
	sleep(0.7)
   end
  end
end
sketchitWatermark = false
end
function save()
m = 1
secs = (#itemToPrint*3)/20
clear()
drawBox(1,1,50,17)
files = fs.list("sketch-it/saves")
if #files > 14 then
  for i = 1,14 do
   writePos(3,1+i,files[i])
  end
  if #files > 28 then
   for i = 15,28 do
	writePos(25,-13+i,files[i])
   end
  else
   for i = 15,#files do
	writePos(25,-13+i,files[i])
   end
  end
else
  for i = 1,#files do
   writePos(3,1+i,files[i])
  end
end
writePos(1,18,"What do you want to save the file as? ")
input = read()
if not fs.exists(shell.resolve(input)) then
  fs.makeDir("sketch-it/saves/"..input)
end
writePos(1,19,"Saving...this may take a while...")
file = fs.open("sketch-it/saves/"..input.."/xpos","w")
for i = 1,#xToPrint do
  file.writeLine(xToPrint[i])
  sleep(0.001)
  m = m+1
  secs = secs-0.05
  writePos(1,18,"What do you want to save the file as? approx "..secs.." seconds left")
  writePos(35, 19, m.." Out of "..(#itemToPrint*3))
end
file.close()
file = fs.open("sketch-it/saves/"..input.."/ypos","w")
for i = 1,#yToPrint do
  file.writeLine(yToPrint[i])
  sleep(0.001)
  m = m+1
  secs = secs-0.05
  writePos(1,18,"What do you want to save the file as? approx "..secs.." seconds left")
  writePos(35, 19, m.." Out of "..(#itemToPrint*3))
end
file.close()
file = fs.open("sketch-it/saves/"..input.."/item","w")
for i = 1,#itemToPrint do
  file.writeLine(itemToPrint[i])
  sleep(0.001)
  m = m+1
  secs = secs-0.05
  writePos(1,18,"What do you want to save the file as? approx "..secs.." seconds left")
  writePos(35, 19, m.." Out of "..(#itemToPrint*3))
end
file.close()
if input ~= "exit" then
  fileOpen = input
end
changed = false
end
function runFieldOne()
drawScreenOne()
drawScreenTwo()
drawBox(1,3,11,19)
for i = 1,#mopt do
  writePos(3,3+(i*2),mopt[i])
end
writePos(2,3+(f1Selected*2),">")
event, key = os.pullEvent()
if (key == 200 or key == 17)and f1Selected > 1 then
  f1Selected = f1Selected-1
elseif (key == 208 or key == 31)and f1Selected < #mopt then
  f1Selected = f1Selected+1
elseif key == 14 then
  loopBreaker = true
elseif key == 15 then
  currentField = 2
elseif key == 28 then
  if f1Selected == 4 then
   drawMode = 1
  elseif f1Selected == 5 then
   drawMode = 3
  elseif f1Selected == 6 then
   drawMode = 2
  elseif f1Selected == 1 then
   if changed ~= true then
	xToPrint = {}
	yToPrint = {}
	itemToPrint = {}
	fileOpen = "New File"
	sketchitWatermark = false
   else
	askToSave()
   end
  elseif f1Selected == 2 then
   open()
  elseif f1Selected == 3 then
   save()
  end
end
end
function drawScreenOne()
if currentField == 1 then
  clear()
  drawBox(1,1,50,19)
  writePos(1,3,"+------------------------------------------------+")
  drawBox(1,3,11,19)
  writePos(3,2,"Open: "..fileOpen.." - File size: "..#itemToPrint*3)
  for i = 1,#mopt do
   writePos(3,3+(i*2),mopt[i])
  end
  if drawMode == 1 then
   writePos(50-string.len("Tool: pencil")-1, 2, "Tool: pencil")
  elseif drawMode == 2 then
   writePos(50-string.len("Tool: draw box")-1, 2, "Tool: draw box")
  elseif drawMode == 3 then
   writePos(50-string.len("Tool: rubber")-1, 2, "Tool: rubber")
  end
else
  clear()
  drawBox(1,1,50,19)
  writePos(1,3,"+------------------------------------------------+")
  writePos(3,2,"Open: "..fileOpen.." - File size: "..#itemToPrint*3)
  writePos(9,13,"|")
  drawBox(1,3,9,19)
  for i = 1,#mopt do
   writePos(2,3+(i*2),mopt[i])
  end
  writePos(9,15,"|") -- to cover up "draw box"
  if drawMode == 1 then
   writePos(50-string.len("Tool: pencil")-1, 2, "Tool: pencil")
  elseif drawMode == 2 then
   writePos(50-string.len("Tool: draw box")-1, 2, "Tool: draw box")
  elseif drawMode == 3 then
   writePos(50-string.len("Tool: rubber")-1, 2, "Tool: rubber")
  end
end
end
function add(item, x, y)
if x == nil or y == nil then
  x = cursorPosX
  y = cursorPosY
end
for i = 1,#itemToPrint do
  if xToPrint[i] == x and yToPrint[i] == y then
   table.remove(xToPrint, i)
   table.remove(yToPrint, i)
   table.remove(itemToPrint, i)
  end
end
table.insert(xToPrint, x)
table.insert(yToPrint, y)
table.insert(itemToPrint, item)
end
function runFieldTwo()
drawScreenOne()
drawScreenTwo()
if sketchitWatermark == false then
  k = "sketch-it version "..version
  for i = 1,string.len(k) do
   add(string.sub(k,i,i),10+i,18)
  end
  sketchitWatermark = true
end
if drawMode == 3 then
  for i = 1,#itemToPrint do
   if (cursorPosX == xToPrint[i] and cursorPosY == yToPrint[i]) then
	table.remove(xToPrint, i)
	table.remove(yToPrint, i)
	table.remove(itemToPrint, i)
	changed = true
   end
  end
end
if drawing == true and drawMode == 1 then
  add(drawIcon)
  changed = true
end
event, key, item = os.pullEvent()
if key == 200 and cursorPosY > 4 then
  cursorPosY = cursorPosY-1
elseif key == 208 and cursorPosY < 17 then
  cursorPosY = cursorPosY+1
elseif key == 203 and cursorPosX > 10 then
  cursorPosX = cursorPosX-1
elseif key == 205 and cursorPosX < 49 then
  cursorPosX = cursorPosX+1
elseif event == "char" and drawMode == 2 and key ~= " " and boxStarted ~= false then
  saveBox(key)
  boxStarted = false
  changed = true
elseif event == "char" and drawMode == 2 and key == " " and boxStarted ~= false then
  for i = 1,2 do
   for z = boxX, cursorPosX do
	for i = 1,#itemToPrint do
	 for k = boxY, cursorPosY do
	  if k == yToPrint[i] and z == xToPrint[i] then
	   table.remove(xToPrint, i)
	   table.remove(yToPrint, i)
	   table.remove(itemToPrint, i)
	  end
	 end
	end
   end
  end
  boxStarted = false
  changed = true
elseif key == 15 then
  currentField = 1
elseif key == 14 and boxStarted == false then
  loopBreaker = true
  if changed == true then
   askToSave()
  end
elseif key == 42 and drawMode == 1 and drawing == false then
  drawing = true
elseif event == "char" and drawMode == 1 and key ~= " " then
  add(key)
  changed = true
  if cursorPosX < 49 then
   cursorPosX = cursorPosX+1
  end
  drawing = false
elseif key == 57 and drawMode == 1 and cursorPosX < 49 then
  for i = 1,#itemToPrint do
   if cursorPosX == xToPrint[i] and cursorPosY == yToPrint[i] then
	table.remove(xToPrint, i)
	table.remove(yToPrint, i)
	table.remove(itemToPrint, i)
   end
  end
  cursorPosX = cursorPosX+1
elseif key == 42 and drawMode == 1 and drawing == true then
  drawing = false
elseif key == 42 and drawMode == 3 then
  changed = true
  xToPrint = {}
  yToPrint = {}
  itemToPrint = {}
  sketchitWatermark = false
elseif key == 42 and drawMode == 2 and boxStarted ~= true then
  boxStarted = true
  boxX = cursorPosX
  boxY = cursorPosY
elseif key == 42 and drawMode == 2 and boxStarted == true then
  boxStarted = false
  saveBox()
  changed = true
elseif key == 14 and boxStarted == true then
  boxStarted = false
elseif key == 199 then
  cursorPosX = 10
  cursorPosY = 4
elseif key == 29 then
  os.startTimer(0.2)
  event, key = os.pullEvent()
  if key == 200 then
   cursorPosY = 4
  elseif key == 208 then
   cursorPosY = 17
  elseif key == 203 then
   cursorPosX = 10
  elseif key == 205 then
   cursorPosX = 49
  end
end
end
function drawScreenTwo()
drawScreenOne()
if drawMode == 1 then
  writePos(cursorPosX,cursorPosY,"x")
end
for i = 1,#itemToPrint do
  writePos(xToPrint[i],yToPrint[i],itemToPrint[i])
end
if drawMode == 1 then
  writePos(cursorPosX-1,cursorPosY+1,"/|")
  writePos(cursorPosX-2,cursorPosY+2,"//")
  writePos(cursorPosX-3,cursorPosY+3,"//")
  writePos(cursorPosX-4,cursorPosY+4,"</")
elseif drawMode == 2 then
  writePos(cursorPosX,cursorPosY,"X")
elseif drawMode == 3 then
  drawBox(cursorPosX,cursorPosY,cursorPosX+2,cursorPosY+2)
  writePos(cursorPosX,cursorPosY,"O")
end
if boxStarted == true then
  drawBox(boxX,boxY,cursorPosX,cursorPosY)
end
end
--end
--variables
sketchitWatermark = false
drawing = false
boxStarted = false
changed = false
drawMode = 1
fileOpen = "New File"
version = "1.0.2"
mopt = {
"New";
"Open";
"Save";
"Pencil";
"Rubber";
"Draw box";
"More";
}
currentField = 1
f1Selected = 1
loopBreaker = false
cursorPosY = 4
cursorPosX = 15
xToPrint = {}
yToPrint = {}
itemToPrint = {}
drawIcon = "o"
newPos = 1
topLimit = 1
bottomLimit = topLimit+14
openSel = 1
--end
--code
if not fs.exists("sketch-it") then
fs.makeDir("sketch-it")
end
if not fs.exists("sketch-it/saves") then
fs.makeDir("sketch-it/saves")
end
while loopBreaker ~= true do
if currentField == 1 then
  runFieldOne()
else
  runFieldTwo()
end
end
clear()
writePos(1,1,"Thanks for using sketch-it!")
--end


Thanks

This program is copyrighted to BlueTide Programs. Website: www.bluetideprograms.webs.com Skype: benedict.98 Email: bluetideprograms@gmail.com CC Forums: awsumben13
If you wish to use, edit, distribute or anything else this program please contact us using the links above

Top download link is for v-1.0.2 and the bottom one is for v-1.0.3
jag #2
Posted 28 September 2012 - 07:44 PM
Really cool! Works great!!
I was playing around with it, a really cool tool!
Image 1:
Spoiler
Image 2:
Spoiler
Exerro #3
Posted 28 September 2012 - 07:51 PM
:P/>/> glad you like it! Thanks for putting some pictures up as well because i'm not sure how to :l have fun!
jag #4
Posted 28 September 2012 - 08:59 PM
:P/>/> glad you like it! Thanks for putting some pictures up as well because i'm not sure how to :l have fun!
Well you can just take a screenshot inside of minecraft, and the use like imgur.com to upload the image, and the use the image link in the post.
Exerro #5
Posted 07 October 2012 - 01:12 PM
Sketch-it version 1.0.3 is out!
This update includes sketch-it movie maker, lots more options in the program like the select tool, and de-frag option, and a all new verification system to stop 3rd party distribution. Have fun!