Advertisement
TheOddByte

[ComputerCraft][API] Draw

Sep 28th, 2014
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. --[[
  2.     [API] Draw
  3.     @version 1.0, 2014/06/29
  4.     @author TheOddByte
  5. --]]
  6.  
  7.  
  8.  
  9. local version = "1.0"
  10.  
  11.  
  12.  
  13.  
  14. function at( x, y, text )
  15.     term.setCursorPos( x, y )
  16.     term.write( text )
  17. end
  18.  
  19.  
  20.  
  21. function setColors( text_color, background )
  22.     if text_color then
  23.         pcall( term.setTextColor, text_color  )
  24.     end
  25.     if background then
  26.         pcall( term.setBackgroundColor, background  )
  27.     end
  28. end
  29.  
  30.  
  31. function line( x, y, width, text_color, background, str )
  32.     setColors( text_color, background )
  33.     if str then
  34.         str = str:sub( 1,1 )
  35.     else
  36.         str = " "
  37.     end
  38.     local line = string.rep( str, width )
  39.     at( x, y, line )
  40. end
  41.  
  42.  
  43. function box( x, y, width, height, background )
  44.     setColors( nil, background )
  45.     for i = 1, height do
  46.         line( x, (y-1)+i, width, nil, background )
  47.     end
  48. end
  49.  
  50.  
  51. function center( y, text, text_color, background )
  52.     setColors( text_color, background )
  53.     local w, h = term.getSize()
  54.     at( math.ceil( (w - #text)/2 ), y, text )
  55. end
  56.  
  57. function midpoint( x1, x2, y, text, text_color, background )
  58.     setColors( text_color, background )
  59.     at( math.ceil( ((x1+x2)-#text)/2 ), y, text )
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement