Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.69 KB | None | 0 0
  1. --Digital Screen Functions
  2. --Made by Yevano
  3.  
  4. local wire = loadModule("wire")
  5. local time = loadModule("time")
  6.  
  7. wire.setPorts({"DS:wirelink"}, {"Debug"})
  8.  
  9. FIRST = true
  10.  
  11. function tick()
  12.     if wire.isInputWired("DS") then
  13.         if FIRST then
  14.             FIRST = false
  15.            
  16.             ds = DigitalScreen("DS")
  17.            
  18.             ds.clk(true)
  19.             ds.clear()
  20.             ds.setColorMode(2)
  21.             ds.setResolution(Vector2(64, 64))
  22.            
  23.             ds.drawRectWH(Vector2(32, 32), Vector2(4, 4), Color(255, 255, 0))
  24.         end
  25.     end
  26. end
  27.  
  28. function Color(r, g, b)
  29.     local this
  30.    
  31.     this = {
  32.         r = r,
  33.         g = g,
  34.         b = b,
  35.        
  36.         print = function()
  37.             print("["..this.r..", "..this.g..", "..this.b.."]")
  38.         end
  39.     }
  40.    
  41.     return this
  42. end
  43.  
  44. function Vector2(x, y)
  45.     local this
  46.    
  47.     this = {
  48.         x = x,
  49.         y = y,
  50.        
  51.         print = function()
  52.             print("["..this.x..", "..this.y.."]")
  53.         end,
  54.        
  55.         distance = function(v)
  56.             local x1 = this.x
  57.             local y1 = this.y
  58.             local x2 = v.x
  59.             local y2 = v.y
  60.            
  61.             return math.sqrt((math.pow(x2 - x1, 2)) + (math.pow(y2 - y1, 2)))
  62.         end
  63.     }
  64.    
  65.     return this
  66. end
  67.  
  68. function DigitalScreen(wl)
  69.     local this
  70.    
  71.     this = {
  72.         wirelink = wl and wl or '',
  73.        
  74.         drawPixel = function(pos, color)
  75.             local x = pos.x
  76.             local y = pos.y
  77.            
  78.             wire.wirelinkWriteCell(
  79.                 this.wirelink,                             --name
  80.                 (x - 1) + (y - 1) * wire.wirelinkReadCell( --address
  81.                     this.wirelink,
  82.                     1048573
  83.                 ),
  84.                 color.r * 65536 + color.g * 256 + color.b  --value
  85.             )
  86.         end,
  87.        
  88.         drawRectWH = function(pos, size, color)
  89.             local i = 1
  90.             local j = 1
  91.            
  92.             while true do
  93.                 this.drawPixel(Vector2(i + pos.x, j + pos.y), color)
  94.                
  95.                 if i < size.x then i = i + 1
  96.                 else
  97.                     i = 1
  98.                    
  99.                     if j < size.y then j = j + 1
  100.                     else break end
  101.                 end
  102.             end
  103.         end,
  104.        
  105.         setColorMode = function(mode)
  106.             wire.wirelinkWriteCell(
  107.                 this.wirelink,
  108.                 1048569,
  109.                 mode and mode or 2
  110.             )
  111.         end,
  112.        
  113.         clk = function(b)
  114.             wire.wirelinkWriteCell(
  115.                 this.wirelink,
  116.                 1048575,
  117.                 b and 1 or 0
  118.             )
  119.         end,
  120.        
  121.         clear = function()
  122.             wire.wirelinkWriteCell(
  123.                 this.wirelink,
  124.                 1048574,
  125.                 1
  126.             )
  127.            
  128.             wire.wirelinkWriteCell(
  129.                 this.wirelink,
  130.                 1048574,
  131.                 0
  132.             )
  133.         end,
  134.        
  135.         setResolution = function(res)
  136.             wire.wirelinkWriteCell( --Height
  137.                 this.wirelink,
  138.                 1048572,
  139.                 res.y
  140.             )
  141.            
  142.             wire.wirelinkWriteCell( --Width
  143.                 this.wirelink,
  144.                 1048573,
  145.                 res.x
  146.             )
  147.         end,
  148.        
  149.         getResolution = function()
  150.             return Vector2(
  151.                 wire.wirelinkReadCell(
  152.                     this.wirelink,
  153.                     1048573
  154.                 ),
  155.                
  156.                 wire.wirelinkReadCell(
  157.                     this.wirelink,
  158.                     1048572
  159.                 )
  160.             )
  161.         end
  162.     }
  163.    
  164.     return this
  165. end
  166.  
  167. hook("Think", tick)
Add Comment
Please, Sign In to add comment