We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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)
Answers
Rgb values are packed into an int. First byte is the alpha, second is red, third is green, fourth is blue. And in Java (and it would appear in python) large positive numbers look like negative numbers (two's complement).
So, unpack that int. There are methods for this, red() etc.
There's also a big tutorial about this on the processing website, go have a read.
http://py.Processing.org/reference/rightshift.html
http://py.Processing.org/reference/pixels.html
http://py.Processing.org/reference/PImage.html
Thanks to both of you!