Getting the RGB data from a pixel

edited December 2017 in Python Mode

So I'm I've made some code that gets the pixel color value from every pixel in an image and stores it in a list. The only problem is I need to store the color value as RGB (eg. [200,10,20]) and not as the color type it is now (The values look like this: "-2477824"). I've tried using functions like colourMode() but nothing seems to work. Can anyone help?

Here's my code so far:

global pixel_log
pixel_log = []

def get_pixels():
    for pixel_width in range(width):
        for pixel_height in range(height):

            current_pixel = get(pixel_width,pixel_height)
            pixel_log.append(current_pixel)

def setup():
    size(600,540)

    rainbow = loadImage("rainbow.jpg")
    image(rainbow,0,0)
    get_pixels()

    global pixel_index
    pixel_index = list(range(0,width*height+1))

def draw():
    color_choice = choice(pixel_log)
    fill(color_choice)
    rect(100,100,400,400)
    sleep(1)
Tagged:

Answers

Sign In or Register to comment.