eniallator

Straight Line Equation Grapher

Sep 30th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. local width,height = 15,40
  2.  
  3. local gradient = height/width
  4. local heightIntercept = -(gradient*width) + height
  5.  
  6. for w=1,width do
  7.     local output = ""
  8.  
  9.   for h=1,height do
  10.     equation = gradient*w + heightIntercept
  11.  
  12.     if equation%1 < 0.5 then
  13.         equation = math.floor(equation)
  14.     else
  15.         equation = math.ceil(equation)
  16.     end
  17.  
  18.     if w == 1 or h == 1 or w == width or h == height then
  19.         output = output .. " "
  20.  
  21.     elseif h == equation then
  22.         output = output .. "x"
  23.  
  24.     else
  25.         output = output .. " "
  26.     end
  27.   end
  28.  
  29.   print(output)
  30. end
Advertisement
Add Comment
Please, Sign In to add comment