Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Digital Screen Functions
- --Made by Yevano
- local wire = loadModule("wire")
- local time = loadModule("time")
- wire.setPorts({"DS:wirelink"}, {"Debug"})
- FIRST = true
- function tick()
- if wire.isInputWired("DS") then
- if FIRST then
- FIRST = false
- ds = DigitalScreen("DS")
- ds.clk(true)
- ds.clear()
- ds.setColorMode(2)
- ds.setResolution(Vector2(64, 64))
- ds.drawRectWH(Vector2(32, 32), Vector2(4, 4), Color(255, 255, 0))
- end
- end
- end
- function Color(r, g, b)
- local this
- this = {
- r = r,
- g = g,
- b = b,
- print = function()
- print("["..this.r..", "..this.g..", "..this.b.."]")
- end
- }
- return this
- end
- function Vector2(x, y)
- local this
- this = {
- x = x,
- y = y,
- print = function()
- print("["..this.x..", "..this.y.."]")
- end,
- distance = function(v)
- local x1 = this.x
- local y1 = this.y
- local x2 = v.x
- local y2 = v.y
- return math.sqrt((math.pow(x2 - x1, 2)) + (math.pow(y2 - y1, 2)))
- end
- }
- return this
- end
- function DigitalScreen(wl)
- local this
- this = {
- wirelink = wl and wl or '',
- drawPixel = function(pos, color)
- local x = pos.x
- local y = pos.y
- wire.wirelinkWriteCell(
- this.wirelink, --name
- (x - 1) + (y - 1) * wire.wirelinkReadCell( --address
- this.wirelink,
- 1048573
- ),
- color.r * 65536 + color.g * 256 + color.b --value
- )
- end,
- drawRectWH = function(pos, size, color)
- local i = 1
- local j = 1
- while true do
- this.drawPixel(Vector2(i + pos.x, j + pos.y), color)
- if i < size.x then i = i + 1
- else
- i = 1
- if j < size.y then j = j + 1
- else break end
- end
- end
- end,
- setColorMode = function(mode)
- wire.wirelinkWriteCell(
- this.wirelink,
- 1048569,
- mode and mode or 2
- )
- end,
- clk = function(b)
- wire.wirelinkWriteCell(
- this.wirelink,
- 1048575,
- b and 1 or 0
- )
- end,
- clear = function()
- wire.wirelinkWriteCell(
- this.wirelink,
- 1048574,
- 1
- )
- wire.wirelinkWriteCell(
- this.wirelink,
- 1048574,
- 0
- )
- end,
- setResolution = function(res)
- wire.wirelinkWriteCell( --Height
- this.wirelink,
- 1048572,
- res.y
- )
- wire.wirelinkWriteCell( --Width
- this.wirelink,
- 1048573,
- res.x
- )
- end,
- getResolution = function()
- return Vector2(
- wire.wirelinkReadCell(
- this.wirelink,
- 1048573
- ),
- wire.wirelinkReadCell(
- this.wirelink,
- 1048572
- )
- )
- end
- }
- return this
- end
- hook("Think", tick)
Add Comment
Please, Sign In to add comment