Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using get() to obtain colour value of a pixel in image or sketch #338

Open
ArayB opened this issue Mar 22, 2022 · 1 comment
Open

Using get() to obtain colour value of a pixel in image or sketch #338

ArayB opened this issue Mar 22, 2022 · 1 comment

Comments

@ArayB
Copy link

ArayB commented Mar 22, 2022

In Processing you can use the get() method on an image, or the sketch to obtain the colour value of a particular pixel. This also works in p5js.
In p5py you can access the colour value of a pixel in an image by indexing into it as an array e.g: color = image_name[10,10] but I can't see how you do this on the sketch to obtain the colour of a pixel.

It would be great if there was a get() method that could be called which would return the colour value of a pixel in the sketch.
This would also return the colour value of a shape that was present in the sketch at that coordinate.

I've tried to create the same behaviour using the load_pixels() method but it doesn't appear to work as I would expect.
If there is no image present in the sketch it just returns the background colour. It ignores any shapes drawn in the sketch and also clears them from the sketch.

As a very simple example of what I mean in Processing and p5js (in a draw() function) the following works:

background(220);
c = get(50, 50)

fill(255,255,255)
rect(0,0, 300, 300)

c2 = get(80, 80)
fill(c)
rect(10, 10, 50, 50)

fill(c2)
rect(15, 15, 30, 30)

Simply retrieving that background colour and then the white of a rectangle and drawing another rectangle with the appropriate colour. I can't see how to do this in p5py.

I can see the _get_pixel method in the image class so presumably adding a get() method that forwards on to that would be fairly straightforward. I don't know how it would work for the whole sketch though.

@github-actions
Copy link
Contributor

Thank you for submitting your first issue to p5py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant