Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- currentx = 0
- currenty = 0
- function move (n,str)
- function forward(n)
- while n > 0
- do turtle.forward()
- n = n - 1
- currenty = currenty + 1
- end
- end
- function back(n)
- while n > 0
- do turtle.back()
- n = n - 1
- currenty = currenty - 1
- end
- end
- function right(n)
- while n > 0
- do turtle.turnRight()
- turtle.forward()
- n = n - 1
- currentx = currentx + 1
- turtle.turnLeft()
- end
- end
- function left(n)
- while n > 0
- do turtle.turnLeft()
- turtle.forward()
- currentx = currentx - 1
- n = n - 1
- turtle.turnRight()
- end
- end
- if str == "forward"
- then forward(n)
- elseif str == "back"
- then back (n)
- elseif str == "right"
- then right(n)
- elseif str == "left"
- then left (n)
- else
- print("string error, not a direction")
- print("or bug in function move")
- end
- end
- function plot(desiredx,desiredy)
- local movementx = desiredx - currentx
- local movementy = desiredy - currenty
- if movementy < 0
- then movementy = -movementcurrenty
- move(movementy,"back")
- else
- move(movementy,"forward")
- end
- if movementx < 0
- then movementx = -movementcurrentx
- move(movementx,"left")
- else
- move(movementx,"right")
- end
- turtle.placeDown()
- end
- function drawcircle (radius)
- turtle.up()
- turtle.placeDown()
- local f = 1 - radius
- local ddx = 0
- local ddy = -2*radius
- local x = 0
- local y = radius
- plot(0,0 + radius)
- plot(0, 0 - radius)
- plot(0 + radius,0)
- plot(0 - radius,0)
- while x < y
- do
- if f >= 0
- then y = y - 1
- ddy = ddy + 2
- f = f + ddy
- end
- x = x + 1
- ddx = ddx + 2
- f = f + ddx + 1
- plot (0 + x,0 + y)
- plot (0 - x, 0 + y)
- plot (0 + x, 0 - y)
- plot (0 - x, 0 - y)
- plot (0 + y, 0 + x)
- plot (0 - y, 0 + x)
- plot (0 + y, 0 - x)
- plot (0 - y, 0 - x)
- end
- end
- function reset ()
- currentx = 0
- currenty = 0
- end
- print("Good day, radius please")
- radius = tonumber(read())
- drawcircle(radius)
Add Comment
Please, Sign In to add comment