Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chars = {}
- local function new(t)
- t.y = 0
- table.insert(chars, t)
- end
- setmetatable(chars, {__call = function(t)
- local i = 0
- return function()
- i = i + 1
- return t[i], i
- end
- end})
- local function timer(period)
- return {
- id = nil;
- run = function(self)
- self.id = os.startTimer(period)
- end;
- }
- end
- local updateTimer = timer(0.1)
- local creator = timer(0.1)
- updateTimer:run()
- creator:run()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- while true do
- local _, t = os.pullEvent('timer')
- local w,h = term.getSize()
- if t == updateTimer.id then
- for char, i in chars() do
- char.y = char.y + 1
- if char.y > h then
- table.remove(chars, i)
- else
- term.setCursorPos(char.x, char.y)
- if char.color == colors.black then
- term.setBackgroundColor(colors.black)
- term.write(' ')
- else
- term.setTextColor(char.color)
- term.write(string.char(math.random(38, 126)))
- end
- end
- end
- updateTimer:run()
- elseif t == creator.id then
- local time = math.random()*0.8 + 0.5
- local tail = timer(time)
- local eraser = timer(time + math.random()*0.25 + 0.5)
- new {
- x = math.random(w);
- color = colors.lime;
- tail = tail;
- eraser = eraser;
- ishead = true;
- }
- creator:run()
- tail:run()
- eraser:run()
- else
- for char in chars() do
- if char.ishead then
- if t == char.tail.id then
- new {
- x = char.x;
- color = colors.green;
- }
- break
- elseif t == char.eraser.id then
- new {
- x = char.x;
- color = colors.black;
- }
- break
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment