Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [[ startup reference ]] --
- reference = {
- defbackcol = colors.black,
- deftxtcol = colors.white,
- mon = peripheral.find("monitor"),
- }
- if reference.mon then
- term.redirect(reference.mon)
- end
- reference.size = {term.getSize()}
- debug = {
- hit = function()
- slowDraw("HIT",5,5,colors.red)
- end,
- }
- -- [[ end of line ]] --
- function Monitors2Grid()
- --> monitors and sizes of monitors
- --< 2d grid grid
- end
- function classicDraw(txt,x,y,txtcol,backcol)
- txt = txt or " "
- local currX,currY = term.getCursorPos()
- x = x or currX
- y = y or currY
- txtcol = txtcol or reference.deftxtcol
- backcol = backcol or reference.defbackcol
- term.setCursorPos(x,y)
- term.setTextColor(txtcol)
- term.setBackgroundColor(backcol)
- term.write(txt)
- end
- function blitDraw(txt,x,y,txtcol,backcol)
- txt = txt or " "
- if not x or not y then
- local currX,currY = term.getCursorPos()
- end
- x = x or currX
- y = y or currY
- txtcol = txtcol or reference.deftxtcol
- backcol = backcol or reference.defbackcol
- local function color2hex(color)
- local y = math.log(color)/math.log(2)
- if y > 9 then
- y = string.char(y + 87)
- end
- return y
- end
- txtcol = color2hex(txtcol)
- backcol = color2hex(backcol)
- term.setCursorPos(x,y)
- term.blit(txt,string.rep(txtcol,txt:len()),string.rep(backcol,txt:len()))
- --print(txt,txtcol:rep(txt:len()),backcol:rep(txt:len()))
- end
- if term.blit then
- slowDraw = blitDraw
- else
- slowDraw = classicDraw
- end
- function createObject(txt,txtcol,backcol,x,y,dx,dy)
- local class = {}
- class = {
- txt=txt,
- txtcol=txtcol,
- backcol=backcol,
- x=x,
- y=y,
- dir=dir,
- vel=vel,
- acc=acc,
- dx=dx,
- dy=dy,
- previous = {},
- nextPos = function(self)
- self.previous.x = self.x
- self.previous.y = self.y
- self.previous.txt = self.txt
- if self.y + self.dy > reference.size[2] then
- self.dy = -1 * self.dy
- self.y = (2*reference.size[2]) - self.y + self.dy
- elseif self.y + self.dy <= 1 then
- self.dy = -1 * self.dy
- self.y = math.abs(self.dy - self.y)
- else
- self.y = self.y + self.dy
- end
- if self.x + self.dx > reference.size[1] then
- self.dx = -1 * self.dx
- self.x = (2*reference.size[1]) - self.x + self.dx
- elseif self.x + self.dx <= 1 then
- self.dx = -1 * self.dx
- self.x = math.abs(self.dx - self.x)
- else
- self.x = self.x + self.dx
- end
- end,
- draw = function(self)
- if self.previous.x then
- --debug.hit()
- slowDraw(string.rep(" ",#self.previous.txt),self.previous.x,self.previous.y,reference.defbackcol,reference.defbackcol)
- --slowDraw(" ",self.previous.x,self.previous.y)
- end
- slowDraw(self.txt,self.x,self.y,self.txtcol,self.backcol)
- end,
- }
- return class
- end
- --[[function resetTimers(n)
- for i = 1,n do
- loadstring("t"..i.." = os.startTimer(0)")()
- end
- end]]--
- function engine(objects)
- local timer = os.startTimer(0)
- local i = 1
- while true do
- e,v = os.pullEvent()
- if e == "timer" and v == timer then
- for i,v in pairs(objects) do
- v:draw()
- v:nextPos()
- end
- timer = os.startTimer(0)
- end
- end
- end
- local objects = {
- ball = createObject("x",colors.white,colors.green,9,9,1,1),
- balloon = createObject("o",colors.yellow,colors.blue,3,3,2,-2),
- flower = createObject("8",colors.red,colors.black,25,25,2,1),
- }
- local words = {
- b1 = createObject("PewPewPew",colors.green,_,10,10,4,2),
- b2 = createObject("fuckmoeny",colors.white,colors.green,1,1,1,-4),
- b3 = createObject("pussy",colors.magenta,colors.orange,7,7,4,-2),
- }
- function overflow(n)
- overflow = {}
- for i = 1,n do
- local xspeed = 0
- local yspeed = 0
- while xspeed == 0 or yspeed ==0 do
- xspeed = math.random(-5,5)
- yspeed = math.random(-5,5)
- end
- overflow[i] = createObject(" ",_,2^(math.random(6)),math.random(reference.size[1]),math.random(reference.size[2]),xspeed,yspeed)
- end
- end
- term.setBackgroundColor(reference.defbackcol)
- shell.run("clr")
- overflow(20)
- engine(overflow)
- --fastDraw("stuff",5,5,colors.blue,colors.red)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement