Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Resolution Demo - Shows same image at all 4 GPU tiers
- -- Demonstrates OpenComputers-style resolution levels
- -- Adapts to actual monitor size
- local monitor = peripheral.find("monitor")
- if not monitor then
- print("No monitor found! Connect a monitor via cable.")
- return
- end
- -- Get monitor's physical limits
- local maxW, maxH = monitor.getMaxResolution()
- local gpuMaxW, gpuMaxH = maxW, maxH
- -- Calculate resolution tiers based on monitor size
- -- Each tier is a percentage of max resolution
- local function calcTiers()
- return {
- {name = "Basic (Tier 1)", w = math.floor(maxW * 0.15), h = math.floor(maxH * 0.15), color = colors.gray},
- {name = "Standard (Tier 2)", w = math.floor(maxW * 0.35), h = math.floor(maxH * 0.35), color = colors.green},
- {name = "Advanced (Tier 3)", w = math.floor(maxW * 0.6), h = math.floor(maxH * 0.6), color = colors.cyan},
- {name = "Elite (Tier 4)", w = maxW, h = maxH, color = colors.magenta}
- }
- end
- local tiers = calcTiers()
- -- Draw a simple house with tree
- local function drawScene(m, w, h)
- m.clear()
- -- Sky (top 40%)
- m.setBackgroundColor(colors.lightBlue)
- for y = 1, math.floor(h * 0.4) do
- m.setCursorPos(1, y)
- m.write(string.rep(" ", w))
- end
- -- Sun
- m.setBackgroundColor(colors.yellow)
- m.setTextColor(colors.orange)
- local sunX = math.floor(w * 0.8)
- local sunY = math.floor(h * 0.15)
- for dy = -1, 1 do
- m.setCursorPos(sunX - 1, sunY + dy)
- m.write(" ")
- end
- -- Ground (bottom 60%)
- m.setBackgroundColor(colors.green)
- for y = math.floor(h * 0.4) + 1, h do
- m.setCursorPos(1, y)
- m.write(string.rep(" ", w))
- end
- -- House body
- local houseX = math.floor(w * 0.3)
- local houseY = math.floor(h * 0.4)
- local houseW = math.max(10, math.floor(w * 0.2))
- local houseH = math.max(5, math.floor(h * 0.3))
- m.setBackgroundColor(colors.brown)
- for y = houseY, houseY + houseH do
- m.setCursorPos(houseX, y)
- m.write(string.rep(" ", houseW))
- end
- -- Roof
- m.setBackgroundColor(colors.red)
- local roofY = houseY - math.floor(houseH * 0.4)
- for i = 0, math.floor(houseH * 0.4) do
- local roofW = houseW + (math.floor(houseH * 0.4) - i) * 2
- local roofX = houseX - (math.floor(houseH * 0.4) - i)
- m.setCursorPos(math.max(1, roofX), roofY + i)
- m.write(string.rep(" ", roofW))
- end
- -- Door
- m.setBackgroundColor(colors.orange)
- local doorX = houseX + math.floor(houseW / 2) - 1
- local doorH = math.max(2, math.floor(houseH * 0.5))
- for y = houseY + houseH - doorH, houseY + houseH do
- m.setCursorPos(doorX, y)
- m.write(" ")
- end
- -- Window
- m.setBackgroundColor(colors.lightBlue)
- local winX = houseX + 2
- local winY = houseY + 2
- m.setCursorPos(winX, winY)
- m.write(" ")
- m.setCursorPos(winX, winY + 1)
- m.write(" ")
- -- Tree trunk
- local treeX = math.floor(w * 0.7)
- local treeY = math.floor(h * 0.5)
- m.setBackgroundColor(colors.brown)
- for y = treeY, h do
- m.setCursorPos(treeX, y)
- m.write(" ")
- end
- -- Tree leaves
- m.setBackgroundColor(colors.lime)
- local leafSize = math.max(3, math.floor(h * 0.15))
- for dy = -leafSize, 0 do
- local leafW = (leafSize - math.abs(dy)) * 2
- m.setCursorPos(treeX - leafW / 2 + 1, treeY + dy)
- m.write(string.rep(" ", leafW))
- end
- -- Title bar
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- m.setCursorPos(1, 1)
- m.write(string.rep(" ", w))
- m.setCursorPos(2, 1)
- m.write("Resolution: " .. w .. "x" .. h)
- -- Reset colors
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- end
- -- Demo each resolution tier
- print("=== Resolution Demo ===")
- print("Adapts to your monitor size!")
- print("")
- print("Monitor max resolution: " .. maxW .. "x" .. maxH)
- print("GPU max resolution: " .. gpuMaxW .. "x" .. gpuMaxH)
- print("")
- print("Press Enter to cycle through resolutions...")
- print("")
- for i, tier in ipairs(tiers) do
- -- Ensure minimum size
- tier.w = math.max(20, tier.w)
- tier.h = math.max(8, tier.h)
- print("Tier " .. i .. ": " .. tier.name .. " (" .. tier.w .. "x" .. tier.h .. ")")
- -- Check if GPU supports this resolution
- if tier.w <= gpuMaxW and tier.h <= gpuMaxH then
- local success = monitor.setResolution(tier.w, tier.h)
- if success then
- drawScene(monitor, tier.w, tier.h)
- print(" [RENDERED] - Check monitor!")
- else
- print(" [FAILED] Could not set resolution")
- end
- else
- print(" [SKIPPED] GPU tier too low (max: " .. gpuMaxW .. "x" .. gpuMaxH .. ")")
- end
- print("Press Enter for next...")
- read()
- end
- -- Reset to default
- monitor.resetResolution()
- monitor.clear()
- print("")
- print("Demo complete! Monitor reset.")
Advertisement