eniallator

Pong WIP

Jul 31st, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. grid = {}
  2. width, height = term.getSize()
  3.  
  4. function straightLineEquation(x,y,x2,y2)
  5.   dim =  {width:(x2 - x),height:(y2 - y)}
  6.   gradient = dim[height]/dim[width]
  7.   heightIntercept = -(gradient*dim[width]) + dim[height]
  8. end
  9.  
  10. for w=1,width do
  11.   grid[w] = {}
  12.  
  13.   for h=1,height do
  14.     grid[w][h] = ""
  15.     equation = gradient*w + heightIntercept
  16.    
  17.     if equation%1 < 0.5 then
  18.       equation = math.floor(equation)
  19.     else
  20.       equation = math.ceil(equation)
  21.     end
  22.    
  23.     term.setCursorPos(w,h)
  24.    
  25.     if w == 1 or h == 1 or w == width or h == height then
  26.       term.setBackgroundColor(colors.green)
  27.       term.write(" ")
  28.      
  29.     elseif h == equation then
  30.       term.setBackgroundColor(colors.green)
  31.       term.write("x")
  32.      
  33.     else
  34.       term.setBackgroundColor(colors.lime)
  35.       term.write(" ")
  36.     end
  37.   end
  38. end
  39.  
  40. sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment