Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- drawElipse <semi_major_axis> <semi_minor_axis>
- -- place turtle facing semi-minor axis in the center
- args = {...}
- sMa = args[1]
- sma = args[2]
- print(sMa)
- print(sma)
- stage = 1
- running = true
- selectedItem = 1
- --[[stages 1=started, moving toward sma
- 2=moving right, back
- 3=moving left, back
- 4=moving left, forward
- 5=moving right, forward]]--
- location = {x=0, y=0}
- foci = {{x=0, y=0},{x=0,y=0}}
- function findFoci()
- dF = math.sqrt((sMa*sMa)-(sma*sma))
- foci[1].x = math.floor(dF)
- foci[2].x = -(math.floor(dF))
- end
- function move(dir)
- -- dir = 1 forward, 2 = forward/right, 3 = right, 4 = back/right, 5 = back, 6 = back/left, 7 = left, 8 = forward/left
- -- note: turtle will ALWAYS face the same direction
- if dir == 1 then
- if turtle.forward() then
- location.y = location.y + 1
- end
- elseif dir == 2 then
- move(1)
- move(3)
- elseif dir == 3 then
- turtle.turnRight()
- if turtle.forward() then
- location.x = location.x + 1
- end
- turtle.turnLeft()
- elseif dir == 4 then
- move(5)
- move(3)
- elseif dir == 5 then
- if turtle.back() then
- location.y = location.y - 1
- end
- elseif dir == 6 then
- move(5)
- move(7)
- elseif dir == 7 then
- turtle.turnLeft()
- if turtle.forward() then
- location.x = location.x - 1
- end
- turtle.turnRight()
- elseif dir == 8 then
- move(1)
- move(7)
- end
- end
- function focalDistance(pos)
- dx1 = pos.x - foci[1].x
- dx2 = pos.x - foci[2].x
- dy1 = pos.y - foci[1].y
- dy2 = pos.y - foci[2].y
- print("Foci:"..textutils.serialize(foci))
- print("Pos:"..textutils.serialize(pos))
- df1 = math.sqrt(dx1*dx1 + dy1*dy1)
- df2 = math.sqrt(dx2*dx2 + dy2*dy2)
- return math.floor(df1+df2)
- end
- function chooseItem()
- if turtle.getItemCount(selectedItem) < 2 then
- selectedItem = selectedItem + 1
- end
- turtle.select(selectedItem)
- end
- function main()
- chooseItem()
- pos = {}
- print("Stage: "..tostring(stage))
- if stage == 1 then
- move(1)
- print("location: " ..textutils.serialize(location))
- print("Focal Dist: "..tostring(math.floor(focalDistance(location))))
- print("Major Axis: "..tostring(tonumber(sMa)*2))
- if math.floor(focalDistance(location)) == tonumber(sMa)*2 then
- turtle.placeUp()
- stage = 2
- return
- end
- elseif stage == 2 then
- pos.x = location.x + 1
- pos.y = location.y
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 3
- else
- pos.x = location.x + 1
- pos.y = location.y - 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 4
- else
- pos.x = location.x
- pos.y = location.y - 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 5
- end
- end
- end
- move(dir)
- turtle.placeUp()
- if location.y == 0 then
- stage = 3
- return
- end
- elseif stage == 3 then
- pos.x = location.x
- pos.y = location.y - 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 5
- else
- pos.x = location.x - 1
- pos.y = location.y - 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 6
- else
- pos.x = location.x - 1
- pos.y = location.y
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 7
- end
- end
- end
- move(dir)
- turtle.placeUp()
- if location.x == 0 then
- stage = 4
- return
- end
- elseif stage == 4 then
- pos.x = location.x - 1
- pos.y = location.y
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 7
- else
- pos.x = location.x - 1
- pos.y = location.y + 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 8
- else
- pos.x = location.x
- pos.y = location.y + 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 1
- end
- end
- end
- move(dir)
- turtle.placeUp()
- if location.y == 0 then
- stage = 5
- return
- end
- elseif stage == 5 then
- pos.x = location.x
- pos.y = location.y + 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 1
- else
- pos.x = location.x + 1
- pos.y = location.y + 1
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 2
- else
- pos.x = location.x + 1
- pos.y = location.y
- if math.floor(focalDistance(pos)) == tonumber(sMa)*2 then
- dir = 3
- end
- end
- end
- move(dir)
- turtle.placeUp()
- if location.x == 0 then
- stage = 6
- return
- end
- elseif stage == 6 then
- move(5)
- if location.x == 0 and location.y == 0 then
- running = false
- end
- end
- end
- findFoci()
- while running do
- parallel.waitForAny(main)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement