This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Bye.'s profile picture

Monitor resolution

Started by Bye., 08 August 2016 - 09:05 PM
Bye. #1
Posted 08 August 2016 - 11:05 PM
Hello,
I have some problems trying to calculate the monitor resolution using some math…
Esample

Input: 3x2 monitor
Resolution = ?
I thought that it follows some simple math rules like "screenResolution_x = nMonitor_x*7-(nMonitor_x-1)*4" but it's not so straight forward. :(/>/>
So, there is any function or API that can help me?
Thank you :)/>/>

EDIT: Solved problem

I solved the problem using a big table that involve x and y values and also scales.
To help future users here is the full table:

screenResolution = {
["0.5"] = {{15,36,57,79,100,121,143,164},{10,24,38,52,67,81}},
["1"]   = {{7,18,29,39,50,61,71,82},{5,12,19,26,33,40}},
["1.5"] = {{5,12,19,26,33,40,48,55},{3,8,13,17,22,27}},
["2"]   = {{4,9,14,20,25,30,36,41},{2,6,10,13,17,20}},
["2.5"] = {{3,7,11,16,20,24,29,33},{2,5,8,10,13,16}},
["3"]   = {{2,6,10,13,17,20,24,27},{2,4,6,9,11,13}},
["3.5"] = {{2,5,8,11,14,17,20,23},{1,3,5,7,10,12}},
["4"]   = {{2,5,7,10,13,15,18,21},{1,3,5,7,8,10}},
["4.5"] = {{2,4,6,9,11,13,16,18},{1,3,4,6,7,9}},
["5"]   = {{1,4,6,8,10,12,14,16},{1,2,4,5,7,8}},
}

Usage:

local function getMonSize(x,y,scale)
   return screenResolution[scale][1][x],screenResolution[scale][2][y]
end
xValue, yValue = getMonSize(5,3,"1.5")
--Note: remember to put the quote on the scale value
Edited on 06 September 2016 - 12:43 PM
Lupus590 #2
Posted 09 August 2016 - 12:22 AM
http://computercraft.info/wiki/Term.getSize
Bye. #3
Posted 09 August 2016 - 12:37 PM
I know that function… My question is if there is any mathematical formula to calculate the resolution starting from the number of screen horizontally and vertically
The_Cat #4
Posted 09 August 2016 - 01:08 PM
So you want to get the resolution based off how many monitors there are? which is kinda pointless as you can do what Lupus590 said..
Bye. #5
Posted 09 August 2016 - 01:29 PM
So you want to get the resolution based off how many monitors there are? which is kinda pointless as you can do what Lupus590 said..
I need it because I want to calculate the resolution even without have the monitor connected to the computer.
I think I will create a table with every resolution of every scale
Edited on 09 August 2016 - 11:30 AM
The_Cat #6
Posted 09 August 2016 - 01:32 PM
I did this test:

mon = peripheral.wrap("top")

w, h = mon.getSize()

-- Amount the monitor can hold
hMonitor = {6, 7}
wMonitor = {9, 11}

mon.clear()
mon.setBackgroundColor(colors.black)

for i = 1, w do
mon.setCursorPos(i, 1)
mon.write("1")
end

for i = 1, h do
mon.setCursorPos(1, i)
mon.write("2")
end

You can figure out the resolution knowing the amount of pixel can fit where.
Bye. #7
Posted 09 August 2016 - 01:42 PM
I did this test:

mon = peripheral.wrap("top")

w, h = mon.getSize()

-- Amount the monitor can hold
hMonitor = {6, 7}
wMonitor = {9, 11}

mon.clear()
mon.setBackgroundColor(colors.black)

for i = 1, w do
mon.setCursorPos(i, 1)
mon.write("1")
end

for i = 1, h do
mon.setCursorPos(1, i)
mon.write("2")
end

