pastebin get TPvfZRMD instance
Get this file if you wan't:
pastebin get 5jS6b73w test
Spoiler
os.loadAPI("instance")
local w, h = term.getSize()
local running = true
objButton = instance.objectAdd(w/2, h/2, colors.orange)--Create object objButton
function objButton:create()--objButton creation code
self.width=6
self.heigth=3
self.x=self.x-self.width/2
self.y=self.y-self.heigth/2
self.text="Random: "..tostring(math.random(1000))
self.textLen=string.len(self.text)
self.rxVel=math.random(-2, 2)
self.ryVel=math.random(-2, 2)
end
function objButton:update()--objButton step code
self.x=self.x+self.rxVel
self.y=self.y+self.ryVel
if(self.x<=1 or self.x>=w-self.width+1) then self.rxVel=-self.rxVel end
if(self.y<=1 or self.y>=h-self.heigth+1) then self.ryVel=-self.ryVel end
end
function objButton:draw()--objButton draw code
for xx=self.x, self.x+self.width do
for yy=self.y, self.y+self.heigth do
paintutils.drawPixel(xx, yy, colors.orange)
term.setTextColor(colors.black)
term.setCursorPos((self.x+self.width/2)-self.textLen/2, (self.y+self.heigth/2))
term.write(self.text)
end
end
end
local function screenClear(col)
term.setBackgroundColor(col)
term.clear()
end
function main()
screenClear(colors.white)
local tmp=instance.create(objButton)
local count=0
instance.updateAll()
while running do
screenClear(colors.white)
--After everything is done, update the instance's!
instance.updateAll()
count=count+1
if(count>30) then
count=0
instance.create(objButton, math.random(w), math.random(h))
if(instance.exists(tmp)) then
instance.destroy(tmp)
end
end
os.sleep(.1)
end
end
main()