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

get color of current pixel - Question

Started by Goof, 19 April 2013 - 02:32 AM
Goof #1
Posted 19 April 2013 - 04:32 AM
Hello..

Does anyone know a method to get the current color of a pixel, without editing shell/bios/term… ?
i know i could just use tables to store the information, but how would i be able to?

could you give examples?

Thanks in Advance
Sariaz #2
Posted 19 April 2013 - 05:44 AM
You are correct you would have to save the data to a table. Heres an example:


screen = {}
function pixel(x,y,char,color)
  --draw the pixel
  screen[x][y] = your pixel
end

Basically you have a table for your column(x) and inside that you have a table for what row(y) it is. So if i had a pixel at 3,5 it would be in the third column and fifth row. To retrieve the data it would be screens[x cord][y cord][what data I want]. Assuming you want to keep track of the color of the character and the what character is displaying there you might add:


  screens[x][y]["color"] = color
  screens[x][y]["char"] = char

After line four before line five.
Hope this helped if you need more help just ask.
Engineer #3
Posted 19 April 2013 - 08:11 AM
-snip-
With yours its easy to look up what kind of pixel you have. Now if Mikk wanted to loop through the table, he can ofcourse, but I prefer this for it:

local pixels = {}

function pixel(x, y, char, color)
    term.setCursorPos( x, y)
    local sText = char or " "
    term.setBackgroundColor(color or colors.black)
    write(sText)

    pixels[#pixels + 1] = {}
    pixels[#pixels].x = x
    pixels[#pixels].y = y
    pixels[#pixels].char = sText
    pixels[#pixels].color = color or colors.black
end

Of course, it depends on what you are wanting to accomplish with this. I would personally use this, but if you dont want to, please use Sariaz's.

And if you really want to, you can search first if your x and y are used in the table, then overwrite that. But I will leave that to you
Sariaz #4
Posted 19 April 2013 - 08:37 AM
If you want to search by coordinates use mine if you want to search by pixel you add use Engineer's. Would you agree Engineer? I could see using mine for a game to get the color and other such data about a specific block. If however, you have a game that just needs to know what pixels its made you should probably use Engineer's.
Engineer #5
Posted 19 April 2013 - 08:48 AM
If you want to search by coordinates use mine if you want to search by pixel you add use Engineer's. Would you agree Engineer? I could see using mine for a game to get the color and other such data about a specific block. If however, you have a game that just needs to know what pixels its made you should probably use Engineer's.
I agree, but in certain ways you can search for a specific coordinate with mine. But if he really would only want that, I still recommend yours :)/>/>
Sariaz #6
Posted 19 April 2013 - 08:55 AM
Ya you can do everything with both of ours its just some parts are easier with mine, and others are easier with yours. Example: searching by cords Me: screen[x pos][y pos] you: loop through table checking till find a match. Reverse: looking by time created you: pixels[pixel's number] me: loop through table till find a match. :P/>

Edit: btw like your quote.
Edited on 19 April 2013 - 06:55 AM
remiX #7
Posted 19 April 2013 - 09:09 AM
Already helped him, if anyone wants it - pastebin