Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ===========================================
- -- AUTO-SCALING MONITOR DEMO
- -- ===========================================
- -- This script shows how to use the canvas API
- -- that automatically scales to your GPU tier!
- --
- -- You draw using PERCENTAGES (0-100), and the
- -- monitor handles the rest. Higher tier GPUs
- -- show more detail, but it looks the same!
- -- ===========================================
- -- Find the monitor
- local monitor = peripheral.find("monitor")
- if not monitor then
- print("No monitor found!")
- print("Connect a monitor with a cable.")
- return
- end
- -- Debug: Check what resolution APIs report
- print("=== Debug Info ===")
- local maxW, maxH = monitor.getMaxResolution()
- print("getMaxResolution: " .. maxW .. "x" .. maxH)
- local curW, curH = monitor.getResolution()
- print("getResolution (before): " .. curW .. "x" .. curH)
- -- Try using setResolution directly instead of canvas.setup
- print("Setting resolution to max...")
- local success = monitor.setResolution(maxW, maxH)
- print("setResolution result: " .. tostring(success))
- local newW, newH = monitor.getResolution()
- print("getResolution (after): " .. newW .. "x" .. newH)
- -- Get the canvas API from the monitor
- local canvas = monitor.canvas
- -- Use the resolution we set
- local w, h = newW, newH
- print("")
- print("Drawing at: " .. w .. "x" .. h)
- -- ===========================================
- -- DRAW A SCENE USING PERCENTAGES
- -- ===========================================
- -- Clear the screen
- canvas.clear(colors.black)
- -- Sky (top 45% of screen)
- canvas.rect(0, 0, 100, 45, colors.lightBlue)
- -- Sun (circle at 80% from left, 15% from top)
- canvas.circle(80, 15, 8, colors.yellow)
- -- Ground (from 45% down to bottom)
- canvas.rect(0, 45, 100, 55, colors.green)
- -- House body (at 15% from left, 40% from top)
- canvas.rect(15, 40, 25, 35, colors.brown)
- -- Roof (layered rectangles to make triangle shape)
- canvas.rect(10, 32, 35, 3, colors.red)
- canvas.rect(12, 35, 31, 3, colors.red)
- canvas.rect(14, 38, 27, 2, colors.red)
- -- Door
- canvas.rect(23, 55, 8, 20, colors.orange)
- -- Window
- canvas.rect(18, 48, 6, 10, colors.lightBlue)
- -- Tree trunk
- canvas.rect(70, 55, 5, 30, colors.brown)
- -- Tree leaves (circle)
- canvas.circle(72, 45, 12, colors.lime)
- -- Title bar at top
- canvas.rect(0, 0, 100, 8, colors.black)
- -- Show resolution in title
- local title = "GPU: " .. w .. "x" .. h
- canvas.centerText(3, title, colors.white, colors.black)
- -- ===========================================
- -- PRINT INFO TO COMPUTER TERMINAL
- -- ===========================================
- print("")
- print("=== Auto-Scaling Demo ===")
- print("Look at your monitor!")
- print("Resolution: " .. w .. "x" .. h)
- print("")
- print("Press Enter to exit...")
- read()
- -- Reset monitor
- monitor.resetResolution()
- monitor.clear()
- print("Done!")
Advertisement