Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pullEventBackup = os.pullEvent
- os.pullEvent = os.pullEventRaw
- term.clear()
- -- this program accepts 1 optional argument, being intensity. Intensity determines the likelihood of the line to turn. Default is 0.05, max is 0.5 (mostly turning) and min is 0 (straight lines)
- local args = {...}
- local intensity = tonumber(args[1]) or 0.05
- if intensity > 0.5 then intensity = 0.5 end
- if intensity < 0 then intensity = 0 end
- local linego = false
- local redraw = os.startTimer(0.05)
- local startfrom = {["x"] = 0, ["y"] = 0, ["dir"] = 0}
- local termx, termy = term.getSize()
- -- directions: 0 - down; 1 - left; 2 - up; 3 - right
- while true do
- e, p1, p2, p3 = os.pullEvent()
- if e == 'terminate' then
- term.setBackgroundColor(2^15)
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(2^14)
- end
- print('Terminated')
- os.pullEvent = pullEventBackup
- break
- end
- if e == 'key' then
- if p1 == keys.q then
- term.setBackgroundColor(2^15)
- term.clear()
- term.setCursorPos(1,1)
- sleep(0.05)
- os.pullEvent = pullEventBackup
- break
- end
- end
- if e == 'timer' then
- if startfrom.x > termx or startfrom.x < 1 or startfrom.y > termy or startfrom.y < 1 then
- linego = false
- end
- if not linego then
- linego = true
- math.randomseed(os.time()*1000)
- term.setBackgroundColor(math.pow(2, ((math.log(term.getBackgroundColor())/math.log(2)) + (math.random(1,14)))%15))
- local perimeter = (termx*2) + (termx*2)
- local startnum = math.random(1,perimeter)
- if startnum > (termx*2) + termy then
- -- left
- startfrom.x = 1
- startfrom.y = startnum - ((termx*2) + termy)
- startfrom.dir = 3
- elseif startnum > termx + termy then
- -- bottom
- startfrom.y = termy
- startfrom.x = startnum - (termx + termy)
- startfrom.dir = 2
- elseif startnum > termx then
- -- right
- startfrom.x = termx
- startfrom.y = startnum - termx
- startfrom.dir = 1
- else
- -- top
- startfrom.y = 1
- startfrom.x = startnum
- startfrom.dir = 0
- end
- end
- term.setCursorPos(startfrom.x, startfrom.y)
- write(' ')
- local rnd = math.random()
- if rnd < intensity then
- startfrom.dir = (startfrom.dir - 1) % 4
- elseif rnd > (1 - intensity) then
- startfrom.dir = (startfrom.dir + 1) % 4
- end
- if startfrom.dir == 0 then
- startfrom.y = startfrom.y + 1
- elseif startfrom.dir == 1 then
- startfrom.x = startfrom.x - 1
- elseif startfrom.dir == 2 then
- startfrom.y = startfrom.y - 1
- else
- startfrom.x = startfrom.x + 1
- end
- redraw = os.startTimer(0.05)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment