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

Manipulating Monitors

Started by shiskebab, 05 December 2016 - 12:26 PM
shiskebab #1
Posted 05 December 2016 - 01:26 PM
Hi, I'm trying to create an automated train station, and I wanna add a large monitor which displays in/outgoing trains, but thats kinda besides the point. You see I know I've seen some programs use these "x, y" functions like they can retrieve information about the size of the display, and then adapt the information (in this case train tables) to fit the screen. I was wondering if anybody has any information or resources which teaches monitor manipulation in this way?

Thx
KingofGamesYami #2
Posted 05 December 2016 - 01:33 PM
A monitor has a width, height, and scale. The smallest possible scale is 0.5, which will result in the largest width and height values.

Some programs know they need, for example, 20 characters in width to display their content. They detect the width of the monitor, then adjust the scale to increase or decrease the width.

I did this for a game (CCOthello) like this:
Spoiler

                for k, v in pairs( peripheral.getNames() ) do
                        if peripheral.getType( v ) == "monitor" and peripheral.call( v, "isColor" ) then
                                --y 14
                                --x 33
                                peripheral.call( v, "setTextScale", 1 )
                                local x, y = peripheral.call( v, "getSize" )
                                peripheral.call( v, "setTextScale", math.floor( math.min( y/12, x/33 ) ) )
                                term.redirect( peripheral.wrap( v ) )
                                mon = true
                        end
shiskebab #3
Posted 05 December 2016 - 01:53 PM
A monitor has a width, height, and scale. The smallest possible scale is 0.5, which will result in the largest width and height values.

Some programs know they need, for example, 20 characters in width to display their content. They detect the width of the monitor, then adjust the scale to increase or decrease the width.

I did this for a game (CCOthello) like this:
Spoiler

				for k, v in pairs( peripheral.getNames() ) do
						if peripheral.getType( v ) == "monitor" and peripheral.call( v, "isColor" ) then
								--y 14
								--x 33
								peripheral.call( v, "setTextScale", 1 )
								local x, y = peripheral.call( v, "getSize" )
								peripheral.call( v, "setTextScale", math.floor( math.min( y/12, x/33 ) ) )
								term.redirect( peripheral.wrap( v ) )
								mon = true
						end

Oh, this is neat :D/>

But, uh. The math sets the text scale to the math.floor (largest integer smaller than or equal to x) of math.min (returns the minimum value among its arguments?)? I'm not familiar with the math API, does this mean it divides the screen scale of the actual monitor by the minimum requirement? But the math.min separates its arguments so the computer can tell the difference between x and y, or does it simply select the smallest integer from the /x /y calculations? But then why use math.floor if math.min already selects the text scale?
KingofGamesYami #4
Posted 05 December 2016 - 03:19 PM
Monitors only accept scales in increments of 0.5 - hence the math.floor. I could've rounded to the nearest 0.5 but I didn't know that when the program was written.

In the case of my program, I calculated two scale factors - one for y, one for x. I needed to select the smaller of the two to guarantee enough width and height to display my game.

Sorry for lack of examples I am on a phone ATM.