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
- sMa, 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]]--
- 1
- location = {x=0, y=0}
- foci = {1={x=0, y=0}, 2={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 = right, 3 = back, 4 = left
- -- note: turtle will ALWAYS face the same direction
- if dir == 1 then
- if turtle.forward() then
- location.y = location.y + 1
- end
- elsif dir == 2 then
- turtle.turnRight()
- if turtle.forward() then
- location.x = location.x + 1
- end
- turtle.turnLeft()
- elseif dir == 3 then
- if turtle.back() then
- location.y = location.y - 1
- end
- elseif dir == 4 then
- turtle.turnLeft()
- if turtle.forward() then
- location.x = location.x - 1
- end
- turtle.turnRight()
- end
- end
- function focalDistance()
- dx1 = location.x - foci[1].x
- dx2 = location.x - foci[2].x
- dy1 = location.y - foci[1].y
- dy2 = location.y - foci[2].y
- 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()
- if stage == 1 then
- if focalDistance() < (sMa * 2) then
- move(1)
- else
- turtle.placeUp()
- stage = 2
- return
- end
- elseif stage == 2 then
- move(2)
- if focalDistance() > (sMa * 2) then
- move(3)
- end
- turtle.placeUp()
- if location.x == 0 then
- stage = 3
- return
- end
- elseif stage == 3 then
- move( 3)
- if focalDistance() > (2*sMa) then
- move(4)
- end
- turtle.placeUp()
- if location.y == 0 then
- stage = 4
- return
- end
- elseif stage == 4 then
- move(4)
- if focalDistance() == (2*sMa) then
- move(1)
- end
- turtle.placeUp()
- if location.y == 0 then
- stage = 5
- return
- end
- elseif stage == 5
- move(1)
- if focalDistance() > (2*sMa) then
- move(2)
- end
- turtle.placeUp()
- if location.y == 0 then
- stage = 6 return
- end
- elseif stage == 6 then
- move(3)
- if location.x == 0 and location.y == 0 then
- running = false
- end
- end
- end
- while running do
- parallel.waitForAny(main)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement