Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- out = term
- function setOutput( monitor )
- out = monitor
- end
- Rectangle = { x = 0, y = 0, xs = 10, ys = 10, filled = false, color = colors.white, fcolor = colors.white, visible = true }
- function Rectangle:new ( o )
- o = o or {} -- create object if user does not provide one
- setmetatable( o, self ) -- sets the metatable recursively
- self.__index = self -- sets the index metamethod recursively
- return o
- end
- function Rectangle:setVisible( visible )
- self.visible = visible
- end
- function Rectangle:setColor( color )
- self.color = color
- end
- function Rectangle:setFillColor( color )
- self.fcolor = color
- end
- function Rectangle:setFilled( filled )
- self.filled = filled
- end
- function Rectangle:setPos( x, y )
- self.x = x
- self.y = y
- end
- function Rectangle:setSize( xs, ys )
- self.xs = xs
- self.ys = ys
- end
- function Rectangle:getPos()
- return { x = self.x, y = self.y }
- end
- function Rectangle:draw()
- if not self.visible then
- return 0
- end
- for j=0, self.ys-1 do
- for i=0, self.xs-1 do
- out.setCursorPos( self.x+i, self.y+j )
- if not self.filled then
- if ( j == 0 or j == self.ys-1 or i == 0 or i == self.xs-1 ) then
- --sleep(0.02)
- out.setBackgroundColor( self.color )
- out.write( " " )
- end
- else
- --sleep(0.02)
- if ( j == 0 or j == self.ys-1 or i == 0 or i == self.xs-1 ) then
- out.setBackgroundColor( self.color )
- else
- out.setBackgroundColor( self.fcolor )
- end
- out.write( " " )
- end
- end
- end
- out.setBackgroundColor( colors.black )
- end
- --------------------------------CIRCLE-----------------------------
- Circle = { x = 0, y = 0, r = 0, filled = false, color = colors.white, fcolor = colors.white, visible = true}
- function Circle:new( o )
- o = o or {} -- create object if user does not provide one
- setmetatable( o, self ) -- sets the metatable recursively
- self.__index = self -- sets the index metamethod recursively
- return o
- end
- function Circle:setColor( color )
- self.color = color
- end
- function Circle:setFillColor( color )
- self.fcolor = color
- end
- function Circle:setFilled( filled )
- self.filled = filled
- end
- function Circle:setPos( x, y )
- self.x = x
- self.y = y
- end
- function Circle:setRadius( r )
- self.r = r
- end
- function Circle:draw()
- if not self.visible then
- return 0
- end
- for i = 1, 360 do
- if self.filled then -- IMPROVE!!!
- for j = 0, self.r-1 do
- local angle = i * math.pi / 180
- out.setBackgroundColor( self.fcolor )
- out.setCursorPos( math.floor( self.x + j * math.cos( angle ) + 0.5 ), math.floor( self.y + j * math.sin( angle ) + 0.5 ) )
- out.write( " " )
- --sleep(0.02)
- end
- end
- local angle = i * math.pi / 180
- out.setBackgroundColor( self.color )
- out.setCursorPos( math.floor( self.x + self.r * math.cos( angle ) + 0.5 ), math.floor( self.y + self.r * math.sin( angle ) + 0.5 ) )
- out.write( " " )
- --sleep(0.02)
- end
- out.setBackgroundColor( colors.black )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement