This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Saving screens as a file
Started by johnnic, 02 July 2013 - 10:15 PMPosted 03 July 2013 - 12:15 AM
In my OS, I would like to be able to save different parts of your desktop/whatever and be able to load those later. Is there any way to save what is on a computer in a paint format?
Posted 03 July 2013 - 02:05 AM
Not directly, but you could write a function to do so.
Posted 03 July 2013 - 02:40 AM
As Shnupbups said, not directly. However it is completely possible. A possible solution that I can think of requires you to have a screen buffer, i.e. a table that contains information about all the background colours, text colours and the characters on the screen.
Then you can loop through the buffer printing its contents to file. An easy way of writing colours out to a file is like so
Doing the above method creates the same file format as paint and nPaintPro.
Then you can loop through the buffer printing its contents to file. An easy way of writing colours out to a file is like so
local function colorToHex(col)
--# return an empty string when it isn't a valid colour
if not col or not tonumber(col) then
return " "
end
--# reduce the colour from the 2^16 scale down to numbers 0-15
col = math.floor( math.log(col) / math.log(2) )
--# turn the numbers 0-15 into hexadecimal ( 0-F ... hex is 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f )
return string.format("%X", col)
end
Then to convert them back
local function hexToColor(hex)
--# if there is no value, or its not a hex character
if not hex or not tonumber(hex,16) then
return colors.black
end
--# convert from 0-F to 0-15 ... we use 16 because hex is base-16
hex = tonumber(hex, 16)
--# return our color
return 2^hex
end
Doing the above method creates the same file format as paint and nPaintPro.
Posted 03 July 2013 - 10:07 AM
How would i make the screen a saveable string in the first place?
Posted 03 July 2013 - 01:25 PM
Are you trying to make a screenshot program or something?
If so then you would probably need to track everything that has happened on the screen since startup because it'll need to know what has been printed etc. And the best way todo this is a coroutine function that's been run from startup or something and it stores the stuff into a table.. But idk.. Kinda hard to make this..
If so then you would probably need to track everything that has happened on the screen since startup because it'll need to know what has been printed etc. And the best way todo this is a coroutine function that's been run from startup or something and it stores the stuff into a table.. But idk.. Kinda hard to make this..
Posted 04 July 2013 - 01:12 AM
How would i make the screen a saveable string in the first place?
If so then you would probably need to track everything that has happened on the screen since startup because it'll need to know what has been printed etc.
A possible solution that I can think of requires you to have a screen buffer, i.e. a table that contains information about all the background colours, text colours and the characters on the screen.
Posted 05 July 2013 - 09:48 AM
Sorry… Didn't read that..