I'll try to explain it to the best of my ability.
local pixels = {}
function newPixel(x, y)
table.insert(pixels, {x=x, y=y})
end
This function here allows you to create a new pixel by adding a table to the "pixels" table, with the values of it, x and y, set to what you've given it respectively. If I wanted to make 20 random pixels:
local w,h = term.getSize()
for i=1, 20 do
newPixel(math.random(1, w), math.random(1, h))
end
And then we just make a loop, first drawing the pixels, then getting a mouse click, and checking them all against the mouse click.
while true do
-- "start off by clearing the screen with the color black before drawing anything"
term.setBackgroundColor(colors.black)
term.clear()
-- "we start at 1, and add 1 until we reach the length of the pixels table"
-- "this is only where we draw the pixels"
for i=1, #pixels do
-- "for simplification, we get the current pixel and store it in a variable."
local pixel = pixels[i]
-- "then access the pixel's data, go to it's position, and write a white space."
term.setCursorPos(pixel.x, pixel.y)
term.setBackgroundColor(colors.white)
term.write(' ')
end
-- "we get a click event from the user"
local _, button, mx, my = os.pullEvent('mouse_click')
-- "then loop through the buttons again."
for i=1, #pixels do
-- "again, storing it"
local pixel = pixels[i]
-- "checking for a like position"
if pixel.x == mx and pixel.y == my then
-- "if the positions match up, draw a lime green space for half a second."
term.setCursorPos(pixel.x, pixel.y)
term.setBackgroundColor(colors.lime)
term.write(' ')
sleep(0.5)
-- "since we've already found a pixel to click, no need to check for others."
-- "so we break out of the loop."
break
end
end
-- "after the pixel is green for half a second, the loop resumes, and all pixels are redrawn white again."
end