MiStAWaFFlEZZ

Circle Drawer

Feb 14th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --Circular Digger--
  2. function define()
  3.     print("Circle Diameter: ")
  4.     d = read()
  5.     if d <= 1 then
  6.         print("ERROR: Diameter must be greater than 1")
  7.     end
  8.     r = tonumber(d / 2 )-- radius
  9.     print("Radius: " ..r)
  10.     theta = 0
  11.     r = r - 1 -- normalise values, otherwise r = 1 is actually r = 2
  12.     m = peripheral.wrap("<SIDE>") -- allows interaction with the monitor
  13.     currX = 0 -- Turtle's pos in the X (length)
  14.     currY = 0 -- Turtle's pos in the Y (depth)
  15.     currZ = 0 -- pos in the Z (width)
  16. end
  17. function getCoords()
  18.     repeat
  19.         for theta = 0, 359 do --draw all of the circle. (No 360 b/c 0 = 360)
  20.             xCoord = math.floor(r * math.cos(math.rad(theta))) -- math.rad() math.cos/sin expects radians
  21.             yCoord = math.floor(r * math.sin(math.rad(theta)))
  22.             --m.setCursorPos(xCoord, yCoord) -- Monitor O utput
  23.             --m.write("#") -- Replace with whatever the circle will be drawn as
  24.             moveTo()
  25.         end
  26.         r = r - 1 -- reduce r by 1 and draw the circle again. draws the next 'inner' circle. Basically, this fills the entire circle in.
  27.     until r == -1 -- technically -1 = 0, 0 = 1 etc. so really, until r = 0
  28. end
  29.  
  30. function moveTo() -- TO DO: Turtle intergration
  31. atLoc = false
  32. repeat
  33.     if currX >  xCoord then
  34.         turtle.back()
  35.         currX = currX - 1
  36.     end
  37.     if currX < xCoord then
  38.         turtle.forward()
  39.         currX = currX + 1
  40.     end
  41.     if currX == xCoord then
  42.         turtle.left()
  43.             if currY >  yCoord then
  44.                 turtle.back()
  45.                 currY = currY - 1
  46.             end
  47.             if currY < yCoord then
  48.                 turtle.forward()
  49.                 currY = currY + 1
  50.             end
  51.             if currY == yCoord then
  52.                 print("Made it!")
  53.                 atLoc = true
  54.     end
  55. until atLoc == true
  56. end
  57.  
  58. define()
  59. getCoords()
Advertisement
Add Comment
Please, Sign In to add comment