Jump to content




get color of current pixel - Question


  • You cannot reply to this topic
6 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 19 April 2013 - 03: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

#2 Sariaz

  • Members
  • 107 posts

Posted 19 April 2013 - 04: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.

#3 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 19 April 2013 - 07:11 AM

View PostSariaz, on 19 April 2013 - 04:44 AM, said:

-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

#4 Sariaz

  • Members
  • 107 posts

Posted 19 April 2013 - 07: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.

#5 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 19 April 2013 - 07:48 AM

View PostSariaz, on 19 April 2013 - 07:37 AM, said:

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 :)/>

#6 Sariaz

  • Members
  • 107 posts

Posted 19 April 2013 - 07: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 by Sariaz, 19 April 2013 - 07:55 AM.


#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 19 April 2013 - 08:09 AM

Already helped him, if anyone wants it - pastebin





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users