• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Nov 16th, 2018 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. currentx = 0
2. currenty = 0
3. function move (n,str)
4.     function forward(n)
5.         while n > 0
6.             do turtle.forward()
7.             n = n - 1
8.             currenty = currenty + 1
9.         end
10.     end
11.     function back(n)
12.         while n > 0
13.             do turtle.back()
14.             n = n - 1
15.             currenty = currenty - 1
16.         end
17.     end
18.     function right(n)
19.         while n > 0
20.             do turtle.turnRight()
21.             turtle.forward()
22.             n = n - 1
23.             currentx = currentx + 1
24.             turtle.turnLeft()
25.         end
26.     end
27.     function left(n)
28.         while n > 0
29.             do turtle.turnLeft()
30.             turtle.forward()
31.             currentx = currentx - 1
32.             n = n - 1
33.             turtle.turnRight()
34.
35.         end
36.     end
37. if str == "forward"
38.     then forward(n)
39. elseif str == "back"
40.     then back (n)
41. elseif str == "right"
42.     then right(n)
43. elseif str == "left"
44.     then left (n)
45. else
46.     print("string error, not a direction")
47.     print("or bug in function move")
48. end
49. end
50. function plot(desiredx,desiredy)
51.     local movementx = desiredx - currentx
52.     local movementy = desiredy - currenty
53.     if movementy < 0
54.         then movementy = -movementcurrenty
55.         move(movementy,"back")
56.     else
57.         move(movementy,"forward")
58.     end
59.     if movementx < 0
60.         then movementx = -movementcurrentx
61.         move(movementx,"left")
62.     else
63.         move(movementx,"right")
64.
65.     end
66.
67.     turtle.placeDown()
68.
69.
70. end
71.
72. function drawcircle (radius)
73.     turtle.up()
74.     turtle.placeDown()
75.     local f = 1 - radius
76.     local ddx = 0
77.     local ddy = -2*radius
78.     local x = 0
79.     local y = radius
80.     plot(0,0 + radius)
81.     plot(0, 0 - radius)
82.     plot(0 + radius,0)
83.     plot(0 - radius,0)
84.     while x < y
85.         do
86.         if f >= 0
87.             then y = y - 1
88.             ddy = ddy + 2
89.             f = f + ddy
90.         end
91.         x = x + 1
92.         ddx = ddx + 2
93.         f = f + ddx + 1
94.         plot (0 + x,0 + y)
95.         plot (0 - x, 0 + y)
96.         plot (0 + x, 0 - y)
97.         plot (0 - x, 0 - y)
98.         plot (0 + y, 0 + x)
99.         plot (0 - y, 0 + x)
100.         plot (0 + y, 0 - x)
101.         plot (0 - y, 0 - x)
102.     end
103. end
104.
105. function reset ()
106.     currentx = 0
107.     currenty = 0
108. end
109. print("Good day, radius please")
110. radius = tonumber(read())
111. drawcircle(radius)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top