We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I’m using Processing.py 3, and I want to be able to detect when the mouse is over a specific image, but also on a pixel that isn’t transparent. I think doing img.get() would give me the info I need, but I’ve also scaled up the image. How would I go about doing this?
For example: I have an image, whose original size is 10x10 pixels, scaled up by 10 so on the screen it’s 100x100. It’s placed at x=100, y=100. The mouse is located at x=150, y=150. What code would I need to get a true/false on the transparency of the image at the mouse position?
I looked at the documentation but it’s a little unclear. I also don’t know how to access alpha data.
Here’s my guess(in python mode):
test_img = loadImage(“image.png”) image(img, 100, 100, 100, 100) def if_mouse_on_image(img, xpos, ypos): mouse_on_image_x = mouseX - xpos mouse_on_image_y = mouseY - ypos pixel_data = img.get(mouse_on_image_x, mouse_on_image_y, 10, 10) #here is where I’m confused the most. return not pixel_data #is this correct? I’m not familiar with alpha values print(if_mouse_on_image(test_img))
Would this code achieve my goals? The reason I haven’t tried this myself is because I’m not at my computer. I’m writing this from my phone.