You can figure out the resolution knowing the amount of pixel can fit where.
But this unfortunately sill need the monitor to be connected to the computer… :(/> I think I'll create some table to solve this problem, something like this:

monitorResolution = {
    scale05 = {{X values},{Y values}},
    scale10 = {{X values},{Y values}},
    scale15 = {{X values},{Y values}},
    ...
}
Bomb Bloke #8
Posted 09 August 2016 - 01:45 PM
Bear in mind that the edge pieces have a different resolution to the middle pieces. You'll need to track those separately.
The_Cat #9
Posted 09 August 2016 - 02:10 PM
Well if you know 1 screen width for the edges and non edges you can work it out… For example 3 horizontal 2x9 (edge monitors) = 18 + 11 (1 non edge) == 29 mean the width of 3 monitors is 29… I wrote that program to find out these values.
Edited on 09 August 2016 - 12:10 PM
Bye. #10
Posted 09 August 2016 - 02:12 PM
Well if you know 1 screen width for the edges and non edges you can work it out… For example 3 horizontal 2x9 (edge monitors) = 18 + 11 (1 non edge) == 29 mean the width of 3 monitors is 29… I wrote that program to find out these values.
I'll try this method in a moment
Twijn #11
Posted 09 August 2016 - 05:16 PM
The only way I can think of doing this accurately would be to create a huge table:


local monSize = {
  {{7,5},{7,12},{7,19},{7,26},{7,33},{7,40}};
  {{18,5},{18,12},{18,19},{18,26},{18,33},{18,40}};
  {{29,5},{29,12},{29,19},{29,26},{29,33},{29,40}};
  {{39,5},{39,12},{39,19},{39,26},{39,33},{39,40}};
  {{50,5},{50,12},{50,19},{50,26},{50,33},{50,40}};
  {{61,5},{61,12},{61,19},{61,26},{61,33},{61,40}};
  {{71,5},{71,12},{71,19},{71,26},{71,33},{71,40}};
  {{82,5},{82,12},{82,19},{82,26},{82,33},{82,40}};
}
local monSizeTest = monSize[3][2] -- Gets monitor size of 3x2 monitor
monSizeTest[1] -- width of mon size 3x2
monSizeTest[2] -- height of mon size 3x2

Otherwise, you could do it slightly more efficiently with a function:


local monSizeX = {7,18,29,39,50,61,71,82}
local monSizeY = {5,12,19,26,33,40}
function getMonSize(x,y)
  return monSizeX[x],monSizeY[y]
end
local x,y = getMonSize(3,2) -- x = x size of 3x2 y = y size of 3x2
Bye. #12
Posted 09 August 2016 - 07:50 PM
The only way I can think of doing this accurately would be to create a huge table:


local monSize = {
  {{7,5},{7,12},{7,19},{7,26},{7,33},{7,40}};
  {{18,5},{18,12},{18,19},{18,26},{18,33},{18,40}};
  {{29,5},{29,12},{29,19},{29,26},{29,33},{29,40}};
  {{39,5},{39,12},{39,19},{39,26},{39,33},{39,40}};
  {{50,5},{50,12},{50,19},{50,26},{50,33},{50,40}};
  {{61,5},{61,12},{61,19},{61,26},{61,33},{61,40}};
  {{71,5},{71,12},{71,19},{71,26},{71,33},{71,40}};
  {{82,5},{82,12},{82,19},{82,26},{82,33},{82,40}};
}
local monSizeTest = monSize[3][2] -- Gets monitor size of 3x2 monitor
monSizeTest[1] -- width of mon size 3x2
monSizeTest[2] -- height of mon size 3x2

Otherwise, you could do it slightly more efficiently with a function:


local monSizeX = {7,18,29,39,50,61,71,82}
local monSizeY = {5,12,19,26,33,40}
function getMonSize(x,y)
  return monSizeX[x],monSizeY[y]
end
local x,y = getMonSize(3,2) -- x = x size of 3x2 y = y size of 3x2
I think I'll do it this way
Bye. #13
Posted 10 August 2016 - 09:14 PM
I solved the problem using a big table that involve x and y values and also scales.
To help future users here is the full table:

screenResolution = {
["0,5"] = {{15,36,57,79,100,121,143,164},{10,24,38,52,67,81}},
["1"]   = {{7,18,29,39,50,61,71,82},{5,12,19,26,33,40}},
["1,5"] = {{5,12,19,26,33,40,48,55},{3,8,13,17,22,27}},
["2"]   = {{4,9,14,20,25,30,36,41},{2,6,10,13,17,20}},
["2,5"] = {{3,7,11,16,20,24,29,33},{2,5,8,10,13,16}},
["3"]   = {{2,6,10,13,17,20,24,27},{2,4,6,9,11,13}},
["3,5"] = {{2,5,8,11,14,17,20,23},{1,3,5,7,10,12}},
["4"]   = {{2,5,7,10,13,15,18,21},{1,3,5,7,8,10}},
["4,5"] = {{2,4,6,9,11,13,16,18},{1,3,4,6,7,9}},
["5"]   = {{1,4,6,8,10,12,14,16},{1,2,4,5,7,8}},
}

Usage:

local function getMonSize(x,y,scale)
   return screenResolution[scale][1][x],screenResolution[scale][2][y]
end
xValue, yValue = getMonSize(5,3,"1,5")
--Note: remember to put the quote on the scale value
Edited on 10 August 2016 - 07:16 PM