Advertisement
Guest User

adjustScreen

a guest
Mar 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. -- automatically adjust resolution to fit entire screen
  2. -- made by Nex4rius
  3. local c = require("component")
  4. -- if c.isAvailable("gpu") and c.isAvailable("screen") then
  5. function startScreen(gpuId,screen)
  6.     local gpu = c.proxy(c.get(gpuId))
  7.     if arg2 then
  8.       local screen = c.get(screen)
  9.       gpu.bind(screen)
  10.     end
  11.     local x, y = c.proxy(gpu.getScreen()).getAspectRatio()
  12.     x = x - 0.25
  13.     y = y - 0.25
  14.     local max_x, max_y = gpu.maxResolution()
  15.     local end_x, end_y
  16.     if x == y then
  17.         end_x = max_y * 2
  18.         end_y = max_y
  19.     elseif x > y then
  20.         end_x = max_x
  21.         end_y = max_x / x * y / 2
  22.         if end_y > max_y then
  23.             local v = max_y / end_y
  24.             end_x = end_x * v
  25.             end_y = end_y * v
  26.         end
  27.         end_x = math.ceil(end_x)
  28.         end_y = math.floor(end_y)
  29.     elseif x < y then
  30.         end_x = max_y / y * x * 2
  31.         end_y = max_y
  32.         if end_x > max_x then
  33.             local v = max_x / end_x
  34.             end_x = end_x * v
  35.             end_y = end_y * v
  36.         end
  37.         end_x = math.floor(end_x)
  38.         end_y = math.ceil(end_y)
  39.     end
  40.     gpu.setResolution(end_x, end_y)
  41.     gpu.fill(1,1,end_x,end_y," ")
  42. end
  43. -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement